-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfabfile.py
48 lines (32 loc) · 1.33 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
'''
fabfile -- deployment using Fabric
=================================================================
expecting local fabric.json with following content
{
"connect_kwargs": {
"key_filename": sshkeyfilename (export OpenSSH key from puttygen)
},
"user": "appuser"
}
execute as follows
fab -H <target-host> deploy
or
fab -H <target1>,<target2> deploy
if you need to check out a particular branch
fab -H <target-host> deploy --branchname=<branch>
'''
from fabric import task
from invoke import Exit
APP_NAME = 'webmodules'
@task
def deploy(c, branchname='main', qualifier='prod'):
print(f'c.user={c.user} c.host={c.host} branchname={branchname}')
project_dir = f'/var/www/{c.host}/{APP_NAME}/{APP_NAME}'
c.run(f'cd {project_dir} && git pull')
if not c.run(f'cd {project_dir} && git show-ref --verify --quiet refs/heads/{branchname}', warn=True):
raise Exit(f'branchname {branchname} does not exist')
c.run(f'cd {project_dir} && git checkout {branchname}')
c.run(f'cd {project_dir} && cp -R ../../libs/js app/src/{APP_NAME}/static')
# stop and build/start docker services
c.run(f'cd {project_dir} && docker compose down')
c.run(f'cd {project_dir} && docker compose -f docker-compose.yml -f docker-compose.{qualifier}.yml up --build -d')