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

Dev #19

Open
wants to merge 42 commits into
base: dev
Choose a base branch
from
Open

Dev #19

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
f78d4b9
Add files via upload
redmicelles Feb 10, 2022
560b0a7
Add files via upload
redmicelles Feb 11, 2022
1f2c315
Update setup.sh
redmicelles Feb 11, 2022
3ddfeb5
modify setup.sh to create user
ciradu2204 Feb 11, 2022
5b76137
install.sh file added
iaddokoh1 Feb 13, 2022
da25dbc
create the database and assign it to the mob_db_user
ciradu2204 Feb 14, 2022
4846aa4
created the python-venv
ciradu2204 Feb 14, 2022
f0052a0
Merge branch 'dev' of https://github.com/redmicelles/Mobalysis into dev
ciradu2204 Feb 14, 2022
975455a
install script adjustments
redmicelles Feb 14, 2022
8a59d34
Merge branch 'dev' of https://github.com/redmicelles/mobalysis into dev
redmicelles Feb 14, 2022
c58f784
added the the shell type
ciradu2204 Feb 15, 2022
a916930
create env and install packages
ciradu2204 Feb 15, 2022
bf06cd3
modified python-venv installation
ciradu2204 Feb 15, 2022
9e4a8d0
created venv
redmicelles Feb 15, 2022
0ff3413
created venv
redmicelles Feb 15, 2022
5813340
create the virtualenv and install packages
ciradu2204 Feb 15, 2022
0b04b57
task 7 completed, user creation modified to allow password encryption…
redmicelles Feb 15, 2022
bdfe5b3
task 7 completed
redmicelles Feb 15, 2022
b0af652
install modified to .profile instead of .bashrc
redmicelles Feb 15, 2022
c3e2921
tasks 9 and 10 completed
redmicelles Feb 15, 2022
231057d
error file deleted
redmicelles Feb 15, 2022
99858c8
Update install.sh
redmicelles Feb 15, 2022
6a00b07
Merge branch 'AzubiAfrica:dev' into dev
ciradu2204 Mar 10, 2022
316d403
installed nodeJs
ciradu2204 Mar 14, 2022
8519747
tasks 14 and 15 accomplished
redmicelles Mar 15, 2022
17aba55
Remove the command to check node version
ciradu2204 Mar 15, 2022
a3eb2f5
Updated the if statements by adding space
ciradu2204 Mar 15, 2022
6a1a17f
removed the nodeInstallSh
ciradu2204 Mar 16, 2022
4644f6d
ansibles files added
redmicelles Mar 17, 2022
f80ba1c
Delete nodesource_setup.sh
redmicelles Mar 17, 2022
a3d636e
Merge branch 'dev' of https://github.com/redmicelles/Mobalysis into dev
ciradu2204 Mar 17, 2022
3c4da15
added the frontend playbook tasks
ciradu2204 Mar 17, 2022
04bf548
Delete the ansible.pem
ciradu2204 Mar 17, 2022
b328f97
modified the gitgnore to remove the private key
ciradu2204 Mar 17, 2022
c3ef430
added the ansible server.pem
ciradu2204 Mar 17, 2022
5de11e1
commented the last part
ciradu2204 Mar 18, 2022
e5aae45
installed dependencies
iaddokoh1 Mar 18, 2022
a31b532
added script to run the repo
ciradu2204 Mar 18, 2022
12839b7
updated the frontend.sh
ciradu2204 Mar 18, 2022
f666211
backend configuration
ciradu2204 Apr 6, 2022
8fd611b
updated the files
ciradu2204 Apr 6, 2022
16d89ab
changed files
ciradu2204 Apr 9, 2022
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/ansible_server.pem
/mykeyPair.pem
3 changes: 3 additions & 0 deletions ansible_aws.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
web ansible_host=44.201.191.44 ansible_port=22 ansible_user=ubuntu ansible_ssh_private_key_file=ansible_server.pem
#ansible web -i aws.ini -m ping
#ansible web -i aws.ini -m ping
10 changes: 10 additions & 0 deletions ansible_aws.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
all:
hosts:
web:
ansible_host: 18.215.156.51
ansible_port: 22
ansible_user: ubuntu
ansible_ssh_private_key_file: myKeyPair.pem

#ansible web -i aws.yaml -m ping
#ansible web -i aws.yaml -m ping
28 changes: 28 additions & 0 deletions ansible_playbook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
---
- hosts: web
remote_user: root
become: yes

tasks:
- name: transfer the setup script
copy: src=setup.sh dest=/home mode=0777

- name: execute the script
command: sh /home/setup.sh

- name: transfer the install script for frontend
copy: src=install_frontend.sh dest=/home/mob_app_usr mode=0777

