Skip to content

Commit

Permalink
Add Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
jodal committed Jun 24, 2024
1 parent c1567ef commit fddd601
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
50 changes: 50 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
20 changes: 20 additions & 0 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"

0 comments on commit fddd601

Please sign in to comment.