Skip to content
This repository has been archived by the owner on Feb 10, 2022. It is now read-only.

Deployment with Docker

MrSerth edited this page Oct 23, 2015 · 2 revisions

Setup

Docker:

We use this docker image for deployment: https://hub.docker.com/r/mammooc/mammooc.org/

You have to modify the docker-compose.yml and include your own environment variables. Run the following commands from the same working directory in order to set up your instance of mammooc:

docker-compose pull mammooc/mammooc.org
docker-compose run web rake db:create db:setup
docker-compose up

Run as a service:

Just create a new service file located in /etc/init/mammooc.conf with the following content:

description "mammooc init script"

respawn
respawn limit 10 5
umask 022

chdir <mammooc working directory>

setuid <user name>
setgid <group name>

exec docker-compose up

Control this service using service mammooc [start|stop|restart].

Update your mammooc installation:

#!/bin/bash

if [ "$CRON" == "true" ]; then
	exec 3>&1
	exec 1>/dev/null
fi

echo "mammooc.org: Checking for new version"

set -e
IMAGE="mammooc/mammooc.org"
docker pull $IMAGE
CONTAINER_ID=$(docker ps | grep $IMAGE | awk '{print $1}')
LATEST_IMAGE=`docker inspect --format "{{.Id}}" $IMAGE`
RUNNING_IMAGE=`docker inspect --format "{{.Image}}" $CONTAINER_ID`

echo "Latest mammooc.org version:" $LATEST_IMAGE
echo "Running mammooc.org version:" $RUNNING_IMAGE

if [ $LATEST_IMAGE != $RUNNING_IMAGE ]; then
	if [ "$CRON" == "true" ]; then
		exec 1>&3
	fi
	echo "mammooc.org: Installing update"
	service mammooc restart
	echo "mammooc.org: Waiting for container reboot..."
	sleep 80s
	echo "mammooc.org: Done"
else
	echo "mammooc.org: Already up to date"
fi

You can automatically update the Docker images by using the following cron job. This will cause to check and install available updates every two hours (12 am, 2 am, ...).

# update mammooc.org if necessary
0  */2 *   *   *     CRON=true bash '/<path to script>/update.sh'

Connect to the docker image:

docker exec -it <docker container ID> bash