-
Notifications
You must be signed in to change notification settings - Fork 2
/
fabfile.py
69 lines (49 loc) · 1.56 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
from fabric.api import local, env, settings, abort, run, cd, prefix, sudo, prompt
from fabric.colors import green, red
from fabric.api import settings # noqa
from contextlib import contextmanager as _contextmanager
from pyfiglet import Figlet
INIT = False
env.use_ssh_config = True
env.user = 'ubuntu'
env.hosts = ['159.89.166.117']
env.directory = '~/var/www/fractal_hackathon'
env.activate = 'source ~/var/www/fractal_hackathon/env/bin/activate'
APP_DIR = '~/var/www/fractal_hackathon/app'
STATIC_DIR = '{}/static'.format(APP_DIR)
SUPERVISOR_CONF = 'app'
def _sudo_patch(*args, **kwargs):
return sudo(*args, **kwargs)
_sudo = _sudo_patch
def deploy():
_confirm()
with cd(APP_DIR):
with _virtualenv():
run('git pull origin master')
set_requirements()
_setup_static()
_restart_app()
@_contextmanager
def _virtualenv():
with cd(env.directory):
with prefix(env.activate):
yield
def set_requirements():
run('pip install -r requirements.txt')
def _restart_app():
with cd(APP_DIR):
with _virtualenv():
_sudo('supervisorctl restart {}'.format(SUPERVISOR_CONF))
def _setup_static():
with cd(STATIC_DIR):
run('yarn')
run('node ./node_modules/webpack/bin/webpack.js -p')
def _confirm():
figlet = Figlet(font='slant')
response = prompt("""
type YES to continue to deploy ===>
""")
if response != "YES":
abort(red("ABORTING DEPLOYMENT"))
local("clear")
print(green(figlet.renderText("LET'S GO...")))