-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
fabfile.py
86 lines (68 loc) · 2.96 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
import time
from fabric import task
def banner(txt):
print("========================== %s ==========================" % txt)
def upload(c, kk_ver):
banner("upload")
bld_dir = 'kk-%s' % kk_ver
c.run('rm -rf %s' % bld_dir)
c.run('mkdir %s' % bld_dir)
c.put('kraken-docker-stack-%s.yaml' % kk_ver, bld_dir)
def redeploy(c, kk_ver):
c.run('docker service scale kraken_agent=0')
c.run('docker service scale kraken_ui=0')
c.run('docker service scale kraken_server=0')
c.run('docker service scale kraken_controller=0')
c.run('docker service scale kraken_rq=0')
c.run('docker service scale kraken_redis=0')
c.run('docker service scale kraken_clickhouse-proxy=0')
c.run('docker service scale kraken_clickhouse=0')
c.run('docker service scale kraken_minio=0')
c.run('docker service ls')
# backup the old backup
with c.cd('backup'):
c.run('rm -f db-vol.prev.tar.gz db-sql.prev.gz')
c.run('mv db-vol.current.tar.gz db-vol.prev.tar.gz')
c.run('mv db-sql.current.gz db-sql.prev.gz')
# dump postgresql as sql
c.run("""bash -c "docker exec `docker ps -qf 'name=kraken_postgres'` bash -c 'export PGPASSWORD=kk123 && /usr/bin/pg_dump -U kraken kraken' | gzip -9 > ~/backup/db-sql.current.gz" """)
c.run('ls -lh ~/backup/db-sql.current.gz')
# dump volume with postgresql files
c.run('docker service scale kraken_postgres=0')
c.run("docker run --rm -v kraken_db-data:/db -v ~/backup:/backup ubuntu:20.04 bash -c 'cd /db && tar -zcf /backup/db-vol.current.tar.gz .'")
c.run('ls -lh ~/backup/db-vol.current.tar.gz')
c.run('ls -alh ~/backup')
c.sudo('systemctl stop docker')
time.sleep(5)
c.sudo('systemctl start docker')
# deploy the stack
bld_dir = 'kk-%s' % kk_ver
with c.cd(bld_dir):
c.run('docker stack deploy --with-registry-auth -c kraken-docker-stack-%s.yaml kraken' % kk_ver)
# do some cleanup
c.run('docker container prune -f')
c.run('docker image prune -a -f')
c.run('docker builder prune -a -f')
#c.run('docker volume prune -f') TODO: this is too dangerous, it can deleted pgsql db
# restart services
# c.run('docker service update --force kraken_postgres')
# c.run('docker service update --force kraken_clickhouse')
# c.run('docker service update --force kraken_clickhouse-proxy')
# c.run('docker service update --force kraken_minio')
# c.run('docker service update --force kraken_controller')
# c.run('docker service update --force kraken_server')
# c.run('docker service update --force kraken_rq')
# c.run('docker service update --force kraken_agent')
# c.run('docker service update --force kraken_ui')
def show_state(c):
banner("system state")
c.run('docker service ls')
c.run('df -h | grep /dev/xvda')
c.run('free -m')
c.run('top -b -n1 | head -n 10')
c.run('ls -lh ~/backup')
@task
def upgrade(c, kk_ver):
upload(c, kk_ver)
redeploy(c, kk_ver)
show_state(c)