-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfabfile.py
74 lines (60 loc) · 2.19 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
70
71
72
73
74
import os.path
from fabric import Connection, Config, task
from invoke import Exit
import getpass
# Name of the git repository
GIT_REPO = 'jodal'
# Path of the directory
DIR = '/home/projects/%s' % (GIT_REPO)
# nginx container
NGINX_CONTAINER = 'jodal_nginx_1'
# Container used to compile the assets
NODE_CONTAINER = 'jodal_node_1'
# App container
APP_CONTAINER = 'jodal_backend_1'
# makesite container
MAKESITE_CONTAINER = 'jodal_makesite_1'
MAKESITE2_CONTAINER = 'jodal_makesite-pdd_1'
# API container
API_CONTAINER = 'api-jodal'
# Server name
SERVER = 'fluorine'
@task
def deploy(c):
sudo_pass = getpass.getpass("Enter your sudo password on %s: " % SERVER)
config = Config(overrides={'sudo': {'password': sudo_pass}})
c = Connection(SERVER, config=config)
# Pull from GitHub
c.run(
'cd %s && git pull [email protected]:openstate/%s.git' % (
DIR,
GIT_REPO
)
)
# build & start new containers
c.sudo("sh -c 'cd %s && docker-compose build'" % (os.path.join(DIR, 'docker'),))
c.sudo("sh -c 'cd %s && docker-compose up -d'" % (os.path.join(DIR, 'docker'),))
# compile web landing page
#c.sudo("docker exec %s ./makesite.py" % (MAKESITE_CONTAINER,))
#c.sudo("docker exec %s ./makesite.py" % (MAKESITE2_CONTAINER,))
# Compile assets
output = c.sudo(
'docker inspect --format="{{.State.Status}}" %s' % (NODE_CONTAINER)
)
if output.stdout.strip() != 'running':
raise Exit(
'\n*** ERROR: The %s container, used to compile the assets, is '
'not running. Please build/run/start the container.' % (
NODE_CONTAINER
)
)
c.sudo('docker exec %s yarn' % (NODE_CONTAINER))
c.sudo('docker exec %s yarn build' % (NODE_CONTAINER))
# Upgrade database
c.sudo('docker exec %s alembic upgrade head' % (APP_CONTAINER))
# put elasticsearch mapings
c.sudo('docker exec %s python manage.py elasticsearch put_templates' % (APP_CONTAINER))
# reload api container
c.sudo("sh -c 'cd %s && docker-compose restart %s'" % (os.path.join(DIR, 'docker'), API_CONTAINER))
# Reload app
c.sudo('docker exec %s nginx -s reload' % (NGINX_CONTAINER))