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
·37 lines (31 loc) · 1.25 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
#!/usr/bin/python3
"""Module that includes a Fabric Script."""
from fabric.api import local, put, run, env
from os.path import exists
env.hosts = ['52.90.14.162', '100.25.162.4']
def do_pack():
"""Generates a .tgz archive from the contents of `web_static` directory"""
local("mkdir -p versions")
local("tar -cvzf versions/web_static_$(date +%Y%m%d%H%M%S).tgz web_static")
def do_deploy(archive_path):
"""Distributes an archive to your web servers.
Returns:
False, if the file path `archive path` doesn't exist.
"""
if exists(archive_path) is False:
return (False)
try:
put(f"{archive_path}", "/tmp/")
archive_file = archive_path.split('/')[1]
archive_no_ext = archive_file.split('.')[0]
full_archive_dir = f"/data/web_static/releases/{archive_no_ext}"
run(f"mkdir -p {full_archive_dir}")
run(f"tar -xzf /tmp/{archive_file} -C {full_archive_dir}/")
run(f"rm /tmp/{archive_file}")
run(f"mv {full_archive_dir}/web_static/* {full_archive_dir}")
run(f"rm -r {full_archive_dir}/web_static")
run("unlink /data/web_static/current")
run(f"ln -sf {full_archive_dir}/ /data/web_static/current")
return (True)
except:
return (False)