forked from justinmajetich/AirBnB_clone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2-do_deploy_web_static.py
executable file
·32 lines (30 loc) · 1022 Bytes
/
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
#!/usr/bin/python3
"""
Fabric script method do_deploy
deploys archive to webservers
"""
from fabric.api import env, put, run
import os.path
env.hosts = ['35.237.202.79', '34.204.185.51']
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 ValueError:
return False