zoukankan      html  css  js  c++  java
  • git+gitlab实现git版本控制管理本地化+自动化部署

    情景

    假如你在本地的虚拟机或者公司内网服务器部署了gitlab,希望版本控制管理本地化或内网化,那如何实现版本控制管理本地化或内网化的同时,能够将项目基于版本控制管理部署在线上服务器,这就是以下要讨论的问题。

    上面方案存在的关卡

    • 远程服务器如何同步或克隆本地gitlab的代码

    • gitlab如何项目实现自动化同步部署远程服务器

    实现过程

    建立仓库

    • 在gitlab建立项目(即在gitlab建立仓库过程)

    • 在远程服务器建立裸仓库

        

    • 本地克隆gitlab仓库

        

    部署ssh-keys

    • 生成
    
    ssh-keygen -t rsa -C "your_email@example.com"
    
    • 在gitlab部署本地ssh-key

      第一步:

        

    第二步:

    • 在远程服务器部署gitlab的ssh-key

    部署钩子

    • 在gitlab的.ssh文件的config文件配置相关信息
    
    host test
        hostname 0.0.0.0 #你的主机地址
        user root
        port 22
        identityfile ~/.keys/test  #你的私钥地址
    
    • 在gitlab的仓库的下创建custom_hooks文件夹,并在custom_hook下创建post-receive,编辑
    
    #!/bin/sh
    # example hook script for the "post-receive" event.
    #
    # The "post-receive" script is run after receive-pack has accepted a pack
    # and the repository has been updated.  It is passed arguments in through
    # stdin in the form
    #  <oldrev> <newrev> <refname>
    # For example:
    #  aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
    #
    # see contrib/hooks/ for a sample, or uncomment the next line and
    # rename the file to "post-receive".
    
    #. /usr/share/git-core/contrib/hooks/post-receive-email
    while read oldrev newrev ref
    do
        branch=$(git rev-parse --symbolic --abbrev-ref $ref)
        if [ "$branch" = "1.0" ]
        then
            git push -f test:/var/www/html/test.git $branch
        fi
    done
    
    • 在远程裸仓库部署钩子
    
    #!/bin/sh
    #
    # An example hook script for the "post-receive" event.
    #
    # The "post-receive" script is run after receive-pack has accepted a pack
    # and the repository has been updated.  It is passed arguments in through
    # stdin in the form
    #  <oldrev> <newrev> <refname>
    # For example:
    #  aa453216d1b3e49e7f6f98441fa56946ddcd6a20 68f7abf4e6f922807889f52bc043ecd31b79f814 refs/heads/master
    #
    # see contrib/hooks/ for a sample, or uncomment the next line and
    # rename the file to "post-receive".
    
    #. /usr/share/git-core/contrib/hooks/post-receive-email
    while read oldrev newrev ref
    do
        if [[ $ref =~ .*/1.0$ ]];
        then
            echo "1.0 ref received.  Deploying 1.0 branch to test server..."
            git --work-tree=/var/www/html/test--git-dir=$GIT_DIR checkout -f $ref
        fi
    done
    

    测试

    • 在本地新建文件,提交,如何测试服能自动更新,即部署成功

    注意:

    (1)出现下面

     

    原因:gitlab未把host添加进kown_hosts

    欢迎关注技术公众号,博客和公众号同步更新,将不断更新各种技术心得


    作者: 苏沛云
    本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须在文章页面给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    Nginx负载均衡配置
    云鹏在美团八年工作总结
    尽量不要让儿女从事这3种工作,钱再多也别做,坚持再久也没前途
    Nginx 配置ip_hash
    postgresql获取表结构,表名、表注释、字段名、字段类型及长度和字段注释
    更快的Maven来了,我的天,速度提升了8倍!
    Nginx负载均衡配置及算法详解
    nginx负载均衡策略:ip_hash、url_hash
    Windows Phone实用开发技巧(41):解决WebBrowser中显示黑色背景网页闪屏
    Windows Phone实用开发技巧(32):照片角度处理
  • 原文地址:https://www.cnblogs.com/spydxk/p/11325950.html
Copyright © 2011-2022 走看看