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

Fix console #1468

Open
wants to merge 49 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
61670af
Add authors
honorine22 Sep 25, 2024
448b66c
Database setup
honorine22 Sep 25, 2024
f282a57
Test db storage
honorine22 Sep 25, 2024
3d809ae
Test console
honorine22 Sep 25, 2024
2919f85
Fix storage and console
honorine22 Sep 25, 2024
f0966a1
Fix console
honorine22 Sep 25, 2024
6329d55
Merge branch 'honorine-dev' of https://github.com/honorine22/alu-AirB…
honorine22 Sep 25, 2024
725fbfe
Fix: db storage
honorine22 Sep 25, 2024
6d17472
DBStorage - States and Cities
Darlington6 Sep 26, 2024
a66fbf1
Deleted a file that was mistakenly created
Darlington6 Sep 26, 2024
adb6b6a
DBStorage - User
Darlington6 Sep 26, 2024
e1479f9
DBStorage - Place
Darlington6 Sep 26, 2024
ed82871
DBStorage - Review
Darlington6 Sep 26, 2024
d2bfffa
DBStorage - Amenity
Darlington6 Sep 26, 2024
d5225d3
Written tests files
Darlington6 Sep 27, 2024
21349ea
Update tests
honorine22 Sep 27, 2024
c4448c8
Merge branch 'master' of https://github.com/honorine22/alu-AirBnB_clo…
honorine22 Sep 27, 2024
289f18e
Fix many blank lines
honorine22 Sep 27, 2024
0649397
pack web static
honorine22 Oct 3, 2024
1e5a4b8
deploy we static
honorine22 Oct 3, 2024
7c28032
set up ssh
honorine22 Oct 3, 2024
2d7ca06
servers addresses changed
honorine22 Oct 3, 2024
d5b03d6
Fix: server addresses
honorine22 Oct 3, 2024
67e0f4f
Fix PEP8 validation
honorine22 Oct 3, 2024
b2fa6aa
Fix: do deploy web static
honorine22 Oct 3, 2024
93e606b
remove unnecessary comments
honorine22 Oct 3, 2024
167645c
permission for setup web static
honorine22 Oct 4, 2024
9e06c8b
amend
honorine22 Oct 4, 2024
7a315d8
setup for multiple host
honorine22 Oct 4, 2024
307b900
amend
honorine22 Oct 4, 2024
a5fe357
deploy
honorine22 Oct 4, 2024
94e6833
PEP8 fix
honorine22 Oct 4, 2024
1a361d7
logs for deploy
honorine22 Oct 4, 2024
cb8374e
with logs
honorine22 Oct 4, 2024
aaa32df
PEP8 fix
honorine22 Oct 4, 2024
d06ef75
amend
honorine22 Oct 4, 2024
23d7427
Update 3-deploy_web_static.py
honorine22 Oct 4, 2024
3c45960
amend
honorine22 Oct 4, 2024
40377d9
Merge branch 'master' of https://github.com/honorine22/alu-AirBnB_clo…
honorine22 Oct 4, 2024
12ee8d2
amend
honorine22 Oct 4, 2024
350c850
advanced tasks
honorine22 Oct 4, 2024
a0dd873
.
irielle12 Oct 8, 2024
24d1f78
.
irielle12 Oct 8, 2024
f38a241
.
irielle12 Oct 8, 2024
4c770e2
.
irielle12 Oct 8, 2024
c3e0c5a
PEP8 Validation fix
honorine22 Oct 10, 2024
6b7f975
web flask
honorine22 Oct 10, 2024
5f64ed9
fix pytho_route
honorine22 Oct 10, 2024
c69a7c5
amend
honorine22 Oct 10, 2024
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
5 changes: 5 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
HBNB_MYSQL_USER = mysql
HBNB_MYSQL_PWD = Password@123!
HBNB_MYSQL_DB = hbnb_dev_db
HBNB_MYSQL_HOST = localhost
HBNB_ENV = test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
venv
33 changes: 33 additions & 0 deletions 0-setup_web_static.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/env bash
# Sets up web servers for deployment of web_static

# Install Nginx if not already installed
sudo apt-get update -y
sudo apt-get install -y nginx

# Create necessary directories
sudo mkdir -p /data/web_static/releases/test /data/web_static/shared

# Create a fake HTML file to test Nginx configuration
echo "<html>
<head>
</head>
<body>
Holberton School
</body>
</html>" | sudo tee /data/web_static/releases/test/index.html

# Create symbolic link, force (-f) remove it if it exists
sudo ln -sf /data/web_static/releases/test/ /data/web_static/current

# Set ownership of /data/ folder to ubuntu user and group recursively
sudo chown -R ubuntu:ubuntu /data/

# Update Nginx configuration to serve the content from the symbolic link
# The alias directive is used to map /hbnb_static to /data/web_static/current/
sudo sed -i '/listen 80 default_server/a location /hbnb_static { alias /data/web_static/current/;}' /etc/nginx/sites-enabled/default
# Restart Nginx to apply changes
sudo service nginx restart

