Unverified Commit cedea272 authored by Thom Wiggers's avatar Thom Wiggers 📐
Browse files

Add docker image

parent 7046acf8
FROM python:3.5-alpine
MAINTAINER Thom Wiggers <thom@thomwiggers.nl>
LABEL version=1.0
LABEL description="Contains the Thaliawebsite Django application"
# Try to keep static operation on top to maximise Docker cache utilisation
# Disable output buffering
ENV DJANGO_PRODUCTION 1
ENV PYTHONUNBUFFERED 1
# Create log dir
RUN mkdir /log/
RUN touch /log/uwsgi.log
# Create app directory
RUN mkdir -p /usr/src/app
# Create entry points
WORKDIR /usr/local/bin
COPY resources/entrypoint.sh /usr/local/bin/entrypoint.sh
COPY resources/entrypoint_production.sh /usr/local/bin/entrypoint_production.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint_production.sh
# Install dependencies
RUN apk add --no-cache \
gettext \
bash \
postgresql-client \
libwebp \
tiff \
zlib \
freetype \
uwsgi \
lcms2 \
libjpeg-turbo \
nodejs
# Install build deps
RUN apk add --no-cache --virtual .builddeps \
build-base \
tiff-dev \
libjpeg-turbo-dev \
zlib-dev \
freetype-dev \
lcms2-dev \
libwebp-dev \
postgresql-dev
WORKDIR /usr/src/app
# install python requirements
COPY requirements.txt /usr/src/app/
COPY production-requirements.txt /usr/src/app/
RUN pip install --no-cache-dir \
-r requirements.txt \
-r production-requirements.txt
# Install nodejs-less
RUN npm install -g less mkdirp
RUN apk del .builddeps
# copy app source
COPY website /usr/src/app/
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["--help"]
version: '2'
services:
postgres:
image: postgres
environment: &postgresvars
POSTGRES_DB: thalia
web:
build: .
command: runserver 0.0.0.0:8000
ports:
- 8000:8000
depends_on:
- postgres
volumes:
- ./website:/usr/src/app
environment:
<<: *postgresvars
DJANGO_DEBUG: 'True'
DJANGO_POSTGRES_HOST: postgres
#!/bin/bash
set -e
until psql -h "$DJANGO_POSTGRES_HOST" -U "postgres" -c '\l'; do
>&2 echo "PostgreSQL is unavailable: Sleeping"
sleep 5
done
>&2 echo "PostgreSQL is up"
cd /usr/src/app
>&2 echo "Running ./manage.py $@"
./manage.py $@
#!/bin/bash
set -e
until psql -h "$DJANGO_POSTGRES_HOST" -U "postgres" -c '\l'; do
>&2 echo "PostgreSQL is unavailable: Sleeping"
sleep 5
done
>&2 echo "PostgreSQL is up"
cd /usr/src/app
>&2 echo "Running site with uwsgi"
uwsgi --chdir /usr/src/app \
--socket :8000 \
--threads 2 \
--processes 4 \
--module thaliawebsite.wsgi:application \
--lazy-app \
--harakiri 20 \
--max-requests 5000 \
--vacuum \
--logto '/log/uwsgi.log'
# flake8: noqa
import os
from .settings import *
try:
from .localsettings import *
except ImportError:
pass
if os.environ.get('DJANGO_PRODUCTION'):
from .production import *
"""
Django settings for thaliawebsite project.
Docker version
"""
import os
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = os.environ.get(
'DJANGO_SECRET',
'#o-0d1q5&^&06tn@8pr1f(n3$crafd++^%sacao7hj*ea@c)^t')
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = os.environ.get('DJANGO_DEBUG') == 'True'
ALLOWED_HOSTS = os.environ.get('DJANGO_HOSTS', '').split(',')
ROOT_URLCONF = 'thaliawebsite.urls'
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': os.environ.get('POSTGRES_USER'),
'USER': 'postgres',
'DATABASE': os.environ.get('POSTGRES_DB'),
'HOST': os.environ.get('DJANGO_POSTGRES_HOST'),
'PORT': 5432,
}
}
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/dev/howto/static-files/
# Where to store uploaded files
MEDIA_ROOT = os.path.join('/', 'media')
MEDIA_URL = '/media/' # Public is included by the db fields
SENDFILE_BACKEND = 'sendfile.backends.development'
STATIC_URL = '/static/'
STATIC_ROOT = '/static'
COMPRESS_ENABLED = True
COMPRESS_PRECOMPILERS = (
('text/less', 'lessc {infile} {outfile}'),
)
COMPRESS_CSS_FILTERS = ['compressor.filters.css_default.CssAbsoluteFilter',
'compressor.filters.cssmin.rCSSMinFilter']
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment