-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3-deploy_web_static.py
54 lines (39 loc) · 1.35 KB
/
3-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
44
45
46
47
48
49
50
51
52
53
54
#!/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']
@runs_once
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')
path = "versions/web_static_{}.tgz".format(now)
local("mkdir -p versions")
local("tar -czvf {} web_static".format(path))
return path
def do_deploy(archive_path):
"""Distributes a .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
def deploy():
"""Creates and Distributes a .tgz archive through web servers
"""
archive = do_pack()
return do_deploy(archive)