add docker setup

This commit is contained in:
Laura Klünder 2016-12-18 15:54:37 +01:00
parent 1a8b711c62
commit b688076b23
3 changed files with 114 additions and 1 deletions

41
Dockerfile Normal file
View file

@ -0,0 +1,41 @@
FROM debian:jessie
RUN apt-get update && apt-get install -y locales git build-essential \
python3 python3-pip python3-dev \
libpq-dev libmysqlclient-dev libmemcached-dev libgeos-dev gettext \
librsvg2-bin --no-install-recommends
WORKDIR /
RUN dpkg-reconfigure locales && \
locale-gen C.UTF-8 && \
/usr/sbin/update-locale LANG=C.UTF-8
ENV LC_ALL C.UTF-8
RUN apt-get clean && rm -rf /var/lib/apt/lists/*
RUN useradd -ms /bin/bash -d /c3nav -u 15371 c3navuser
RUN echo 'c3navuser ALL=(ALL) NOPASSWD: /usr/bin/supervisord' >> /etc/sudoers
RUN mkdir /etc/c3nav
RUN mkdir /data
RUN mkdir /data/map
COPY src /c3nav/src
WORKDIR /c3nav/src
RUN pip3 install -U pip wheel setuptools
RUN pip3 install -r requirements.txt -r requirements/mysql.txt -r requirements/postgres.txt \
-r requirements/memcached.txt -r requirements/redis.txt gunicorn
RUN mkdir /static && chown -R c3navuser:c3navuser /static /c3nav /data
COPY deployment/docker/c3nav.bash /usr/local/bin/c3nav
RUN chmod +x /usr/local/bin/c3nav
USER c3navuser
EXPOSE 8000
ENTRYPOINT ["c3nav"]
CMD ["all"]

View file

@ -0,0 +1,72 @@
#!/bin/bash
set -e
cd /c3nav/src
export DATA_DIR=/data/
NUM_WORKERS=10
if [ ! -d /data/logs ]; then
mkdir /data/logs;
fi
if [ ! -d /data/media ]; then
mkdir /data/media;
fi
ls /data/map
python3 manage.py migrate --noinput
python3 manage.py loadmap -y
if [ "$1" == "webworker" ]; then
exec gunicorn c3nav.wsgi \
--name c3nav \
--workers $NUM_WORKERS \
--max-requests 1200 \
--max-requests-jitter 50 \
--log-level=info \
--bind=unix:/tmp/c3nav.sock
fi
if [ "$1" == "taskworker" ]; then
export C_FORCE_ROOT=True
exec celery -A c3nav worker -l info
fi
if [ "$1" == "checkmap" ]; then
echo ""
echo "### checking map..."
exec python3 manage.py checkmap
fi
if [ "$1" == "editor" ]; then
echo ""
echo "### starting editor..."
exec python3 manage.py runserver 0.0.0.0:8000
fi
if [ "$1" == "build" ]; then
echo ""
echo "### rendering map..."
python3 manage.py rendermap
echo ""
echo "### building graph..."
exec python3 manage.py buildgraph
fi
if [ "$1" == "all" ]; then
echo ""
echo "### rendering map..."
python3 manage.py rendermap
echo ""
echo "### building graph..."
python3 manage.py buildgraph
echo ""
echo "### running server..."
exec python3 manage.py runserver 0.0.0.0:8000
fi
echo "Specify argument: webworker|taskworker|checkmap|editor|build|all"
exit 1

View file

@ -10,7 +10,7 @@ from django.utils.crypto import get_random_string
from django.utils.translation import ugettext_lazy as _
config = configparser.RawConfigParser()
config.read(['/etc/c3nav/c3nav.cfg', os.path.expanduser('~/.c3nav.cfg'), 'c3nav.cfg'],
config.read(['/etc/c3nav/c3nav.cfg', os.path.expanduser('~/.c3nav.cfg'), os.environ.get('C3NAV_CONFIG', 'c3nav.cfg')],
encoding='utf-8')
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)