-
Notifications
You must be signed in to change notification settings - Fork 1
/
fabfile.py
69 lines (45 loc) · 1.45 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import os
from contextlib import contextmanager
from fabric.api import cd, env, prefix, run, sudo, task
# don't changed
SYSTEM_NAME = 'dapi'
PROJECT_NAME = '<replace_this>'
REPOSITORY_URL = '<url_repository_git>'
PROJECT_ROOT = '<replace_this>'
VENV_DIR = os.path.join(PROJECT_ROOT, '../env3')
REPO = '<replace_this>'
host_dev = ['<remplace for your IP SERVER']
@task
def dev():
env.hosts = host_dev
env.environment = 'dev'
env.forward_agent = True
@contextmanager
def source_virtualenv():
with prefix('source ' + os.path.join(VENV_DIR, 'bin/activate')):
yield
def clean():
"""Cleans Python bytecode"""
sudo('find . -name \'*.py?\' -exec rm -rf {} \;')
def chown():
"""Sets proper permissions"""
sudo('chown -R www-data:www-data %s' % PROJECT_ROOT)
def restart():
sudo('service nginx restart')
@task
def deploy():
"""
Deploys the latest tag to the dev server
"""
sudo('chown -R %s:%s %s' % (env.user, env.user, PROJECT_ROOT))
with cd(PROJECT_ROOT):
run('git pull origin master')
with source_virtualenv():
with prefix('export DJANGO_SETTINGS_MODULE={}.settings'.format(SYSTEM_NAME,)):
run('pwd')
run('source ../env3/bin/activate')
run('pip3 install -r requirements/staging.txt')
run('./migratelocal.py')
run('./runlocal.sh')
chown()
restart()