温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

git实现自动化部署,同时push到多个远程仓库

发布时间:2020-06-18 17:58:59 来源:网络 阅读:1728 作者:boy12626 栏目:开发技术

方法一、

1、先在服务器创建裸仓库  git init --bare <repo>  裸仓库是可以被正常 clone 和 push 更新的, 裸仓库不包含工作区,所以并不会存在在裸仓库上直接提交变更的情况

   git init --bare test.git

2、配置hooks 钩子

     cd test/test.git/hooks/

      vi post-receive       

      #!/bin/sh

      git --work-tree=/root/test  --git-dir=/root/test/test.git checkout -f     #/root/test是代码目录,/root/test/test.git 是裸仓库


3、配置本地git conf

vi conf

[remote "web"]

        url = git@git.oschina.net/mytest.git    #远程仓库

        url = 账号@ip:/root/test/test.git         #服务器裸仓库

4、测试

git push web master


方法二、

 1、配置码云

  配置url和密码  (http://127.0.0.1/git_hooks,密码:123456)

2、配置服务器端

  

@login.route('/git_hooks', methods=['POST'])
def git_payload():
    data = request.get_json()
    password = '123456'
    if data.get('password', None) == password:
        if data.get('hook_name') == "push_hooks":
            try:
                cmd_output = subprocess.Popen(
                    [". /home/git_sh.sh"], shell=True)
                return jsonify({'msg': str(cmd_output)})
            except subprocess.CalledProcessError as error:
                return jsonify({'msg': str(error.output)})
        else:
            return jsonify('invalid hooks')
    else:
        return jsonify('invalid hash')

3、编辑git_sh.sh脚本

  cd /home/backend/www/aw

  git pull origin master


4、git实现自动化部署,同时push到多个远程仓库

  

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI