-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2-do_deploy_web_static.py
executable file
·33 lines (29 loc) · 1.06 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
#!/usr/bin/python3
"""
Fabric script that distributes an archive to your web servers
"""
from os.path import exists
from fabric.api import env, put, run
env.hosts = ['18.206.207.101', '54.174.244.164']
env.key_filename = '~/.ssh/id_rsa_alx_new_publickey'
env.user = 'ubuntu'
def do_deploy(archive_path):
"""distributes an archive to your web servers"""
if exists(archive_path) is False:
return False
try:
file_name = archive_path.split("/")[-1]
file_name_no_ext = file_name.split(".")[0]
path = "/data/web_static/releases/{}/".format(file_name_no_ext)
put(archive_path, "/tmp/")
run("mkdir -p {}".format(path))
run("tar -xzf /tmp/{} -C {}".format(file_name, path))
run("rm /tmp/{}".format(file_name))
run("mv {}web_static/* {}".format(path, path))
run("rm -rf {}web_static".format(path))
run("rm -rf /data/web_static/current")
run("ln -s {} /data/web_static/current".format(path))
print("New version deployed!")
return True
except:
return False