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
·52 lines (42 loc) · 1.54 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
#!/usr/bin/python3
"""
Fabric script that distributes an archive to your web servers
"""
from datetime import datetime
from fabric.api import *
import os
env.hosts = ["44.210.150.159", "35.173.47.15"]
env.user = "ubuntu"
def do_pack():
"""
return the archive path if archive has generated correctly.
"""
local("mkdir -p versions")
date = datetime.now().strftime("%Y%m%d%H%M%S")
archived_f_path = "versions/web_static_{}.tgz".format(date)
t_gzip_archive = local("tar -cvzf {} web_static".format(archived_f_path))
if t_gzip_archive.succeeded:
return archived_f_path
else:
return None
def do_deploy(archive_path):
"""
Distribute archive.
"""
if os.path.exists(archive_path):
archived_file = archive_path[9:]
newest_version = "/data/web_static/releases/" archived_file[:-4]
archived_file = "/tmp/" archived_file
put(archive_path, "/tmp/")
run("sudo mkdir -p {}".format(newest_version))
run("sudo tar -xzf {} -C {}/".format(archived_file,
newest_version))
run("sudo rm {}".format(archived_file))
run("sudo mv {}/web_static/* {}".format(newest_version,
newest_version))
run("sudo rm -rf {}/web_static".format(newest_version))
run("sudo rm -rf /data/web_static/current")
run("sudo ln -s {} /data/web_static/current".format(newest_version))
print("New version deployed!")
return True
return False