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

test fixes #1502

Open
wants to merge 14 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
# Install Nginx if not already installed
sudo apt-get -y update
sudo apt-get -y upgrade
sudo apt-get -y install nginx

# create folders
sudo mkdir -p /data/web_static/releases/test /data/web_static/shared
#create a fake html file
echo "This is a test" | sudo tee /data/web_static/releases/test/index.html
# create symbolic link
sudo ln -sf /data/web_static/releases/test/ /data/web_static/current

# give ownership
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
19 changes: 19 additions & 0 deletions 1-pack_web_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/python3
""" Function that compress a folder """
from datetime import datetime
from fabric.api import local
import os


def do_pack():
"""The function that compress a folder before sending"""
try:
if not os.path.exists("versions"):
local('mkdir versions')
t = datetime.now()
f = "%Y%m%d%H%M%S"
archive_path = 'versions/web_static_{}.tgz'.format(t.strftime(f))
local('tar -cvzf {} web_static'.format(archive_path))
return archive_path
except:
return None
63 changes: 63 additions & 0 deletions 2-do_deploy_web_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/python3
""" Function that deploys """
from datetime import datetime
from fabric.api import *
import os
import shlex


env.hosts = ['54.23.202.242', '44.220.160.138']
env.user = "ubuntu"


def deploy():
""" DEPLOYS """
try:
archive_path = do_pack()
except:
return False

return do_deploy(archive_path)


def do_pack():
try:
if not os.path.exists("versions"):
local('mkdir versions')
t = datetime.now()
f = "%Y%m%d%H%M%S"
archive_path = 'versions/web_static_{}.tgz'.format(t.strftime(f))
local('tar -cvzf {} web_static'.format(archive_path))
return archive_path
except:
return None


def do_deploy(archive_path):
""" Deploys """
if not os.path.exists(archive_path):
return False
try:
name = archive_path.replace('/', ' ')
name = shlex.split(name)
name = name[-1]

wname = name.replace('.', ' ')
wname = shlex.split(wname)
wname = wname[0]

releases_path = "/data/web_static/releases/{}/".format(wname)
tmp_path = "/tmp/{}".format(name)

put(archive_path, "/tmp/")
run("mkdir -p {}".format(releases_path))
run("tar -xzf {} -C {}".format(tmp_path, releases_path))
run("rm {}".format(tmp_path))
run("mv {}web_static/* {}".format(releases_path, releases_path))
run("rm -rf {}web_static".format(releases_path))
run("rm -rf /data/web_static/current")
run("ln -s {} /data/web_static/current".format(releases_path))
print("New version deployed!")
return True
except:
return False
63 changes: 63 additions & 0 deletions 3-deploy_web_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/python3
""" Function that deploys """
from datetime import datetime
from fabric.api import *
import os
import shlex


env.hosts = ['54.235.14.97', '54.205.221.93']
env.user = "ubuntu"


def deploy():
""" DEPLOYS """
try:
archive_path = do_pack()
except:
return False

return do_deploy(archive_path)


def do_pack():
try:
if not os.path.exists("versions"):
local('mkdir versions')
t = datetime.now()
f = "%Y%m%d%H%M%S"
archive_path = 'versions/web_static_{}.tgz'.format(t.strftime(f))
local('tar -cvzf {} web_static'.format(archive_path))
return archive_path
except:
return None


def do_deploy(archive_path):
""" Deploys """
if not os.path.exists(archive_path):
return False
try:
name = archive_path.replace('/', ' ')
name = shlex.split(name)
name = name[-1]

wname = name.replace('.', ' ')
wname = shlex.split(wname)
wname = wname[0]

releases_path = "/data/web_static/releases/{}/".format(wname)
tmp_path = "/tmp/{}".format(name)

put(archive_path, "/tmp/")
run("mkdir -p {}".format(releases_path))
run("tar -xzf {} -C {}".format(tmp_path, releases_path))
run("rm {}".format(tmp_path))
run("mv {}web_static/* {}".format(releases_path, releases_path))
run("rm -rf {}web_static".format(releases_path))
run("rm -rf /data/web_static/current")
run("ln -s {} /data/web_static/current".format(releases_path))
print("New version deployed!")
return True
except:
return False
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@

Ezra Nobrega <[email protected]>
Justin Majetich <[email protected]>
Adebayo Seyi<[email protected]>
Sibahle Diamini<[email protected]>
Loading