forked from justinmajetich/AirBnB_clone
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2-do_deploy_web_static.py
executable file
·44 lines (37 loc) · 1.41 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
#!/usr/bin/python3
"""Generates a .tgz archive from the contents of the web_static folder."""
from fabric.api import run, env, put
import time
import os
env.hosts = ['44.200.178.81', '54.175.65.219']
def do_pack():
"""Generate an tgz archive from web_static folder"""
try:
local("mkdir -p versions")
local("tar -cvzf versions/web_static_{}.tgz web_static/".
format(time.strftime("%Y%m%d%H%M%S")))
return ("versions/web_static_{}.tgz".format(time.
strftime("%Y%m%d%H%M%S")))
except:
return None
def do_deploy(archive_path):
""" """
arc_path = 'versions/web_static_20221214143240.tgz'
filename = arc_path.split('/')[-1]
no_ext = filename.split('.')[0]
path = '/data/web_static/releases/'
if os.exists(archive_path) is False:
return False
else:
try:
put(archive_path, '/tmp/')
run(f'sudo mkdir -p {path}{filename}')
run(f'sudo tar -xzf /tmp/{arc_path} -C {path}{no_ext}')
run(f'sudo rm /tmp/{filename}')
run(f'sudo mv {path}{no_ext}/web_static/* {path}{no_ext}/')
run(f'sudo rm -rf {path}{no_ext}/web_static')
run(f'sudo rm -rf /data/web_static/current')
run(f'sudo ln -s {path}{no_ext} /data/web_static/current')
return True
except Exception:
return False