# Ensure script exits successfully
exit 0
23 changes: 23 additions & 0 deletions 1-pack_web_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python3
"""
Fabric script to genereate tgz archive
execute: fab -f 1-pack_web_static.py do_pack
"""

from datetime import datetime
from fabric.api import *


def do_pack():
"""
making an archive on web_static folder
"""

time = datetime.now()
archive = 'web_static_' + time.strftime("%Y%m%d%H%M%S") + '.' + 'tgz'
local('mkdir -p versions')
create = local('tar -cvzf versions/{} web_static'.format(archive))
if create is not None:
return archive
else:
return None
33 changes: 33 additions & 0 deletions 100-clean_web_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#!/usr/bin/python3
"""
Deletes out-of-date archives
fab -f 100-clean_web_static.py do_clean:number=2
-i ssh-key -u ubuntu > /dev/null 2>&1
"""

import os
from fabric.api import *

env.hosts = ['100.27.187.5', '54.167.59.7']


def do_clean(number=0):
"""Delete out-of-date archives.
Args:
number (int): The number of archives to keep.
If number is 0 or 1, keeps only the most recent archive. If
number is 2, keeps the most and second-most recent archives,
etc.
"""
number = 1 if int(number) == 0 else int(number)

archives = sorted(os.listdir("versions"))
[archives.pop() for i in range(number)]
with lcd("versions"):
[local("rm ./{}".format(a)) for a in archives]

with cd("/data/web_static/releases"):
archives = run("ls -tr").split()
archives = [a for a in archives if "web_static_" in a]
[archives.pop() for i in range(number)]
[run("rm -rf ./{}".format(a)) for a in archives]
88 changes: 88 additions & 0 deletions 101-setup_web_static.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# Configures a web server for deployment of web_static.

# Nginx configuration file
$nginx_conf = "server {
listen 80 default_server;
listen [::]:80 default_server;
add_header X-Served-By ${hostname};
root /var/www/html;
index index.html index.htm;
location /hbnb_static {
alias /data/web_static/current;
index index.html index.htm;
}
location /redirect_me {
return 301 https://th3-gr00t.tk;
}
error_page 404 /404.html;
location /404 {
root /var/www/html;
internal;
}
}"

package { 'nginx':
ensure => 'present',
provider => 'apt'
} ->

file { '/data':
ensure => 'directory'
} ->

file { '/data/web_static':
ensure => 'directory'
} ->

file { '/data/web_static/releases':
ensure => 'directory'
} ->

file { '/data/web_static/releases/test':
ensure => 'directory'
} ->

file { '/data/web_static/shared':
ensure => 'directory'
} ->

file { '/data/web_static/releases/test/index.html':
ensure => 'present',
content => "Holberton School Puppet\n"
} ->

file { '/data/web_static/current':
ensure => 'link',
target => '/data/web_static/releases/test'
} ->

exec { 'chown -R ubuntu:ubuntu /data/':
path => '/usr/bin/:/usr/local/bin/:/bin/'
}

file { '/var/www':
ensure => 'directory'
} ->

file { '/var/www/html':
ensure => 'directory'
} ->

file { '/var/www/html/index.html':
ensure => 'present',
content => "Holberton School Nginx\n"
} ->

file { '/var/www/html/404.html':
ensure => 'present',
content => "Ceci n'est pas une page\n"
} ->

file { '/etc/nginx/sites-available/default':
ensure => 'present',
content => $nginx_conf
} ->

exec { 'nginx restart':
path => '/etc/init.d/'
}
30 changes: 30 additions & 0 deletions 2-do_deploy_web_static.py
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 = ['100.27.187.5', '54.167.59.7']


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
54 changes: 54 additions & 0 deletions 3-deploy_web_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/python3
"""
Fabric script based on the file 2-do_deploy_web_static.py that creates and
distributes an archive to the web servers

execute: fab -f 3-deploy_web_static.py deploy -i ~/.ssh/id_rsa -u ubuntu
"""

from fabric.api import env, local, put, run
from datetime import datetime
from os.path import exists, isdir
env.hosts = ['100.27.187.5', '54.167.59.7']


def do_pack():
"""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):
"""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


def deploy():
"""creates and distributes an archive to the web servers"""
archive_path = do_pack()
if archive_path is None:
return False
return do_deploy(archive_path)
3 changes: 3 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@

Ezra Nobrega <[email protected]>
Justin Majetich <[email protected]>

Honorine Igiraneza <[email protected]>
Desmond Tunyinko <[email protected]>
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<<<<<<< HEAD
<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.
Expand Down Expand Up @@ -139,4 +140,7 @@ Usage: <class_name>.update(<_id>, <dictionary>)
(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>
=======
AirBnB clone - Deploy static
>>>>>>> c3e0c5a9d97add352fe2a7200f1683b6af1cfab7
Loading