Loading Dockerfile 0 → 100644 +79 −0 Original line number Diff line number Diff line # syntax = docker/dockerfile:1.3-labs ### BUILD # FROM quay.io/pypa/manylinux2014_x86_64 as build ## Install dependencies # RUN yum install -y \ # mariadb-devel \ # wget FROM python:3.9-slim as build RUN apt update && apt install -y libmariadb-dev build-essential COPY --from=docker.kodo.org.uk/kodo.org.uk/docker/docker-build-helpers:latest \ /scripts /bin ## Build python wheels WORKDIR /pkg RUN --mount=type=bind,source=kodo_sso,target=/src/kodo_sso \ --mount=type=bind,source=util,target=/src/util \ --mount=type=bind,source=setup.py,target=/src/setup.py \ pip install --prefer-binary /src gunicorn mysqlclient whitenoise RUN <<END_SCRIPT set -eu find /usr/local/lib/python3.9/lib-dynload \ -name '_tkinter.*' -prune \ -o -type f -print0 | xargs -0 collect-binaries \ /bin/sh \ /usr/local/bin/python3.9 \ /usr/local/lib/libpython3.9.so* ln -s python3.9 /stage/usr/local/bin/python cp /usr/local/bin/kodo-sso /stage/bin/ mkdir -p /stage/usr/local/lib/python3.9 { find /usr/local/lib/python3.9/ \ -mindepth 1 -maxdepth 1 \ \( \ -name site-packages \ -o -name lib-dynload \ -o -name 'config-*' \ -o -name unittest \ \) -prune -o -print find /usr/local/lib/python3.9/site-packages \ -mindepth 1 -maxdepth 1 \ \( \ -name 'README.txt' \ -o -name '*distutils*' \ -o -name 'pip*' \ -o -name 'setuptools*' \ -o -name 'wheel*' \ \) -prune -o -print } | while read fname; do cp -r "$fname" /stage/usr/local/lib/python3.9/ done END_SCRIPT ### INSTALL # FROM python:3.7-slim as final FROM scratch as final LABEL uk.org.kodo.maintainer = "Dom Sekotill <dom.sekotill@kodo.org.uk>" LABEL maintainer = "Dom Sekotill <dom.sekotill@kodo.org.uk>" COPY --from=build /stage/ / WORKDIR /app COPY docker/gunicorn_conf.py /app/gunicorn_conf.py ENV LD_LIBRARY_PATH=/lib:/usr/local/lib ENV PYTHONPATH=/app ENV STATIC_ROOT=/app/static ENV DJANGO_SETTINGS_MODULE=gunicorn_conf RUN kodo-sso collectstatic --noinput COPY docker/entrypoint.sh /bin/entrypoint ENTRYPOINT ["/bin/entrypoint"] CMD ["run"] docker/entrypoint.sh 0 → 100755 +20 −0 Original line number Diff line number Diff line #!/bin/sh set -eu command_run() { while [ $# -gt 0 ]; do case "$1" in *) echo >&2 "Unknown argument: $1"; exit 2 ;; esac shift done kodo-sso migrate --fake-initial exec gunicorn --config python:gunicorn_conf gunicorn_conf } command="${1}"; shift case "${command}" in run) command_run "$@" ;; createsuperuser|collectstatic) exec kodo-sso "${command}" "$@" ;; *) exec "${command}" "$@" ;; esac docker/gunicorn_conf.py 0 → 100644 +24 −0 Original line number Diff line number Diff line import os import random ## Django configs from kodo_sso.settings.production import * ALLOWED_HOSTS = ['*'] WHITENOISE_MAX_AGE = 365 * 24 * 3600 SECRET_KEY = bytes(random.randrange(32, 127) for _ in range(20)).decode() MIDDLEWARE_CLASSES = ('whitenoise.middleware.WhiteNoiseMiddleware',) + MIDDLEWARE_CLASSES ## Gunicorn configs # kodo_sso.wsgi MUST be loaded after Django settings from kodo_sso.wsgi import application bind = ['0.0.0.0:80'] preload_app = True proxy_allow_ips = '*' # import aiohttp.worker # worker_class = aiohttp.worker.GunicornWebWorker Loading
Dockerfile 0 → 100644 +79 −0 Original line number Diff line number Diff line # syntax = docker/dockerfile:1.3-labs ### BUILD # FROM quay.io/pypa/manylinux2014_x86_64 as build ## Install dependencies # RUN yum install -y \ # mariadb-devel \ # wget FROM python:3.9-slim as build RUN apt update && apt install -y libmariadb-dev build-essential COPY --from=docker.kodo.org.uk/kodo.org.uk/docker/docker-build-helpers:latest \ /scripts /bin ## Build python wheels WORKDIR /pkg RUN --mount=type=bind,source=kodo_sso,target=/src/kodo_sso \ --mount=type=bind,source=util,target=/src/util \ --mount=type=bind,source=setup.py,target=/src/setup.py \ pip install --prefer-binary /src gunicorn mysqlclient whitenoise RUN <<END_SCRIPT set -eu find /usr/local/lib/python3.9/lib-dynload \ -name '_tkinter.*' -prune \ -o -type f -print0 | xargs -0 collect-binaries \ /bin/sh \ /usr/local/bin/python3.9 \ /usr/local/lib/libpython3.9.so* ln -s python3.9 /stage/usr/local/bin/python cp /usr/local/bin/kodo-sso /stage/bin/ mkdir -p /stage/usr/local/lib/python3.9 { find /usr/local/lib/python3.9/ \ -mindepth 1 -maxdepth 1 \ \( \ -name site-packages \ -o -name lib-dynload \ -o -name 'config-*' \ -o -name unittest \ \) -prune -o -print find /usr/local/lib/python3.9/site-packages \ -mindepth 1 -maxdepth 1 \ \( \ -name 'README.txt' \ -o -name '*distutils*' \ -o -name 'pip*' \ -o -name 'setuptools*' \ -o -name 'wheel*' \ \) -prune -o -print } | while read fname; do cp -r "$fname" /stage/usr/local/lib/python3.9/ done END_SCRIPT ### INSTALL # FROM python:3.7-slim as final FROM scratch as final LABEL uk.org.kodo.maintainer = "Dom Sekotill <dom.sekotill@kodo.org.uk>" LABEL maintainer = "Dom Sekotill <dom.sekotill@kodo.org.uk>" COPY --from=build /stage/ / WORKDIR /app COPY docker/gunicorn_conf.py /app/gunicorn_conf.py ENV LD_LIBRARY_PATH=/lib:/usr/local/lib ENV PYTHONPATH=/app ENV STATIC_ROOT=/app/static ENV DJANGO_SETTINGS_MODULE=gunicorn_conf RUN kodo-sso collectstatic --noinput COPY docker/entrypoint.sh /bin/entrypoint ENTRYPOINT ["/bin/entrypoint"] CMD ["run"]
docker/entrypoint.sh 0 → 100755 +20 −0 Original line number Diff line number Diff line #!/bin/sh set -eu command_run() { while [ $# -gt 0 ]; do case "$1" in *) echo >&2 "Unknown argument: $1"; exit 2 ;; esac shift done kodo-sso migrate --fake-initial exec gunicorn --config python:gunicorn_conf gunicorn_conf } command="${1}"; shift case "${command}" in run) command_run "$@" ;; createsuperuser|collectstatic) exec kodo-sso "${command}" "$@" ;; *) exec "${command}" "$@" ;; esac
docker/gunicorn_conf.py 0 → 100644 +24 −0 Original line number Diff line number Diff line import os import random ## Django configs from kodo_sso.settings.production import * ALLOWED_HOSTS = ['*'] WHITENOISE_MAX_AGE = 365 * 24 * 3600 SECRET_KEY = bytes(random.randrange(32, 127) for _ in range(20)).decode() MIDDLEWARE_CLASSES = ('whitenoise.middleware.WhiteNoiseMiddleware',) + MIDDLEWARE_CLASSES ## Gunicorn configs # kodo_sso.wsgi MUST be loaded after Django settings from kodo_sso.wsgi import application bind = ['0.0.0.0:80'] preload_app = True proxy_allow_ips = '*' # import aiohttp.worker # worker_class = aiohttp.worker.GunicornWebWorker