forked from paytaca/watchtower-cash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
74 lines (57 loc) · 1.54 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
from patchwork.transfers import rsync
from fabric import task
from dotenv import dotenv_values
config = dotenv_values(".env")
hosts = [ 'root@' + config['SERVER_IP'] ]
project = "watchtower"
@task(hosts=hosts)
def sync(c):
rsync(
c,
'.',
f'/root/{project}',
exclude=[
'.venv',
'.git',
'/static',
'.DS_Store',
'.env',
'__pycache__',
'*.pyc',
'*.log',
'*.pid'
]
)
@task(hosts=hosts)
def build(c):
with c.cd(f'/root/{project}'):
c.run('docker-compose -f compose/prod.yml build')
@task(hosts=hosts)
def up(c):
with c.cd(f'/root/{project}'):
c.run('docker-compose -f compose/prod.yml up -d')
@task(hosts=hosts)
def down(c):
with c.cd(f'/root/{project}'):
c.run('docker-compose -f compose/prod.yml down')
@task(hosts=hosts)
def deploy(c):
sync(c)
build(c)
down(c)
up(c)
@task(hosts=hosts)
def nginx(c):
sync(c)
with c.cd(f'/root/{project}/compose'):
nginx_conf = f"/etc/nginx/sites-available/{project}"
nginx_slink = f"/etc/nginx/sites-enabled/{project}"
c.run(f'sudo rm {nginx_conf}')
c.run(f'sudo rm {nginx_slink}')
c.run(f'sudo cat nginx.conf > {nginx_conf}')
c.run(f'sudo ln -s {nginx_conf} {nginx_slink}')
c.run('sudo service nginx restart')
@task(hosts=hosts)
def logs(c):
with c.cd(f'/root/{project}'):
c.run(f'docker-compose -p {project} -f compose/prod.yml logs -f web')