zoukankan      html  css  js  c++  java
  • 2019/01/17 基于windows使用fabric将gitlab的文件远程同步到服务器(git)

    觉得django项目把本地更新push到gitlab,再执行fabric脚本从gitlab更新服务器项目挺方便的,当然从本地直接到服务器就比较灵活。

    2019/01/17

    基于windows使用fabric将gitlab的文件远程同步到服务器
    # -*- coding: utf-8 -*-
    from fabric.api import env, run
    from fabric.operations import sudo
    
    GIT_REPO = "gitlab-project地址"
    env.user = '服务器用户名'
    env.password = '服务器用户密码'
    env.hosts = ['服务器ip']
    env.port = '22'
    
    def deploy():
        source_folder = '服务器项目目录'    # 预先把初始项目包含git拷进去
        # 执行保留服务器settings配置的pull操作同步gitlab更新到服务器
        run('cd %s &&  git stash && git pull && git stash pop' % source_folder)
        run("""
            cd {} &&
            pip install -r requirements.txt &&
            python manage.py collectstatic --noinput &&
            python manage.py migrate
            """.format(source_folder))
        sudo('supervisorctl restart project_name')
    
        

     git的使用操作,当我在服务器部署django项目时,当使用fabric脚本远程同步gitlab到服务器,发现服务器跑git pull会报错,原来是本地项目更新了,但是我在服务器的django项目的settings也修改了,这样pull会报错,因为本地、服务器、gitlab操作git项目,本地的更新push到服务器,但是服务器的settings也被我修改过了,这样服务器后手pull会报错,git的操作从博客https://blog.csdn.net/misakaqunianxiatian/article/details/51103734学习。解决办法是,第一种是通过隐藏保留服务器本地的修改,直接pull走流程,

    git stash
    git pull origin master
    git stash pop

    第二种是完全覆盖本地的项目

    git reset --hard
    git pull origin master
    黑发不知勤学早
  • 相关阅读:
    hdu 3033 I love sneakers!
    poj 1742 Coins
    poj 1276 Cash Machine
    hdu 1114 Piggy-Bank
    poj 1293 Duty Free Shop
    hdu 1203 I NEED A OFFER!
    hdu 2546 饭卡
    树的直径
    CF 337D Book of Evil
    ST表
  • 原文地址:https://www.cnblogs.com/bqwzx/p/10282337.html
Copyright © 2011-2022 走看看