Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
3cb885d
Airbnb Version 2
Nicholas-Odiwuor Apr 17, 2024
3fd0d87
Code fixing
Nicholas-Odiwuor Apr 17, 2024
87e6024
Console Improvement
Nicholas-Odiwuor Apr 17, 2024
dbb30bb
Console Improvement
Nicholas-Odiwuor Apr 17, 2024
a6afcd4
Console Improvement
Nicholas-Odiwuor Apr 17, 2024
79ff20c
Console Improvement
Nicholas-Odiwuor Apr 17, 2024
7544944
Console Improvement
Nicholas-Odiwuor Apr 17, 2024
b04ef21
Console Improvement
Nicholas-Odiwuor Apr 17, 2024
7988bfc
Console Improvement
Nicholas-Odiwuor Apr 17, 2024
b25255b
Console Improvement
Nicholas-Odiwuor Apr 17, 2024
133a08e
Console Improvement
Nicholas-Odiwuor Apr 17, 2024
3846ed8
Console Improvement
Nicholas-Odiwuor Apr 17, 2024
0e80895
Console Improvement
Nicholas-Odiwuor Apr 17, 2024
658f3af
Console Improvement
Nicholas-Odiwuor Apr 17, 2024
f294908
Console Improvement
Nicholas-Odiwuor Apr 17, 2024
6927758
Console Improvement
Nicholas-Odiwuor Apr 17, 2024
bc207bd
Setup development
Nicholas-Odiwuor Apr 17, 2024
0e898a1
Setup test
Nicholas-Odiwuor Apr 17, 2024
2d21792
Deletion
Nicholas-Odiwuor Apr 17, 2024
568f13f
Storage
Nicholas-Odiwuor Apr 17, 2024
888a0bf
Airbnb
Nicholas-Odiwuor May 3, 2024
3370965
Airbnb
Nicholas-Odiwuor May 3, 2024
d491400
Airbnb
Nicholas-Odiwuor May 3, 2024
a9448d6
Airbnb
Nicholas-Odiwuor May 3, 2024
d9a6d01
Airbnb
Nicholas-Odiwuor May 3, 2024
a09a4ea
Airbnb
Nicholas-Odiwuor May 3, 2024
e7fbbfb
Web Framework
Nicholas-Odiwuor May 18, 2024
3e1b3a2
Web Flask
Nicholas-Odiwuor May 18, 2024
2c069a3
HBNB
Nicholas-Odiwuor May 18, 2024
0bcea2b
C-route
Nicholas-Odiwuor May 18, 2024
9ce02f4
Python-route
Nicholas-Odiwuor May 18, 2024
07f2f47
Number-route
Nicholas-Odiwuor May 18, 2024
7111728
Number_template
Nicholas-Odiwuor May 18, 2024
95b74b1
Odd or even
Nicholas-Odiwuor May 18, 2024
a868634
Web Flask
Nicholas-Odiwuor May 18, 2024
5b799e0
Web Flask
Nicholas-Odiwuor May 18, 2024
344851f
Web Flask
Nicholas-Odiwuor May 18, 2024
b4c820f
Web Flask
Nicholas-Odiwuor May 18, 2024
58e75ff
Web Flask
Nicholas-Odiwuor May 18, 2024
f90a147
8-cities_by_states.html
Nicholas-Odiwuor May 18, 2024
7ba2992
Cities by States
Nicholas-Odiwuor May 18, 2024
b1094b0
Web Flask
Nicholas-Odiwuor May 18, 2024
78786a7
Web Flask
Nicholas-Odiwuor May 18, 2024
095c7e4
HBNB Filters
Nicholas-Odiwuor May 18, 2024
5b0c87e
HBNB Filters
Nicholas-Odiwuor May 18, 2024
706f704
HBNB Filters
Nicholas-Odiwuor May 18, 2024
b574d35
Styles
Nicholas-Odiwuor May 18, 2024
1cc8e99
Styles
Nicholas-Odiwuor May 18, 2024
654012a
Styles
Nicholas-Odiwuor May 18, 2024
2d3b021
Styles
Nicholas-Odiwuor May 18, 2024
d243bef
HBNB
Nicholas-Odiwuor May 18, 2024
19acfc8
HBNB
Nicholas-Odiwuor May 18, 2024
b300fae
HBNB
Nicholas-Odiwuor May 18, 2024
c0b9564
Styles
Nicholas-Odiwuor May 18, 2024
38f09b3
Development setup
Nicholas-Odiwuor Mar 8, 2025
58b5540
Web app
Nicholas-Odiwuor Mar 8, 2025
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
38 changes: 38 additions & 0 deletions 0-setup_web_static.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bash
# Bash script that sets up your web servers for the 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
22 changes: 22 additions & 0 deletions 1-pack_web_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/python3
# Fabric script that generates a .tgz archive from the contents of the web_static folder of AirBnB Clone.
import os.path
from datetime import datetime
from fabric.api import local


