forked from srinitude/AirBnB_clone_v2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2-do_deploy_web_static.py
56 lines (44 loc) · 1.83 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
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/python3
"""
distributes an archive to web servers
"""
from fabric.api import *
from fabric.operations import run, put, sudo
import os.path
env.hosts = ['142.44.167.241', '144.217.246.212']
#env.user = 'ubuntu'
def do_deploy(archive_path):
""" returns true if deployed correctly, else false"""
# EX:
# archive_path = versions/web_static_20170315003959.tgz
# filename = web_static_20170315003959.tgz
if not os.path.isfile(archive_path):
return False
try:
filename = archive_path.split("/")[1]
temp_path = "/tmp/" + filename
filename_split = filename.split(".")[0]
#folder name = /data/web_static/releases/<archive filename w/o ext
# EX: mkdir -p /data/web_static/releases/web_static_20170315003959/
folder = "/data/web_static/releases/" + filename_split
#Upload the archive to the /tmp/ directory
put(archive_path, temp_path)
run("sudo mkdir -p {}".format(folder))
# Uncompress the archive to the folder
#syntax: tar -zxvf filename -C dir
run("sudo tar -xzf {} -C {}".format(temp_path, folder))
#Delete the archive from the web server
# /tmp/web_static_20170315003959.tgz
run("sudo rm {}".format(temp_path))
run("sudo mv {}web_static/* {}".format(folder, folder))
run("sudo rm -rf {}web_static".format(folder))
#Delete the symbolic link /data/web_static/current from the web server
run("sudo rm -rf /data/web_static/current")
# Create a new the symbolic link /data/web_static/current
# on the web server, linked to the new version of your code
# (/data/web_static/releases/<archive filename without extension>)
run("ln -s {} /data/web_static/current".format(folder))
print("end")
return True
except:
return False