-
Notifications
You must be signed in to change notification settings - Fork 0
Deployment
Since we're using Docker, it's actually quite trivial to deploy the entire application for production. There are two containers running simultaneously: db
and server
. The db
container contains a PostgreSQL database containing our Database Schema. And the server
container contains the Django HTTP server running on port 8000.
First of all, make sure your server is correctly setup with user accounts secured with ssh keys, disabled root login through ssh and added a basic firewall. You can use this guide from DigitalOcean - Initial Server Setup. You also need to install a version of Docker, which is demonstrated in this guide from DigitalOcean - How To Install and Use Docker.
The first step is to clone the latest release to your server, it's advised you place it in some location where other users can access it too. We can also set up some additional permissions.
$ sudo addgroup lopeningent-dev
$ sudo adduser <your-name-here> lopeningent-dev
$ sudo mkdir /opt/lopeningent
$ sudo chown <your-name-here>:lopeningent-dev /opt/lopeningent
$ sudo chmod 770 /opt/lopeningent
$ sudo git pull https://github.com/oSoc17/lopeningent_backend.git /opt/lopeningent
After this is done, you should have a group lopeningent-dev
to which you can add users if you want to give them access to the /opt/lopeningent
folder containing the latest source code of the project.
Oh, and while you're at it, make sure the port 8000 is enabled through ufw
or whatever firewall you're using.
$ sudo ufw allow 8000
$ sudo ufw disable
$ sudo ufw enable
Now we can build the containers by doing the following:
$ cd /opt/lopeningent
$ docker-compose build
Once that's done we need to populate the database with the latest OSM data, there's a script for that! We can run the update.sh command inside the server container's /opt/lig-data
folder, which holds the /data
folder in our project.
$ docker-compose run server /opt/lig-data/update.sh
There's a big chance there will be some error when trying to populate the database, might be because the database hasn't been loaded yet. If that's the case you can try the command a second time, after that it should work.
Finally, you can start the server for the first time by using the following command. Additionally you can do it in detached mode (in the background) by using the -d
flag.
$ docker-compose up -d
Might fail the first time, again, you can just run in twice and it should work.
There are a few things missing which should be added for a real production environment. Currently, the PostgreSQL database isn't using a password because it's running on localhost. This is fine for our testing purposes but in a real environment you should probably consider adding one. Additionally, you might want to keep your passwords in an environment variable so they don't get pushed to GitHub.
Another major thing that's missing is a more robust HTTP server in front of the Django server. Originally this was gunicorn
but I think it might be better to migrate to nginx
or use both. You should also consider getting an HTTPS certificate from Letsencrypt. As these are all things we needed a domain name for, we haven't been able to set that up yet. But I can point you in the direction of some resources that could help with this, namely: gunicorn, nginx/letsencrypt docker container.
Students
Gerwin Dox -
Tim Baccaert -
Redouane Arroubai -
Simon Neuville -
Gregory De Crock -
Hendrik Depauw -
Lorenz van Herwaarden -
Maxim Deweirdt -
Nick Aelterman -
Olivier Cammaert
Supervisors
Krishna Kumar Thirukokaranam Chandrasekar -
Florian Vandecasteele -
Steven Verstockt
Partners
imec - IDLab - Ghent University