|
| 1 | +FROM python:3.7-alpine |
| 2 | + |
| 3 | +LABEL description="This container serves as an entry point for our future Django projects." |
| 4 | + |
| 5 | +# Developed for Werbeagentur Christian Aichner by Florian Kleber |
| 6 | +# for terms of use have a look at the LICENSE file. |
| 7 | +MAINTAINER Florian Kleber < [email protected]> |
| 8 | + |
| 9 | +# Add custom environment variables needed by Django or your settings file here: |
| 10 | +ENV DJANGO_DEBUG=on \ |
| 11 | + DJANGO_SETTINGS_MODULE=esite.settings.production |
| 12 | + |
| 13 | +# The uWSGI configuration (customize as needed): |
| 14 | +ENV UWSGI_VIRTUALENV=/venv \ |
| 15 | + UWSGI_UID=1000 \ |
| 16 | + UWSGI_GID=2000 \ |
| 17 | + UWSGI_WSGI_FILE=esite/wsgi_production.py \ |
| 18 | + UWSGI_HTTP=:8000 \ |
| 19 | + UWSGI_MASTER=1 \ |
| 20 | + UWSGI_WORKERS=2 \ |
| 21 | + UWSGI_THREADS=1 |
| 22 | + |
| 23 | +WORKDIR /code/ |
| 24 | + |
| 25 | +# Add pre-installation requirements: |
| 26 | +ADD requirements/ /requirements/ |
| 27 | + |
| 28 | +# Update, install and cleaning: |
| 29 | +RUN echo "## Installing base ##" && \ |
| 30 | + echo "@main http://dl-cdn.alpinelinux.org/alpine/edge/main/" >> /etc/apk/repositories && \ |
| 31 | + echo "@testing http://dl-cdn.alpinelinux.org/alpine/edge/testing/" >> /etc/apk/repositories && \ |
| 32 | + echo "@community http://dl-cdn.alpinelinux.org/alpine/edge/community/" >> /etc/apk/repositories && \ |
| 33 | + apk upgrade --update-cache --available && \ |
| 34 | + \ |
| 35 | + apk add --no-cache --virtual .build-deps \ |
| 36 | + gcc \ |
| 37 | + g++ \ |
| 38 | + make \ |
| 39 | + libc-dev \ |
| 40 | + musl-dev \ |
| 41 | + linux-headers \ |
| 42 | + pcre-dev \ |
| 43 | + postgresql-dev \ |
| 44 | + libjpeg-turbo-dev \ |
| 45 | + zlib-dev \ |
| 46 | + expat-dev \ |
| 47 | + ;\ |
| 48 | + apk add --force \ |
| 49 | + git@main \ |
| 50 | + bash@main \ |
| 51 | + libjpeg-turbo@main \ |
| 52 | + pcre@main \ |
| 53 | + postgresql-client@main \ |
| 54 | + tini@community \ |
| 55 | + \ |
| 56 | + && python -m venv /venv \ |
| 57 | + && /venv/bin/pip install -U pip \ |
| 58 | + && LIBRARY_PATH=/lib:/usr/lib /bin/sh -c "/venv/bin/pip install -r /requirements/production.txt" \ |
| 59 | + && runDeps="$( \ |
| 60 | + scanelf --needed --nobanner --recursive /venv \ |
| 61 | + | awk '{ gsub(/,/, "\nso:", $2); print "so:" $2 }' \ |
| 62 | + | sort -u \ |
| 63 | + | xargs -r apk info --installed \ |
| 64 | + | sort -u \ |
| 65 | + )" \ |
| 66 | + && apk add --virtual .python-rundeps $runDeps \ |
| 67 | + && apk del .build-deps \ |
| 68 | + && rm -rf /tmp/* /var/tmp/* /var/cache/apk/* /var/cache/distfiles/* |
| 69 | + |
| 70 | +EXPOSE 8000 |
| 71 | + |
| 72 | +VOLUME /code/media |
| 73 | + |
| 74 | +ADD . /code/ |
| 75 | + |
| 76 | +# Place init, make it executable and |
| 77 | +# make sure venv files can be used by uWSGI process: |
| 78 | +RUN mv /code/docker-entrypoint.sh / ;\ |
| 79 | + chmod +x /docker-entrypoint.sh ;\ |
| 80 | + find /venv/ -type f -iname "*.py" -exec chmod -v +x {} ;\ |
| 81 | + \ |
| 82 | + # Call collectstatic with dummy environment variables: |
| 83 | + DATABASE_URL=postgres://none REDIS_URL=none /venv/bin/python manage.py collectstatic --noinput |
| 84 | + |
| 85 | +# I personally like to start my containers with tini |
| 86 | +# which start uWSGI, using a wrapper script to allow us to easily add |
| 87 | +# more commands to container startup: |
| 88 | +ENTRYPOINT ["/sbin/tini", "--", "/docker-entrypoint.sh"] |
| 89 | + |
| 90 | +CMD ["/venv/bin/uwsgi", "--http-auto-chunked", \ |
| 91 | + "--http-keepalive", \ |
| 92 | + "--static-map", \ |
| 93 | + "/media/=/code/media/"\ |
| 94 | +] |
| 95 | + |
| 96 | +# SPDX-License-Identifier: (EUPL-1.2) |
| 97 | +# Copyright © 2019 Werbeagentur Christian Aichner |
0 commit comments