From fddd6014b92899f6d57619687cf6f3fd324cb0f3 Mon Sep 17 00:00:00 2001 From: Stein Magnus Jodal Date: Sun, 23 Jan 2022 17:47:53 +0100 Subject: [PATCH] Add Dockerfile --- Dockerfile | 50 ++++++++++++++++++++++++++++++++++++++++++++ docker-entrypoint.sh | 20 ++++++++++++++++++ 2 files changed, 70 insertions(+) create mode 100644 Dockerfile create mode 100755 docker-entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..30113562 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +FROM python:3.12.3-slim-bookwor + +ENV DEBIAN_FRONTEND=noninteractive +ENV PYTHONUNBUFFERED=1 + +# Install system dependencies +RUN apt-get update \ + && apt-get install -y \ + curl \ + && rm -rf /var/lib/apt/lists/* + +# Create app user +RUN groupadd app \ + && useradd -g app -d /home/app -s /sbin/nologin app \ + && mkdir -p /home/app \ + && chown -R app:app /home/app + +# Create app directory +RUN mkdir /app \ + && chown -R app:app /app + +# Install system dependencies +RUN pip install --no-cache poetry==1.8.2 + +# Add app directory to Python path +ENV PYTHONPATH=/app + +# Activate app user and change working directory +USER app +WORKDIR /app + +# Install app dependencies +COPY --chown=app ./pyproject.toml ./poetry.toml ./poetry.lock /app/ +RUN poetry install \ + --no-root --no-dev --no-interaction --no-ansi \ + --extras api \ + --extras cache \ + --extras pgsql \ + --extras server + +# Install app +COPY --chown=app ./docker-entrypoint.sh /app/ +COPY --chown=app ./manage.py /app/ +COPY --chown=app ./comics/ /app/comics/ + +# Collect static files +RUN DJANGO_SECRET_KEY=s3cret poetry run python manage.py collectstatic --noinput + +# Entrypoint +ENTRYPOINT ["./docker-entrypoint.sh"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 00000000..9be962d9 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,20 @@ +#!/bin/bash +set -e + +# Simplified entrypoints for the different services packaged in this +# Docker image. + +if [ "$1" = "shell" ]; then + poetry run pip install ipython + exec poetry run python manage.py shell ${*:2} +fi + +if [ "$1" = "migrate" ]; then + exec poetry run python manage.py migrate ${*:2} +fi + +if [ "$1" = "web" ]; then + exec poetry run gunicorn --worker-tmp-dir=/dev/shm --log-file=- --bind=0.0.0.0:$PORT comics.wsgi ${*:2} +fi + +exec "$@"