forked from alexaorrico/AirBnB_clone_v2
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
distributes archive to the web servers
- Loading branch information
1 parent
4ce882a
commit ac26bfb
Showing
1 changed file
with
30 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |