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
·49 lines (44 loc) · 1.63 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
#!/usr/bin/python3
# Fabfile to distribute an archive to a web server.
import os.path
from fabric.api import env
from fabric.api import put
from fabric.api import run
env.hosts = ["54.197.82.23", "18.207.112.232"]
def do_deploy(archive_path):
"""Distributes an archive to a web server.
Args:
archive_path (str): The path of the archive to distribute.
Returns:
If the file doesn't exist at archive_path or an error occurs - False.
Otherwise - True.
"""
if os.path.isfile(archive_path) is False:
return False
file = archive_path.split("/")[-1]
name = file.split(".")[0]
if put(archive_path, "/tmp/{}".format(file)).failed is True:
return False
if run("rm -rf /data/web_static/releases/{}/".
format(name)).failed is True:
return False
if run("mkdir -p /data/web_static/releases/{}/".
format(name)).failed is True:
return False
if run("tar -xzf /tmp/{} -C /data/web_static/releases/{}/".
format(file, name)).failed is True:
return False
if run("rm /tmp/{}".format(file)).failed is True:
return False
if run("mv /data/web_static/releases/{}/web_static/* "
"/data/web_static/releases/{}/".format(name, name)).failed is True:
return False
if run("rm -rf /data/web_static/releases/{}/web_static".
format(name)).failed is True:
return False
if run("rm -rf /data/web_static/current").failed is True:
return False
if run("ln -s /data/web_static/releases/{}/ /data/web_static/current".
format(name)).failed is True:
return False
return True