Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

quick fix #1474

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions 0-setup_web_static.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/usr/bin/env bash
# bash script that sets up your web servers for the deployment of web_static

sudo apt-get -y update
sudo apt-get -y install nginx
sudo service nginx start

sudo mkdir -p /data/web_static/shared/
sudo mkdir -p /data/web_static/releases/test/
echo "Holberton School" | sudo tee /data/web_static/releases/test/index.html > /dev/null
sudo ln -sf /data/web_static/releases/test/ /data/web_static/current

sudo chown -R ubuntu:ubuntu /data/

sudo sed -i '44i \\n\tlocation /hbnb_static {\n\t\talias /data/web_static/current/;\n\t}' /etc/nginx/sites-available/default

sudo service nginx restart
24 changes: 24 additions & 0 deletions 1-pack_web_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/python3
"""
script that generates '.tgz' archive from the contents of the 'web_static'
"""
from fabric.api import local
from datetime import datetime


def do_pack():
"""
function to compress directory into .tgz archive
Return: Success - '.tgz' archive path
Failure - None
"""
now = datetime.now()
now = now.strftime('%Y%m%d%H%M%S')
archive_path = 'versions/web_static_' + now + '.tgz'

local('mkdir -p versions/')
result = local('tar -cvzf {} web_static/'.format(archive_path))

if result.succeeded:
return archive_path
return None
33 changes: 33 additions & 0 deletions 2-do_deploy_web_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/python3
"""Fabric script that distributes an archive to your web servers"""
from fabric.api import env, put, run
from os.path import exists

env.hosts = ["34.224.223.249", "18.234.113.9"]
env.user = "ubuntu"
env.key = "~/.ssh/id_rsa"


def do_deploy(archive_path):
"""Function to distribute an archive to your web servers"""
if not exists(archive_path):
return False
try:
file_name = archive_path.split("/")[-1]
name = file_name.split(".")[0]
path_name = "/data/web_static/releases/" + name
put(archive_path, "/tmp/")
run("mkdir -p {}/".format(path_name))
run('tar -xzf /tmp/{} -C {}/'.format(file_name, path_name))
run("rm /tmp/{}".format(file_name))
run("mv {}/web_static/* {}".format(path_name, path_name))
run("rm -rf {}/web_static".format(path_name))
run('rm -rf /data/web_static/current')
run('ln -s {}/ /data/web_static/current'.format(path_name))
return True
except Exception:
return False

# Run the script like this:
# $ fab -f 2-do_deploy_web_static.py
# do_deploy:archive_path=versions/file_name.tgz
53 changes: 53 additions & 0 deletions 3-deploy_web_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
#!/usr/bin/python3
"""Fabric script that creates and distributes an archive to your web servers"""

import os
from fabric.api import env, local, put, run
from datetime import datetime
from os.path import exists

env.hosts = ["54.209.26.141", "18.215.182.32"]
env.user = "ubuntu"
env.key = "~/larissa/.ssh/id_rsa"


def do_pack():
"""Create a .tgz archive from the web_static folder."""
time_stamp = datetime.now().strftime("%Y%m%d%H%M%S")
local("mkdir -p versions")
archive_path = "versions/web_static_{}.tgz".format(time_stamp)
local("tar -cvzf {} web_static".format(archive_path))
if os.path.exists(archive_path):
return archive_path
else:
return None


def do_deploy(archive_path):
"""Distribute the archive to web servers and deploy it."""
if not exists(archive_path):
return False
try:
file_name = archive_path.split("/")[-1]
name = file_name.split(".")[0]
path_name = "/data/web_static/releases/" + name
put(archive_path, "/tmp/")
run("mkdir -p {}/".format(path_name))
run('tar -xzf /tmp/{} -C {}/'.format(file_name, path_name))
run("rm /tmp/{}".format(file_name))
run("mv {}/web_static/* {}".format(path_name, path_name))
run("rm -rf {}/web_static".format(path_name))
run('rm -rf /data/web_static/current')
run('ln -s {}/ /data/web_static/current'.format(path_name))
return True
except Exception:
return False


def deploy():
"""Create and distribute an archive to web servers."""
archive_path = do_pack()
if not archive_path:
return False

return do_deploy(archive_path)
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<center> <h1>HBNB - The Console</h1> </center>

This repository contains the initial stage of a student project to build a clone of the AirBnB website. This stage implements a backend interface, or console, to manage program data. Console commands allow the user to create, update, and destroy objects, as well as manage file storage. Using a system of JSON serialization/deserialization, storage is persistent between sessions.

*Forked for the hbnb assignment*
---

<center><h3>Repository Contents by Project Task</h3> </center>
Expand Down Expand Up @@ -138,5 +138,10 @@ Usage: <class_name>.update(<_id>, <dictionary>)
(hbnb)
(hbnb) User.all()
(hbnb) ["[User] (98bea5de-9cb0-4d78-8a9d-c4de03521c30) {'updated_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134362), 'name': 'Fred the Frog', 'age': 9, 'id': '98bea5de-9cb0-4d78-8a9d-c4de03521c30', 'created_at': datetime.datetime(2020, 2, 19, 21, 47, 29, 134343)}"]


```
<br>
<br>



Loading