-
Notifications
You must be signed in to change notification settings - Fork 4
Deployment
In order to deploy this project you need to a have a system with docker and docker-compose available and optionally a job scheduler such as Vixie Cron for the ability to automatically start and update the docker container images. Also Nginx or Apache is required for the intended use case, of which, only Nginx examples are provided.
Dockerhub builds automatically the frontend and backend images for both master and dev branches with tags production and dev respectively. These autobuilds are done regardless of the results in Travis builds.
There are no high likelihoods for serious errors hitting the master branch, since our project codebase is organized by having master, dev and feature branches where features are merged into dev via pull requests, which are, reviewed by peers, and successively the dev branch into master under supervision. Hence, there is not currently any need for a more sophisticated build chain (e.g. building the docker container images in Travis and pushing them to Dockerhub, that is, only if the prior tests pass).
Current actual working docker-compose.yml file without TOKEN and SECRET values:
version: '2'
services:
web:
environment:
- REACT_APP_BACKEND_URL=https://example.com/path/to/backend
- PUBLIC_URL=https://example.com/path/to/frontend
- NODE_ENV=production
image: labtool/labtool:production
ports:
- "6000:3000"
depends_on:
- backend
- db
backend:
environment:
- TOKEN=CHANGE_ME_TO_ACTUAL_TOKEN
- NODE_ENV=production
- SECRET=LONG_RANDOM_STRING_HERE
- DB_USERNAME=postgres
- DB_PASSWORD=verysecret
- DB_NAME=labtool_production
- DB_HOST=db
- ADMIN_PW=changeme
- KURKI_URL=https://opetushallinto.cs.helsinki.fi
- FRONTEND_URL=https://example.com/path/to/frontend
image: labtool/labtool-backend:production
ports:
- "6001:3001"
depends_on:
- db
db:
environment:
PGDATA: /data/pg10.1_labtool_2018k
volumes:
- /data/pg10.1_labtool_2018k:/data/pg10.1_labtool_2018k
image: postgres:10.1
restart: unless-stopped*note that in this example we are choosing production tag from both frontend and backend tags.
In your local docker-compose.yml file please do change the environment variables TOKEN, SECRET, BACKEND_LOGIN_URL, PUBLIC_URL along with the variables for the database. The following describes the use for the variables:
- TOKEN is used to authenticate requests with the api that provides actual course data.
- SECRET is a long string of random characters and numbers which is used as a salt when generating tokens for frontend users.
- PUBLIC_URL is what the default create-react-app based frontend uses as it's base uri.
- REACT_APP_BACKEND_URL is not used as of yet but would make the code cleaner.
- DB_USERNAME is the username which is used to login into PostgreSQL database.
- DB_PASSWORD is the password which is used to login into PostgreSQL database.
- DB_NAME is the name of the database in use.
- DB_HOST is the hostname of the database server.
- ADMIN_PW is the password used to access the backend admin page.
- KURKI_URL defines the uri of university administration server to be used.
- FRONTEND_URL is used to link users to the correct page from email notifications.
Make sure that the update.sh is executable by your system super user. This because super user privileges are a requirement for running docker containers.
#!/bin/sh
PATH=/usr/local/bin:/usr/sbin:/usr/sbin:/usr/bin:/sbin:/bin
# CHANGE ME
DOCKER_COMPOSE_YML_DIR=/root/ohtuprojekti_2018k
cd $DOCKER_COMPOSE_YML_DIR
DCOMPOSE=`which docker-compose`
$DCOMPOSE down
$DCOMPOSE pull
$DCOMPOSE up
#!/bin/sh
docker rmi `docker images -f "dangling=true"|grep labtool|awk '{print $3}'`Crontab lines in this case to start at system startup and daily at 4 AM restart with automatic update:
@reboot /root/ohtuprojekti_2018k/update.sh >/dev/null 2>&1
0 4 * * * /root/ohtuprojekti_2018k/update.sh >/dev/null 2>&1
5 4 * * 7 /root/ohtuprojekti_2018k/docker-cleanup.sh >/dev/null 2>&1
Our development test server is set to run every 15 minutes. For that reason it might be useful to have another script that cleans old container images and have it run periodically. In this case we run it every Sunday at 4:05 AM.
If you feel the need to disable the cronjobs, you can do it the following way:
First you need to contact the remote server, containing the development branch code. At the server do the following:
sudo -i
crontab -e
Then comment out the lines you wish to disable and exit by pressing
ctrl + x
ctrl + c
and answer the prompted questions.
under http server create two locations as following:
location /labtool/ {
proxy_pass http://localhost:6000/;
}
location /labtool-backend/ {
proxy_pass http://localhost:6001/;
}
*http to https rewrite config yet to be added (in apache terms mod_rewrite).
The SSL sertificate for studies.cs.helsinki.fi will be used for the test production server and assuming on the actual production server.