2022-10-28 22:16:23 +02:00
|
|
|
##############################################
|
|
|
|
# write git info
|
|
|
|
##############################################
|
2024-12-09 12:38:08 +01:00
|
|
|
FROM alpine/git:2.47.1 AS git
|
2022-10-28 22:16:23 +02:00
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
COPY .git /app/.git/
|
|
|
|
RUN git describe --tags --always > /git-describe
|
|
|
|
RUN git rev-parse HEAD > /git-commit
|
|
|
|
RUN date +'%Y-%m-%d %H:%M %Z' > /build-date
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##############################################
|
|
|
|
# Main image
|
|
|
|
##############################################
|
2024-12-09 12:38:07 +01:00
|
|
|
FROM python:3.13.1-slim-bullseye AS final
|
2022-10-28 22:16:23 +02:00
|
|
|
|
|
|
|
ARG DEBIAN_FRONTEND=noninteractive
|
|
|
|
|
|
|
|
# Setup user & group
|
|
|
|
##############################################
|
|
|
|
RUN groupadd -g 1000 django
|
|
|
|
RUN useradd -M -d /app -u 1000 -g 1000 -s /bin/bash django
|
|
|
|
|
|
|
|
# Setup system
|
|
|
|
##############################################
|
|
|
|
RUN apt-get update -y \
|
|
|
|
&& apt-get install -y --no-install-recommends \
|
|
|
|
libxml2 \
|
2022-12-19 21:59:25 +01:00
|
|
|
media-types
|
2022-10-28 22:16:23 +02:00
|
|
|
|
|
|
|
# Create directory structure
|
|
|
|
##############################################
|
|
|
|
WORKDIR /app
|
2022-12-10 01:00:10 +01:00
|
|
|
COPY --chown=django:django pyproject.toml requirements.txt ./
|
2022-10-28 22:16:23 +02:00
|
|
|
ADD --chown=django:django ./src ./src
|
|
|
|
COPY --chown=django:django tasks.py ./tasks.py
|
|
|
|
|
2022-10-31 09:10:14 +01:00
|
|
|
RUN mkdir -p /app/data /app/db
|
|
|
|
RUN chown django:django /app /app/data /app/db
|
|
|
|
|
2022-12-10 01:00:10 +01:00
|
|
|
ENV STATIC_ROOT=/app/static
|
2022-10-31 09:10:14 +01:00
|
|
|
ENV SECRET_KEY "changeme"
|
|
|
|
ENV DEBUG "false"
|
|
|
|
ENV DATABASE_URL "sqlite:////app/db/db.sqlite3"
|
2022-10-28 22:16:23 +02:00
|
|
|
|
2022-12-10 01:27:39 +01:00
|
|
|
RUN python -m pip install --no-cache-dir -r requirements.txt
|
2022-12-10 01:00:10 +01:00
|
|
|
WORKDIR /app/src
|
|
|
|
RUN python manage.py collectstatic --noinput --clear
|
|
|
|
|
2024-02-11 12:59:28 +01:00
|
|
|
# Copy git info
|
|
|
|
##############################################
|
|
|
|
COPY --chown=django:django --from=git /git-describe /git-commit /build-date /app/git/
|
|
|
|
|
2022-10-28 22:16:23 +02:00
|
|
|
EXPOSE 8000
|
|
|
|
|
|
|
|
WORKDIR /app/src
|
|
|
|
|
2022-11-10 17:42:05 +01:00
|
|
|
HEALTHCHECK --start-period=30s CMD python -c "import requests; requests.get('http://localhost:8000', timeout=2)"
|
|
|
|
|
2022-10-28 22:16:23 +02:00
|
|
|
USER django
|
2022-11-10 18:27:45 +01:00
|
|
|
CMD ["gunicorn", "charasheet.wsgi", "--graceful-timeout=5", "--worker-tmp-dir=/dev/shm", "--workers=2", "--threads=4", "--worker-class=gthread", "--bind=0.0.0.0:8000", "--log-file=-"]
|