-
Notifications
You must be signed in to change notification settings - Fork 6
/
fabfile.py
36 lines (31 loc) Β· 1.18 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# -*- coding: utf-8 -*-
import os
from fabric import task
@task
def deploy(c, sha1='', django_setting='pyconkr.staging_settings', port='8000'):
target_dir = f'~/'
api_dir = f'{target_dir}/pyconkr-api'
git_url = 'https://github.com/pythonkr/pyconkr-api.git'
# μ΄μ μ deploy dirμ cloneν μ μ΄ μλ€λ©΄ clone
result = c.run(f'test -e {api_dir}', warn=True)
if result.exited:
print(f'{api_dir} is not exists')
c.run(f'git clone {git_url} {api_dir}')
with c.cd(api_dir):
c.run('git fetch --all -p')
c.run(f'git reset --hard {sha1}')
envs = [
f'PORT={port}',
f'DJANGO_SETTINGS_MODULE={django_setting}'
]
c.run(f'bash -l -c "docker-compose down | true"')
env_command = ' '.join(envs)
compose_command = f'docker-compose up -d --build --force-recreate'
c.run(f'bash -l -c "{env_command} {compose_command}"')
print('finish')
@task
def deploy_dev(c, sha1=''):
deploy(c, sha1=sha1, django_setting='pyconkr.staging_settings', port='8000')
@task
def deploy_master(c, sha1=''):
deploy(c, sha1=sha1, django_setting='pyconkr.production_settings', port='8000')