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

pull request #1504

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
bf8b9d7
console.py
IshimweOlivier-20 Jan 20, 2025
e961a8c
sg
IshimweOlivier-20 Jan 20, 2025
97fdbc4
Updated README.md
IshimweOlivier-20 Jan 25, 2025
559d098
file_storage.py
IshimweOlivier-20 Jan 25, 2025
3302029
db_storage.py
IshimweOlivier-20 Jan 25, 2025
49a6091
console.py
IshimweOlivier-20 Jan 25, 2025
4253c4e
file.json
IshimweOlivier-20 Jan 25, 2025
33e5105
main_delete.py
IshimweOlivier-20 Jan 25, 2025
529cd2a
main_place_amenities.py
IshimweOlivier-20 Jan 25, 2025
7873a04
setup_mysql_dev.sql
IshimweOlivier-20 Jan 25, 2025
5ad5f29
setup_mysql_test.sql
IshimweOlivier-20 Jan 25, 2025
78b23f3
__init__.py
IshimweOlivier-20 Jan 25, 2025
cf64b11
amenity.py
IshimweOlivier-20 Jan 25, 2025
b41b0f1
base_model.py
IshimweOlivier-20 Jan 25, 2025
83110ea
city.py
IshimweOlivier-20 Jan 25, 2025
03cff3a
base_model.py
IshimweOlivier-20 Jan 25, 2025
36ea169
place.py
IshimweOlivier-20 Jan 25, 2025
a034e44
review.py
IshimweOlivier-20 Jan 25, 2025
9e3f66a
state.py
IshimweOlivier-20 Jan 25, 2025
76e5425
user.py
IshimweOlivier-20 Jan 25, 2025
2e89ccf
file_storage.py
IshimweOlivier-20 Jan 25, 2025
a5a48ac
Delete models/vi
IshimweOlivier-20 Jan 25, 2025
dca1aab
Version 2
BirasaDivine Feb 4, 2025
4e28777
0-setup_web_static.sh
IshimweOlivier-20 Feb 7, 2025
5aaeb99
1-pack_web_static.py
IshimweOlivier-20 Feb 7, 2025
2276ea2
2-do_deploy_web_static.py
IshimweOlivier-20 Feb 7, 2025
6585852
3-deploy_web_static.py
IshimweOlivier-20 Feb 7, 2025
b14a356
My project
IshimweOlivier-20 Feb 8, 2025
1fc6412
Solving errors
IshimweOlivier-20 Feb 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"dbcode.connections": []
}
35 changes: 35 additions & 0 deletions 0-setup_web_static.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env bash
# script that sets up web servers for the deployment of web_static
sudo apt-get update
sudo apt-get -y install nginx
sudo ufw allow 'Nginx HTTP'

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

# Add test HTML file to the test folder
sudo tee /data/web_static/releases/test/index.html > /dev/null <<EOF
<html>
<head>
</head>
<body>
Holberton School
</body>
</html>
EOF

# Create a symbolic link to /data/web_static/current
sudo ln -sfn /data/web_static/releases/test/ /data/web_static/current

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

# Update the Nginx configuration to serve the content
sudo sed -i '/listen 80 default_server/a location /hbnb_static { alias /data/web_static/current/; }' /etc/nginx/sites-enabled/default

# Test the Nginx configuration to ensure there are no syntax errors
sudo nginx -t

# Restart Nginx to apply the changes
sudo service nginx restart
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
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 = ['3.84.201.218', '54.224.215.237']


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 = ['34.226.191.215', '34.235.167.216']


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)
2 changes: 2 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# These individuals contributed to the hbnb project in this repository

Olivier Ishimwe < [email protected]>
Birasa Divine < [email protected]>
Ezra Nobrega <[email protected]>
Justin Majetich <[email protected]>
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,6 @@ 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>
Updated by Olivier Ishimwe & Birasa Divine.
Binary file added __pycache__/MySQLdb.cpython-310.pyc
Binary file not shown.
Loading