diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..3bfae3c --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +FROM phusion/baseimage:0.9.17 +MAINTAINER Jethro Yu + +RUN echo 'APT::Get::Clean=always;' >> /etc/apt/apt.conf.d/99AutomaticClean + +RUN apt-get update -qqy +RUN DEBIAN_FRONTEND=noninteractive apt-get -qyy install \ + -o APT::Install-Suggests=false \ + git python-virtualenv python-dev libxml2-dev libvirt-dev zlib1g-dev nginx libsasl2-modules + +ADD . /srv/webvirtcloud +RUN chown -R www-data:www-data /srv/webvirtcloud + +# Setup webvirtcloud +RUN cd /srv/webvirtcloud && \ + virtualenv venv && \ + . venv/bin/activate && \ + pip install -U pip && \ + pip install -r conf/requirements.txt && \ + chown -R www-data:www-data /srv/webvirtcloud + +RUN cd /srv/webvirtcloud && . venv/bin/activate && \ + python manage.py migrate && \ + chown -R www-data:www-data /srv/webvirtcloud + +# Setup Nginx +RUN echo "\ndaemon off;" >> /etc/nginx/nginx.conf && \ + rm /etc/nginx/sites-enabled/default && \ + chown -R www-data:www-data /var/lib/nginx + +ADD conf/nginx/webvirtcloud.conf /etc/nginx/conf.d/ + +# Register services to runit +RUN mkdir /etc/service/nginx && \ + mkdir /etc/service/nginx-log-forwarder && \ + mkdir /etc/service/webvirtcloud && \ + mkdir /etc/service/novnc +ADD conf/runit/nginx /etc/service/nginx/run +ADD conf/runit/nginx-log-forwarder /etc/service/nginx-log-forwarder/run +ADD conf/runit/novncd.sh /etc/service/novnc/run +ADD conf/runit/webvirtcloud.sh /etc/service/webvirtcloud/run + +EXPOSE 80 +EXPOSE 6080 + +# Define mountable directories. +#VOLUME [] + +# Use baseimage-docker's init system. +CMD ["/sbin/my_init"] diff --git a/conf/runit/nginx b/conf/runit/nginx new file mode 100755 index 0000000..a7cd558 --- /dev/null +++ b/conf/runit/nginx @@ -0,0 +1,9 @@ +#!/bin/bash +set -e +if [[ ! -e /var/log/nginx/error.log ]]; then + # The Nginx log forwarder might be sleeping and waiting + # until the error log becomes available. We restart it in + # 1 second so that it picks up the new log file quickly. + (sleep 1 && sv restart /etc/service/nginx-log-forwarder) +fi +exec /usr/sbin/nginx diff --git a/conf/runit/nginx-log-forwarder b/conf/runit/nginx-log-forwarder new file mode 100755 index 0000000..07d63c6 --- /dev/null +++ b/conf/runit/nginx-log-forwarder @@ -0,0 +1,8 @@ +#!/bin/bash +# Forwards the Nginx error.log to the Docker logs. +set -e +if [[ -e /var/log/nginx/error.log ]]; then + exec tail -F /var/log/nginx/error.log +else + exec sleep 10 +fi diff --git a/conf/runit/novncd.sh b/conf/runit/novncd.sh new file mode 100755 index 0000000..99089d7 --- /dev/null +++ b/conf/runit/novncd.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# `/sbin/setuser www-data` runs the given command as the user `www-data`. +cd /srv/webvirtcloud +exec /sbin/setuser www-data /srv/webvirtcloud/venv/bin/python /srv/webvirtcloud/console/novncd >> /var/log/novncd.log 2>&1 diff --git a/conf/runit/webvirtcloud.sh b/conf/runit/webvirtcloud.sh new file mode 100755 index 0000000..179e34f --- /dev/null +++ b/conf/runit/webvirtcloud.sh @@ -0,0 +1,4 @@ +#!/bin/sh +# `/sbin/setuser www-data` runs the given command as the user `www-data`. +cd /srv/webvirtcloud +exec /sbin/setuser www-data /srv/webvirtcloud/venv/bin/gunicorn webvirtcloud.wsgi:application -c /srv/webvirtcloud/gunicorn.conf.py >> /var/log/webvirtcloud.log 2>&1