-
Notifications
You must be signed in to change notification settings - Fork 447
/
2-do_deploy_web_static.py
executable file
·35 lines (33 loc) · 1.13 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
#!/usr/bin/python3
"""
Fabric script that distributes an archive to my web servers
"""
from fabric.api import *
from fabric.operations import run, put, sudo
import os
env.hosts = ['66.70.184.249', '54.210.138.75']
def do_deploy(archive_path):
"""
using fabric to distribute archive
"""
if os.path.isfile(archive_path) is False:
return False
try:
archive = archive_path.split("/")[-1]
path = "/data/web_static/releases"
put("{}".format(archive_path), "/tmp/{}".format(archive))
folder = archive.split(".")
run("mkdir -p {}/{}/".format(path, folder[0]))
new_archive = '.'.join(folder)
run("tar -xzf /tmp/{} -C {}/{}/"
.format(new_archive, path, folder[0]))
run("rm /tmp/{}".format(archive))
run("mv {}/{}/web_static/* {}/{}/"
.format(path, folder[0], path, folder[0]))
run("rm -rf {}/{}/web_static".format(path, folder[0]))
run("rm -rf /data/web_static/current")
run("ln -sf {}/{} /data/web_static/current"
.format(path, folder[0]))
return True
except:
return False