-
Notifications
You must be signed in to change notification settings - Fork 5
/
fabfile.py
108 lines (84 loc) · 2.55 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
from patchwork.transfers import rsync
from fabric import task
from fabric.connection import Connection
from dotenv import dotenv_values
config = dotenv_values(".env")
project = "paytaca-bcmr"
@task
def chipnet(ctx):
ctx.config.network = 'chipnet'
ctx.config.project_dir = f'/root/{project}'
ctx.config.run.env['conn'] = Connection(
config['CHIPNET_SERVER_HOST'],
user=config['CHIPNET_SERVER_USER']
)
@task
def mainnet(ctx):
ctx.config.network = 'mainnet'
ctx.config.project_dir = f'/root/{project}'
ctx.config.run.env['conn'] = Connection(
config['MAINNET_SERVER_HOST'],
user=config['MAINNET_SERVER_USER']
)
@task
def uname(ctx):
conn = ctx.config.run.env['conn']
conn.run('uname -a')
@task
def sync(ctx):
conn = ctx.config.run.env['conn']
rsync(
conn,
'.',
ctx.config.project_dir,
exclude=[
'.venv',
'.git',
'/static',
'.DS_Store',
'__pycache__',
'*.pyc',
'*.log',
'*.pid',
'/postgres-data',
'/redis-data',
]
)
with conn.cd(ctx.config.project_dir):
conn.run(f'cat compose/.env_{ctx.config.network} >> .env')
@task
def build(ctx):
conn = ctx.config.run.env['conn']
with conn.cd(ctx.config.project_dir):
conn.run(f'sudo docker-compose -f compose/{ctx.config.network}.yml --env-file {ctx.config.project_dir}/.env build')
@task
def up(ctx):
conn = ctx.config.run.env['conn']
with conn.cd(ctx.config.project_dir):
conn.run(f'sudo docker-compose -f compose/{ctx.config.network}.yml --env-file {ctx.config.project_dir}/.env up -d')
@task
def down(ctx):
conn = ctx.config.run.env['conn']
with conn.cd(ctx.config.project_dir):
conn.run(f'sudo docker-compose -f compose/{ctx.config.network}.yml --env-file {ctx.config.project_dir}/.env down --remove-orphans')
@task
def deploy(ctx):
sync(ctx)
build(ctx)
down(ctx)
up(ctx)
@task
def nginx(ctx):
sync(ctx)
conn = ctx.config.run.env['conn']
with conn.cd(f'{ctx.config.project_dir}/compose'):
nginx_conf = f"/etc/nginx/sites-available/{project}"
nginx_slink = f"/etc/nginx/sites-enabled/{project}"
try:
conn.run(f'sudo rm {nginx_conf}')
conn.run(f'sudo rm {nginx_slink}')
except:
pass
conn.run(f'sudo cat nginx.conf > {nginx_conf}')
conn.run(f'sudo ln -s {nginx_conf} {nginx_slink}')
conn.run('sudo service nginx restart')