def do_pack():
"""Create a tar gzipped archive of the directory web_static."""
dt = datetime.utcnow()
file = "versions/web_static_{}{}{}{}{}{}.tgz".format(dt.year,
dt.month,
dt.day,
dt.hour,
dt.minute,
dt.second)
if os.path.isdir("versions") is False:
if local("mkdir -p versions").failed is True:
return None
if local("tar -cvzf {} web_static".format(file)).failed is True:
return None
return file
29 changes: 29 additions & 0 deletions 100-clean_web_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/python3
# Fabric script that deletes out-of-date archives, using the function do_clean.

import os
from fabric.api import *

env.hosts = ["54.165.55.51", "52.91.147.19"]


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 @@
# Script that sets up my web servers for the deployment of web_static using puppet

# 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 http://cuberule.com/;
}
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/'
}
48 changes: 48 additions & 0 deletions 2-do_deploy_web_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/python3
# Fabric script that distributes archive to my webservers.
import os.path
from fabric.api import env
from fabric.api import put
from fabric.api import run

env.hosts = ["nickom.tech", "52.91.147.19"]


def do_deploy(archive_path):
"""Distributes an archive to a web server.
Args:
archive_path (str): The path of the archive to distribute.
Returns:
If the file doesn't exist at archive_path or an error occurs - False.
Otherwise - True.
"""
if os.path.isfile(archive_path) is False:
return False
file = archive_path.split("/")[-1]
name = file.split(".")[0]

if put(archive_path, "/tmp/{}".format(file)).failed is True:
return False
if run("rm -rf /data/web_static/releases/{}/".
format(name)).failed is True:
return False
if run("mkdir -p /data/web_static/releases/{}/".
format(name)).failed is True:
return False
if run("tar -xzf /tmp/{} -C /data/web_static/releases/{}/".
format(file, name)).failed is True:
return False
if run("rm /tmp/{}".format(file)).failed is True:
return False
if run("mv /data/web_static/releases/{}/web_static/* "
"/data/web_static/releases/{}/".format(name, name)).failed is True:
return False
if run("rm -rf /data/web_static/releases/{}/web_static".
format(name)).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(name)).failed is True:
return False
return True
75 changes: 75 additions & 0 deletions 3-deploy_web_static.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/python3
# Fabric script that creates and distributes archive to my web serves
import os.path
from datetime import datetime
from fabric.api import env
from fabric.api import local
from fabric.api import put
from fabric.api import run

env.hosts = ["54.165.55.51", "52.91.147.19"]


def do_pack():
"""Create a tar gzipped archive of the directory web_static."""
dt = datetime.utcnow()
file = "versions/web_static_{}{}{}{}{}{}.tgz".format(dt.year,
dt.month,
dt.day,
dt.hour,
dt.minute,
dt.second)
if os.path.isdir("versions") is False:
if local("mkdir -p versions").failed is True:
return None
if local("tar -cvzf {} web_static".format(file)).failed is True:
return None
return file


def do_deploy(archive_path):
"""Distributes an archive to a web server.
Args:
archive_path (str): The path of the archive to distribute.
Returns:
If the file doesn't exist at archive_path or an error occurs - False.
Otherwise - True.
"""
if os.path.isfile(archive_path) is False:
return False
file = archive_path.split("/")[-1]
name = file.split(".")[0]

if put(archive_path, "/tmp/{}".format(file)).failed is True:
return False
if run("rm -rf /data/web_static/releases/{}/".
format(name)).failed is True:
return False
if run("mkdir -p /data/web_static/releases/{}/".
format(name)).failed is True:
return False
if run("tar -xzf /tmp/{} -C /data/web_static/releases/{}/".
format(file, name)).failed is True:
return False
if run("rm /tmp/{}".format(file)).failed is True:
return False
if run("mv /data/web_static/releases/{}/web_static/* "
"/data/web_static/releases/{}/".format(name, name)).failed is True:
return False
if run("rm -rf /data/web_static/releases/{}/web_static".
format(name)).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(name)).failed is True:
return False
return True


def deploy():
"""Create and distribute an archive to a web server."""
file = do_pack()
if file is None:
return False
return do_deploy(file)
2 changes: 1 addition & 1 deletion README.md
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ 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>
Loading