-
Notifications
You must be signed in to change notification settings - Fork 0
/
2-do_deploy_web_static.py
43 lines (31 loc) · 1.16 KB
/
2-do_deploy_web_static.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
#!/usr/bin/python3
from datetime import datetime
from fabric.api import *
from os import path
env.hosts = ['35.229.93.37', '54.196.213.127']
def do_pack():
"""Generates a .tgz archive from the contents
of the web_static folder of this repository.
"""
d = datetime.now()
now = d.strftime('%Y%m%d%H%M%S')
local("mkdir -p versions")
local("tar -czvf versions/web_static_{}.tgz web_static".format(now))
def do_deploy(archive_path):
"""Distributes an .tgz archive through web servers
"""
if path.exists(archive_path):
archive = archive_path.split('/')[1]
a_path = "/tmp/{}".format(archive)
folder = archive.split('.')[0]
f_path = "/data/web_static/releases/{}/".format(folder)
put(archive_path, a_path)
run("mkdir -p {}".format(f_path))
run("tar -xzf {} -C {}".format(a_path, f_path))
run("rm {}".format(a_path))
run("mv -f {}web_static/* {}".format(f_path, f_path))
run("rm -rf {}web_static".format(f_path))
run("rm -rf /data/web_static/current")
run("ln -s {} /data/web_static/current".format(f_path))
return True
return False