-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfabfile.py
53 lines (42 loc) · 1.34 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
from fabric import Connection, Config, task
from invoke import Exit
import getpass
# Name of the git repository
GIT_REPO = 'open-poen'
# Path of the directory
DIR = '/home/projects/%s' % (GIT_REPO)
# Container used to compile the assets
NODE_CONTAINER = 'poen_node_1'
# App container
APP_CONTAINER = 'poen_app_1'
# Server name
SERVER = 'Oxygen'
@task
def deploy_poen(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
)
)
# 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 prod' % (NODE_CONTAINER))
# Upgrade database
c.sudo('docker exec %s flask db upgrade' % (APP_CONTAINER))
# Reload app
c.run('cd %s && touch uwsgi-touch-reload' % (DIR))