Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 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
5819cff
0-hello_route.p
IshimweOlivier-20 Feb 21, 2025
e959cf5
Merge branch 'master' of https://github.com/IshimweOlivier-20/alu-Air…
IshimweOlivier-20 Feb 21, 2025
66e92e0
1-hbnb_route.py
IshimweOlivier-20 Feb 21, 2025
7125067
2-c_route.py
IshimweOlivier-20 Feb 21, 2025
dd8d3d4
3-python_route.py
IshimweOlivier-20 Feb 21, 2025
3bd2ec4
4-number_route.py
IshimweOlivier-20 Feb 21, 2025
281fffa
5-number_template.py
IshimweOlivier-20 Feb 21, 2025
0696886
6-number_odd_or_even.py
IshimweOlivier-20 Feb 21, 2025
b42da0b
7-states_list.py
IshimweOlivier-20 Feb 21, 2025
1c43632
8-cities_by_states.py
IshimweOlivier-20 Feb 21, 2025
8dd5e7d
9-states.py
IshimweOlivier-20 Feb 21, 2025
49e8c3d
9-test.py
IshimweOlivier-20 Feb 21, 2025
ed7ba6d
5-number.html
IshimweOlivier-20 Feb 21, 2025
fce2f5a
6-number_odd_or_even.html
IshimweOlivier-20 Feb 21, 2025
74e8fb5
7-states_list.html
IshimweOlivier-20 Feb 21, 2025
78828ca
8-cities_by_states.html
IshimweOlivier-20 Feb 21, 2025
69e9652
9-states.html
IshimweOlivier-20 Feb 21, 2025
f713cbd
README.md
IshimweOlivier-20 Feb 21, 2025
4d2b13c
__init__.py
IshimweOlivier-20 Feb 21, 2025
8c4e355
5-number_template.py
IshimweOlivier-20 Feb 21, 2025
1b4c23d
Done
BirasaDivine Feb 21, 2025
f8572b6
Web flask
BirasaDivine Feb 21, 2025
6f98f19
Web flask
BirasaDivine Feb 21, 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": []
}
75 changes: 75 additions & 0 deletions 0-setup_web_static.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env bash
<<<<<<< HEAD
# Sets up a web server for deployment of web_static.

apt-get update
apt-get install -y nginx

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

chown -R ubuntu /data/
chgrp -R ubuntu /data/

printf %s "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 http://cuberule.com/;
}

error_page 404 /404.html;
location /404 {
root /var/www/html;
internal;
}
}" > /etc/nginx/sites-available/default

service nginx restart
=======
# 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
>>>>>>> 8c4e35510d77a5ef3680cd4a33a027addfeecf6b
39 changes: 39 additions & 0 deletions 1-pack_web_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/python3
<<<<<<< HEAD
"""#This generates .tgz archive from teh web_static"""
=======
"""
Fabric script to genereate tgz archive
execute: fab -f 1-pack_web_static.py do_pack
"""
>>>>>>> 8c4e35510d77a5ef3680cd4a33a027addfeecf6b

from datetime import datetime
from fabric.api import *


def do_pack():
"""
<<<<<<< HEAD
archive file making
"""

tme = datetime.now()
arch = 'web_static_' + tme.strftime("%Y%m%d%H%M%S") + '.' + 'tgz'
local('mkdir -p versions')
make = local('tar -cvzf versions/{} web_static'.format(arch))
if make is not None:
return arch
=======
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
>>>>>>> 8c4e35510d77a5ef3680cd4a33a027addfeecf6b
else:
return None
23 changes: 23 additions & 0 deletions 100-clean_web_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/python3
"""Let's start"""
import os
from fabric.api import *

env.hosts = ["54.175.253.142", "34.239.255.28"]


def do_clean(number=0):
"""delete out-of-dated archives
"""
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]
90 changes: 90 additions & 0 deletions 101-setup_web_static.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#config web server

$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 http://cuberule.com/;
}

error_page 404 /404.html;
location /404 {
root /var/www/html;
internal;
}
}"

package { 'check-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/'
}
75 changes: 75 additions & 0 deletions 2-do_deploy_web_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/python3
<<<<<<< HEAD
"""distrutes the archive"""
import os.path
from fabric.api import env
from fabric.api import put
from fabric.api import run

env.hosts = ["54.175.253.142", "34.239.255.28"]


def do_deploy(archive_path):
"""gives the archives
"""
if os.path.isfile(archive_path) is False:
return False
fi = archive_path.split("/")[-1]
nme = fi.split(".")[0]

if put(archive_path, "/tmp/{}".format(fi)).failed is True:
return False
if run("rm -rf /data/web_static/releases/{}/".
format(nme)).failed is True:
return False
if run("mkdir -p /data/web_static/releases/{}/".
format(nme)).failed is True:
return False
if run("tar -xzf /tmp/{} -C /data/web_static/releases/{}/".
format(fi, nme)).failed is True:
return False
if run("rm /tmp/{}".format(fi)).failed is True:
return False
if run("mv /data/web_static/releases/{}/web_static/* "
"/data/web_static/releases/{}/".format(nme, nme)).failed is True:
return False
if run("rm -rf /data/web_static/releases/{}/web_static".
format(nme)).failed is True:
return False
if run("rm -rf /data/web_static/current").failed is True:
return False
if run("ln -s /data/web_static/releases/{}/ /data/web_static/current".
format(nme)).failed is True:
return False
return True
=======
"""
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
>>>>>>> 8c4e35510d77a5ef3680cd4a33a027addfeecf6b
84 changes: 84 additions & 0 deletions 3-deploy_web_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/usr/bin/python3
"""
<<<<<<< HEAD
deploys the web static
=======
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
>>>>>>> 8c4e35510d77a5ef3680cd4a33a027addfeecf6b
"""

from fabric.api import env, local, put, run
from datetime import datetime
from os.path import exists, isdir
<<<<<<< HEAD
env.hosts = ['34.228.159.176', '18.234.150.129']


def do_pack():
"""makes a tgz archive"""
=======
env.hosts = ['34.226.191.215', '34.235.167.216']


def do_pack():
"""generates a tgz archive"""
>>>>>>> 8c4e35510d77a5ef3680cd4a33a027addfeecf6b
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:
<<<<<<< HEAD
file_name = archive_path.split("/")[-1]
no_ex = file_n.split(".")[0]
path = "/data/web_static/releases/"
put(archive_path, '/tmp/')
run('mkdir -p {}{}/'.format(path, no_ex))
run('tar -xzf /tmp/{} -C {}{}/'.format(file_name, path, no_ex))
run('rm /tmp/{}'.format(file_name))
run('mv {0}{1}/web_static/* {0}{1}/'.format(path, no_ex))
run('rm -rf {}{}/web_static'.format(path, no_ex))
run('rm -rf /data/web_static/current')
run('ln -s {}{}/ /data/web_static/current'.format(path, no_ex))
=======
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))
>>>>>>> 8c4e35510d77a5ef3680cd4a33a027addfeecf6b
return True
except:
return False


def deploy():
<<<<<<< HEAD
"""creates and distribte the servers"""
=======
"""creates and distributes an archive to the web servers"""
>>>>>>> 8c4e35510d77a5ef3680cd4a33a027addfeecf6b
archive_path = do_pack()
if archive_path is None:
return False
return do_deploy(archive_path)
Binary file added __pycache__/MySQLdb.cpython-310.pyc
Binary file not shown.
Loading