-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forked and updated repository to AirBnB_clone_v4.
- Loading branch information
Showing
185 changed files
with
6,020 additions
and
3,743 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 |
---|---|---|
@@ -1,14 +1,12 @@ | ||
#!/usr/bin/env bash | ||
# Script using bash to setup webservers for deployment of simple HTML | ||
# content | ||
# sets up the web servers for the deployment of web_static | ||
|
||
apt-get update && \ | ||
apt-get install -y nginx && \ | ||
mkdir -p -m=755 /data/web_static/{releases/test,shared} || exit 0 | ||
echo 'Testing 123' > /data/web_static/releases/test/index.html | ||
ln -sf /data/web_static/releases/test/ /data/web_static/current | ||
chown -hR ubuntu:ubuntu /data/ | ||
insert='\\tlocation /hbnb_static/ {\n\t\talias /data/web_static/current/;}' | ||
sed -i "37i $insert" /etc/nginx/sites-available/default | ||
service nginx restart | ||
exit 0 | ||
sudo apt-get -y update | ||
sudo apt-get -y upgrade | ||
sudo apt-get -y install nginx | ||
sudo mkdir -p /data/web_static/releases/test /data/web_static/shared | ||
echo "This is a test" | sudo tee /data/web_static/releases/test/index.html | ||
sudo ln -sf /data/web_static/releases/test/ /data/web_static/current | ||
sudo chown -hR ubuntu:ubuntu /data/ | ||
sudo sed -i '38i\\tlocation /hbnb_static/ {\n\t\talias /data/web_static/current/;\n\t}\n' /etc/nginx/sites-available/default | ||
sudo service nginx start |
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 |
---|---|---|
@@ -1,28 +1,22 @@ | ||
#!/usr/bin/python3 | ||
"""Generate .tgz file from the contents of the web_static folder""" | ||
""" | ||
Fabric script that generates a tgz archive from the contents of the web_static | ||
folder of the AirBnB Clone repo | ||
""" | ||
|
||
from fabric import api | ||
from datetime import datetime | ||
import os | ||
from fabric.api import local | ||
from os.path import isdir | ||
|
||
|
||
def do_pack(): | ||
"""Function to create tarball of webstatic files from the web_static | ||
folder in Airbnb_v2. | ||
Returns: path of .tgz file on success, None otherwise | ||
""" | ||
with api.settings(warn_only=True): | ||
isdir = os.path.isdir('versions') | ||
if not isdir: | ||
mkdir = api.local('mkdir versions') | ||
if mkdir.failed: | ||
return None | ||
suffix = datetime.now().strftime('%Y%m%d%M%S') | ||
path = 'versions/web_static_{}.tgz'.format(suffix) | ||
tar = api.local('tar -cvzf {} web_static'.format(path)) | ||
if tar.failed: | ||
return None | ||
size = os.stat(path).st_size | ||
print('web_static packed: {} -> {}Bytes'.format(path, size)) | ||
return path | ||
"""generates a tgz archive""" | ||
try: | ||
date = datetime.now().strftime("%Y%m%d%H%M%S") | ||
if isdir("versions") is False: | ||
local("mkdir versions") | ||
file_name = "versions/web_static_{}.tgz".format(date) | ||
local("tar -cvzf {} web_static".format(file_name)) | ||
return file_name | ||
except: | ||
return None |
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 |
---|---|---|
@@ -1,43 +1,30 @@ | ||
#!/usr/bin/python3 | ||
"""Deploy an archive of static html to my web servers with Fabric3""" | ||
""" | ||
Fabric script based on the file 1-pack_web_static.py that distributes an | ||
archive to the web servers | ||
""" | ||
|
||
from fabric import api | ||
from fabric.contrib import files | ||
import os | ||
|
||
|
||
api.env.hosts = ['142.44.167.235', '144.217.246.199'] | ||
api.env.user = 'ubuntu' | ||
api.env.key_filename = '~/.ssh/holberton' | ||
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): | ||
"""Function to transfer `archive_path` to web servers. | ||
Args: | ||
archive_path (str): path of the .tgz file to transfer | ||
Returns: True on success, False otherwise. | ||
""" | ||
if not os.path.isfile(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 | ||
with api.cd('/tmp'): | ||
basename = os.path.basename(archive_path) | ||
root, ext = os.path.splitext(basename) | ||
outpath = '/data/web_static/releases/{}'.format(root) | ||
try: | ||
putpath = api.put(archive_path) | ||
if files.exists(outpath): | ||
api.run('rm -rdf {}'.format(outpath)) | ||
api.run('mkdir -p {}'.format(outpath)) | ||
api.run('tar -xzf {} -C {}'.format(putpath[0], outpath)) | ||
api.run('rm -f {}'.format(putpath[0])) | ||
api.run('mv -u {}/web_static/* {}'.format(outpath, outpath)) | ||
api.run('rm -rf {}/web_static'.format(outpath)) | ||
api.run('rm -rf /data/web_static/current') | ||
api.run('ln -sf {} /data/web_static/current'.format(outpath)) | ||
print('New version deployed!') | ||
except: | ||
return False | ||
else: | ||
return True |
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 |
---|---|---|
@@ -1,73 +1,52 @@ | ||
#!/usr/bin/python3 | ||
"""Tar, transfer, and deploy static html to webservers""" | ||
""" | ||
Fabric script based on the file 2-do_deploy_web_static.py that creates and | ||
distributes an archive to the web servers | ||
""" | ||
|
||
from fabric import api, decorators | ||
from fabric.contrib import files | ||
from fabric.api import env, local, put, run | ||
from datetime import datetime | ||
import os | ||
from os.path import exists, isdir | ||
env.hosts = ['142.44.167.228', '144.217.246.195'] | ||
|
||
api.env.hosts = ['holberton1', 'holberton3'] | ||
api.env.hosts = ['142.44.167.235', '144.217.246.199'] | ||
api.env.user = 'ubuntu' | ||
api.env.key_filename = '~/.ssh/holberton' | ||
|
||
|
||
def deploy(): | ||
"""Wrapper function to pack html files into tarball and transfer | ||
to web servers.""" | ||
return do_deploy(do_pack()) | ||
|
||
|
||
@decorators.runs_once | ||
def do_pack(): | ||
"""Function to create tarball of webstatic files from the web_static | ||
folder in Airbnb_v2. | ||
Returns: path of .tgz file on success, False otherwise | ||
""" | ||
with api.settings(warn_only=True): | ||
isdir = os.path.isdir('versions') | ||
if not isdir: | ||
mkdir = api.local('mkdir versions') | ||
if mkdir.failed: | ||
return False | ||
suffix = datetime.now().strftime('%Y%m%d%M%S') | ||
path = 'versions/web_static_{}.tgz'.format(suffix) | ||
tar = api.local('tar -cvzf {} web_static'.format(path)) | ||
if tar.failed: | ||
return False | ||
size = os.stat(path).st_size | ||
print('web_static packed: {} -> {}Bytes'.format(path, size)) | ||
return path | ||
"""generates a tgz archive""" | ||
try: | ||
date = datetime.now().strftime("%Y%m%d%H%M%S") | ||
if isdir("versions") is False: | ||
local("mkdir versions") | ||
file_name = "versions/web_static_{}.tgz".format(date) | ||
local("tar -cvzf {} web_static".format(file_name)) | ||
return file_name | ||
except: | ||
return None | ||
|
||
|
||
def do_deploy(archive_path): | ||
"""Function to transfer `archive_path` to web servers. | ||
"""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 | ||
|
||
Args: | ||
archive_path (str): path of the .tgz file to transfer | ||
|
||
Returns: True on success, False otherwise. | ||
""" | ||
if not os.path.isfile(archive_path): | ||
def deploy(): | ||
"""creates and distributes an archive to the web servers""" | ||
archive_path = do_pack() | ||
if archive_path is None: | ||
return False | ||
with api.cd('/tmp'): | ||
basename = os.path.basename(archive_path) | ||
root, ext = os.path.splitext(basename) | ||
outpath = '/data/web_static/releases/{}'.format(root) | ||
try: | ||
putpath = api.put(archive_path) | ||
if files.exists(outpath): | ||
api.run('rm -rdf {}'.format(outpath)) | ||
api.run('mkdir -p {}'.format(outpath)) | ||
api.run('tar -xzf {} -C {}'.format(putpath[0], outpath)) | ||
api.run('rm -f {}'.format(putpath[0])) | ||
api.run('mv -u {}/web_static/* {}'.format(outpath, outpath)) | ||
api.run('rm -rf {}/web_static'.format(outpath)) | ||
api.run('rm -rf /data/web_static/current') | ||
api.run('ln -s {} /data/web_static/current'.format(outpath)) | ||
print('New version deployed!') | ||
except: | ||
return False | ||
else: | ||
return True | ||
return do_deploy(archive_path) |
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 |
---|---|---|
@@ -1,8 +1,6 @@ | ||
# This file lists all individuals having contributed content to the repository. | ||
Andrew Birnberg <[email protected]> | ||
Felicia Hsieh <[email protected]> | ||
|
||
|
||
Jennifer Huang <[email protected]> | ||
Alexa Orrico <[email protected]> | ||
Thomas Wang <[email protected]> | ||
Ifeanyi Kalu <[email protected]> | ||
Dollars Ita <[email protected]> | ||
Joann Vuong <[email protected]> |
Oops, something went wrong.