-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path2-do_deploy_web_static.py
executable file
·36 lines (34 loc) · 1.14 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
#!/usr/bin/python3
"""
Fabric script method:
do_deploy: deploys archive to webservers
Usage:
fab -f 2-do_deploy_web_static.py
do_deploy:archive_path=versions/web_static_20170315003959.tgz
-i my_ssh_private_key -u ubuntu
"""
from fabric.api import env, put, run
import os.path
env.hosts = ['35.229.54.225', '35.231.225.251']
def do_deploy(archive_path):
"""
Deploy archive to web server
"""
if os.path.isfile(archive_path) is False:
return False
try:
filename = archive_path.split("/")[-1]
no_ext = filename.split(".")[0]
path_no_ext = "/data/web_static/releases/{}/".format(no_ext)
symlink = "/data/web_static/current"
put(archive_path, "/tmp/")
run("mkdir -p {}".format(path_no_ext))
run("tar -xzf /tmp/{} -C {}".format(filename, path_no_ext))
run("rm /tmp/{}".format(filename))
run("mv {}web_static/* {}".format(path_no_ext, path_no_ext))
run("rm -rf {}web_static".format(path_no_ext))
run("rm -rf {}".format(symlink))
run("ln -s {} {}".format(path_no_ext, symlink))
return True
except:
return False