- name: execute the frontend script for frontend
command: sh /home/mob_app_usr/install_frontend.sh

# - name: transfer the backend script
# copy: src=install.sh dest=/home/mob_app_usr mode=0777

# - name: execute the backend script
# command: sh /home/mob_app_usr/install.sh



#ansible-playbook -i ansible_aws.ini ansible_playbook.yaml
#ansible-playbook -i ansible_aws.ini ansible_playbook.yaml
91 changes: 91 additions & 0 deletions install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#!/usr/bin/env bash
#Clone repo and create environment varables
sudo -i -u mob_app_usr bash << EOF

#clone mobalysis repo
git clone -b dev https://github.com/redmicelles/Mobalysis

#set Environment Variables
echo export DBNAME=\'mobalytics\' >> .bashrc
echo export DBUSER=\'mob_db_user\' >> .bashrc
echo export DBPASS=\'mob_db_pass\' >> .bashrc
echo export DBHOST=\'localhost\' >> .bashrc
echo export DBPORT=\'5432\' >> .bashrc

#install env
sudo apt-get install -y python3-venv
#create and activate venv
python3 -m venv ~/Mobalysis/venv
. ~/Mobalysis/venv/bin/activate

#install pip
sudo apt-get install -y python3-pip

#update the settings.py
sed -i 's/'*'/'ec2-18-215-156-51.compute-1.amazonaws.com'/g' ~/Mobalysis/backend/backend/settings.py
echo "STATIC_ROOT = os.path.join(BASE_DIR, 'static/')" >> ~/Mobalysis/backend/backend/settings.py

#create user
sudo -u postgres createuser mob_app_usr

#install a different version of python
sudo apt-get install python3.8-dev

#install a different version of python
sudo apt-get install gcc

#install uwsgi
sudo pip3 install uwsgi

#pip install requirements
sudo pip3 install -r ~/Mobalysis/backend/requirements.txt

#remove old migration
cd /home/mob_app_usr/Mobalysis/backend/api/migrations
rm 0005_auto_20220218_1335.py 0004_auto_20220218_1334.py 0003_auto_20220218_1315.py 0002_auto_20220218_1313.py 0001_initial.py

#makemigrations
python3 ~/Mobalysis/backend/manage.py makemigrations

#migrate django models
python3 ~/Mobalysis/backend/manage.py migrate

#migrate static to the static folder created
python3 ~/Mobalysis/backend/manage.py collectstatic

#create directory for the media files
sudo mkdir /home/mob_app_usr/Mobalysis/backend/media

#create server block configuration files
sudo touch /etc/nginx/sites-available/mobalysis
sudo cp ~/Mobalysis/mobalysis_serverblock /etc/nginx/sites-available/mobalysis

#create add uwsgi_params
sudo touch ~/Mobalysis/backend/uwsgi_params
sudo cp ~/Mobalysis/uwsgi_params ~/Mobalysis/backend/uwsgi_params

#create a symbolic link for nginx to server the backend
sudo ln -s /etc/nginx/sites-available/mobalysis /etc/nginx/sites-enabled/

#
sudo mkdir /home/mob_app_usr/env/env/vassals
sudo ln -s /etc/nginx/sites-available/mobalysis /home/mob_app_usr/env/env/vassals

#make directory for uwsgi
sudo mkdir -p /etc/uwsgi/sites
sudo touch /etc/uwsgi/sites/mobalysis.ini
sudo cp ~/Mobalysis/mobalysis_uwsgi.ini /etc/uwsgi/sites/mobalysis.ini

#make a systemd unitfile for uWSGI
sudo touch /etc/systemd/system/uwsgi.service
sudo cp ~/Mobalysis/uwsgi.service /etc/systemd/system/uwsgi.service

sudo systemctl restart nginx
sudo systemctl start uwsgi

#start automatically at boot
sudo systemctl enable nginx
sudo systemctl enable uwsgi

EOF

55 changes: 55 additions & 0 deletions install_frontend.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#!/bin/bash

# Update packages
sudo apt-get update -y
sudo apt-get upgrade -y

#Add NodeJs PPA to the system
curl -sL https://deb.nodesource.com/setup_16.x -o nodesource_setup.sh
sudo bash nodesource_setup.sh

#install NodeJs
sudo apt install nodejs

if [ $? -eq 0 ]
then
echo "NodeJS successfully created"
else
echo "NodeJs installation failed"
fi

#install Nginx
sudo apt -y install nginx
if [ $? -eq 0 ]
then
echo "Nginx installed sucessfully"
else
echo "Nginx installation failed!"
fi

#Allow Nginx through firewall
sudo ufw allow 'Nginx HTTP'

#Enable and restart Nginx service
sudo systemctl enable nginx
sudo systemctl restart nginx

