forked from alexaorrico/AirBnB_clone_v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
2-do_deploy_web_static.py
30 lines (27 loc) · 1016 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
#!/usr/bin/python3
"""
Fabric script based on the file 1-pack_web_static.py that distributes an
archive to the web servers
"""
from fabric.api import put, run, env
from os.path import exists
env.hosts = ['142.44.167.228', '144.217.246.195']
def do_deploy(archive_path):
"""distributes an archive to the web servers"""
if exists(archive_path) is False:
return False
try:
file_n = archive_path.split("/")[-1]
no_ext = file_n.split(".")[0]
path = "/data/web_static/releases/"
put(archive_path, '/tmp/')
run('mkdir -p {}{}/'.format(path, no_ext))
run('tar -xzf /tmp/{} -C {}{}/'.format(file_n, path, no_ext))
run('rm /tmp/{}'.format(file_n))
run('mv {0}{1}/web_static/* {0}{1}/'.format(path, no_ext))
run('rm -rf {}{}/web_static'.format(path, no_ext))
run('rm -rf /data/web_static/current')
run('ln -s {}{}/ /data/web_static/current'.format(path, no_ext))
return True
except:
return False