open:fabric

Fabric

fabric1 과 fabric2 가 다르다.

from fabric import Connection, task, Config
from invoke import run as local

config = Config(
    overrides={
        'sudo': {
            'user': SUDO_USER,
            'password': SUDO_PASSWORD
        }
    }
)

conn = Connection(
    host=YOUR_HOST,
    user=SUDO_USER,
    connect_kwargs={
        "key_filename": KEY_FILE,
    },
    config=config
)


project_path = YOUR_PROJECT_PATH


@task
def dp(c):
    prepare_deploy()
    get_latest_source()
    reload()


def prepare_deploy():
    local("git add -p && git commit", pty=True, warn=True)
    local("git push", pty=True, warn=True)


def get_latest_source():
    result = local("git log -n 1 --format=%H")
    current_commit = result.stdout.splitlines()[-1]
    print(f'current_commit :  {current_commit}')

    with conn.cd(project_path):
        conn.run("git fetch")
        conn.run(f"git reset --hard {current_commit}")


def reload():
    print('sudo password:', conn['sudo']['password'])
    conn.sudo("systemctl restart gunicorn", user='root')


  • open/fabric.txt
  • 마지막으로 수정됨: 2021/04/03 11:56
  • 저자 127.0.0.1