#remove all the files in nginx
sudo rm -r /var/www/html/*

#CD to WWW directory and clone the frontend directory from the repo
sudo git clone --branch dev https://github.com/redmicelles/Mobalysis /var/www/html/tmp
sudo mv /var/www/html/tmp/frontend /var/www/html
sudo rm -r /var/www/html/tmp

#Install Dependenies
cd /var/www/html/frontend
sudo npm install
sudo npm run build

#move the build files to /var/www/html
sudo mv /var/www/html/frontend/build/* /var/www/html

#delete the frontend
sudo rm -r /var/www/html/frontend

26 changes: 26 additions & 0 deletions mobalysis_serverblock
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
upstream django{
server unix:///home/mob_app_usr/Mobalysis/backend/backend.sock;
}
server {
listen 8080;
server_name ec2-18-215-156-51.compute-1.amazonaws.com www.ec2-18-215-156-51.compute-1.amazonaws.com;
charset utf-8;

location = /favicon.ico { access_log off; log_not_found off; }

#serve static files
location /static/ {
root /home/mob_app_usr/Mobalysis/backend/static;
}

#serve media files
location /media/ {
root /home/mob_app_usr/Mobalysis/backend/media;
}

#serve others
location / {
include /home/mob_app_usr/Mobalysis/backend/uwsgi_params;
uwsgi_pass django;
}
}
19 changes: 19 additions & 0 deletions mobalysis_uwsgi.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[uwsgi]
project=Mobalysis/backend
uid = mob_app_usr
base = /home/%(uid)


chdir = %(base)/%(project)
home = %(base)/Env/%(project)
module = backend.wsgi:application

master = true
processes = 10

socket = /home/mob_app_usr/Mobalysis/backend/backend.sock
#chown-socket = %(uid):www-data
chmod-socket = 666
vacuum = true

daemonize = /home/mob_app_usr/uwsgi-emperor.log
60 changes: 60 additions & 0 deletions setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/bin/bash
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'

wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

sudo apt-get update

sudo apt-get -y install postgresql

sudo systemctl is-active --quiet postgresql

if [ $? -ne 0 ]
then
sudo systemctl start --quiet postgresql
sudo systemctl enable --quiet postgresql
fi

sudo -u postgres psql -c "create user mob_db_user with password 'mob_db_pass';"

echo "Postgresql installation completed"

#create user and home directory
sudo useradd -m -p $(openssl passwd -crypt mob_app_usr) mob_app_usr
if [ $? -eq 0 ]
then
echo "User creation successful"
else
echo "User creation failed"
fi
sudo usermod -aG sudo mob_app_usr

#install python-venv
res=$(python3 -c 'import sys; print(sys.version_info[0])')
if [[ "$res" -eq 3 ]]
then
echo "python 3 version installed"
virtualenv --version
if [[ "$?" -gt 0 ]]
then
sudo apt -y install python3-virtualenv
fi
elif [[ "$res" -eq 2 ]]
then
echo "python 2 version installed"
virtualenv --version
if [[ "$?" -gt 0 ]]
then
sudo apt -y install python-virtualenv
fi
else
echo "python not installed"
sudo apt -y install python3
sudo apt -y install python3-virtualenv
fi

#create the database and assign it to the mob_db_user
sudo -u postgres psql <<EOF
CREATE DATABASE Mobalytics;
ALTER DATABASE Mobalytics OWNER TO mob_db_user;
EOF
15 changes: 15 additions & 0 deletions uwsgi.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[Unit]
Description=uWSGI Emperor service
After=network.target

[Service]
User=mob_app_usr
Restart=always
ExecStart=/home/mob_app_usr/env/env/bin/uwsgi --emperor /home/mob_app_usr/env/env/vassals --uid www-data --gid www-data
RuntimeDirectory=uwsgi
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all

[Install]
WantedBy=multi-user.target
14 changes: 14 additions & 0 deletions uwsgi_params
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
uwsgi_param QUERY_STRING $query_string;
uwsgi_param REQUEST_METHOD $request_method;
uwsgi_param CONTENT_TYPE $content_type;
uwsgi_param CONTENT_LENGTH $content_length;
uwsgi_param REQUEST_URI $request_uri;
uwsgi_param PATH_INFO $document_uri;
uwsgi_param DOCUMENT_ROOT $document_root;
uwsgi_param SERVER_PROTOCOL $server_protocol;
uwsgi_param REQUEST_SCHEME $scheme;
uwsgi_param HTTPS $https if_not_empty;
uwsgi_param REMOTE_ADDR $remote_addr;
uwsgi_param REMOTE_PORT $remote_port;
uwsgi_param SERVER_PORT $server_port;
uwsgi_param SERVER_NAME $server_name;