Select your groove while you move.
Our project video can be found here (or if you contact one of the authors).
Credits to Joey and Len for the explenation.
sudo apt install postgresql postgresql-server-dev-9.6 postgis python-psycopg2
First configure the database with postgres
user and give this user the password postgres
(or change it in the config file):
sudo su postgres
psql
Then create a role 'app' that will create the database and be used by the application:
CREATE ROLE app WITH LOGIN CREATEDB;
CREATE DATABASE dbtutor OWNER app;
You need to 'trust' the role to be able to login. Add the following line to /etc/postgresql/9.6/main/pg_hba.conf
(you need root access, version may vary). It needs to be the first rule (above local all all peer).
# TYPE DATABASE USER ADDRESS METHOD
# app
local dbtutor app trust
and restart the service. Then initialize the database:
sudo systemctl restart postgresql
psql dbtutor -U app -f sql/schema.sql
virtualenv -p python3 env
source env/bin/activate
pip3 install -r requirements.txt
./install.sh
Don't forget to change all the values in the config.py. (Those password should never be put online (the version on GitHub is just an example))
cd src/ProgDBTutor
flask run
Then visit http://localhost:5000
You can run unittests.py
to check whether everything has been set up correctly.
Follow these steps to create a GCP compute instance.
Via the console https://console.cloud.google.com/, you can create a project and add your team members.
These screenshots explain how to create a VM instance. Feel free to change any settings, this is only a suggestion, but make sure you have enough credit until the end of the semester.
Then in the settings of your instance, under network iterfaces, click View details
.
This brings you to the network configuration page. Here you need to set the external IP address to static:
And create a new firewall rule if you want to run the debug server on port 5000
.
In the VM settings, you can add SSH keys for each team member. The next step explains how to generate an SSH key, if you already have one, you can skip this step.
(Optional) Create SSH key
Use
ssh-keygen
to generate a private and public ssh key-pair. This is used to securely login to the remote server. Follow the instructions of this command. After this, a public and private key file will be created respectively~/.ssh/id_rsa.pub
and~/.ssh/id_rsa
.
Copy the contents of ~/.ssh/id_rsa.pub
to the VM instance.
You should now be able to connect to the server with ssh [username]@[external ip]
.
Optionally you can add the following lines to
~/.ssh/config
:Host ppdb Hostname [external ip] User [username]
Then you can connect simply with
ssh ppdb
These steps demonstrate how to run this application with nginx. They are to be executed in addition to the setup in quick start. Instead of running the built in Flask debug server, we use an industrial grade webserver and reverse proxy server: nginx.
sudo apt install nginx
sudo useradd -m -s /bin/bash app
sudo su - app
git clone https://github.com/JoeyDP/PPDB-Template-App.git
Instead of using the Flask debug server, we use gunicorn to serve the application.
cd src/ProgDBTutor
gunicorn --bind 0.0.0.0:5000 wsgi:app
As an account with sudo acces (not app), copy the file service/webapp.service
to /etc/systemd/system/
and enable the service:
sudo ln -s /home/app/PlaceHolder/service/app.service /etc/systemd/system/
sudo systemctl enable app
sudo systemctl start app
A file src/ProgDBTutor/webapp.sock
should be created.
Link or copy the nginx server block configuration file to the right nginx folders:
sudo ln -s /home/app/PlaceHolder/nginx/app /etc/nginx/sites-available/
sudo ln -s /home/app/PlaceHolder/nginx/app /etc/nginx/sites-enabled/
The contents of this file can be changed for your setup. For example change the IP address to your external IP and add the correct DNS name (team[x].ppdb.me
)
server {
listen 80;
server_name 0.0.0.0 ppdb.me;
location / {
include proxy_params;
proxy_pass http://unix:/home/app/PPDB-Template-App/src/ProgDBTutor/webapp.sock;
}
}
Test the configuration with sudo nginx -t
.
Restart the server with sudo systemctl restart nginx
. Your application should be available on port 80.
journalctl -u app
for viewing the terminal output of your app. (often is a restart required for some reason)systemctl status app
for viewing the status of gunicorn.
Edit configurations > "+" > "Flask Server" > Leave everything as the default, except the "Python interpreter", this must go to [PlaceHoleder Location]/venv/bin/python
The source code is located inside the app folder. The template
folder contains the jinja templates, the static
folder the static files. Each other folder is a seperate app blueprint. routes_drive
is the blueprint containing the information about the creation and search of routes and requests in our route, auth
for authentication, api
contains the code about the api.
You can simulate users by using the datageneration script from here.
Arno Deceuninck, Sam Peeters, Sien Nuyens and Tim Sanders