checkout/Dockerfile

67 lines
1.9 KiB
Text
Raw Normal View History

2023-03-25 20:18:13 +01:00
##############################################
# write git info
##############################################
FROM alpine/git:2.40.1 AS git
2022-04-24 15:51:25 +02:00
WORKDIR /app
2023-03-25 20:18:13 +01:00
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
2022-04-24 15:51:25 +02:00
2023-03-25 20:18:13 +01:00
##############################################
# Main image
##############################################
FROM python:3.11.5-slim-bullseye AS final
2022-04-24 15:51:25 +02:00
2023-03-25 20:18:13 +01:00
ARG DEBIAN_FRONTEND=noninteractive
ARG PIP_DISABLE_PIP_VERSION_CHECK=1
2022-04-24 15:51:25 +02:00
2023-03-25 20:18:13 +01:00
# Setup user & group
##############################################
RUN groupadd -g 1000 django
RUN useradd -M -d /app -u 1000 -g 1000 -s /bin/bash django
2022-04-24 15:51:25 +02:00
2023-03-25 20:18:13 +01:00
# Setup system
##############################################
RUN apt-get update -y \
&& apt-get install -y --no-install-recommends \
libxml2 \
2023-03-25 20:34:35 +01:00
media-types \
gettext
2022-04-24 15:51:25 +02:00
2023-03-25 20:18:13 +01:00
# Fetch project requirements
##############################################
COPY --chown=django:django --from=git /git-describe /git-commit /build-date /app/git/
2022-04-24 15:51:25 +02:00
2023-03-25 20:18:13 +01:00
# Create directory structure
##############################################
2022-04-24 15:51:25 +02:00
WORKDIR /app
2023-03-25 20:18:13 +01:00
COPY --chown=django:django pyproject.toml requirements.txt ./
ADD --chown=django:django ./src ./src
COPY --chown=django:django tasks.py ./tasks.py
RUN mkdir -p /app/data /app/db
RUN chown django:django /app /app/data /app/db
2022-04-24 15:51:25 +02:00
2023-03-25 20:18:13 +01:00
ENV STATIC_ROOT=/app/static
2022-04-24 15:51:25 +02:00
ENV SECRET_KEY "changeme"
ENV DEBUG "false"
ENV DB_BASE_DIR "/app/db"
2023-03-25 20:18:13 +01:00
RUN python -m pip install --no-cache-dir -r requirements.txt
WORKDIR /app/src
RUN python manage.py collectstatic --noinput --clear
2023-03-25 20:44:02 +01:00
RUN python manage.py compilemessages -l fr -l en
2023-03-25 20:18:13 +01:00
EXPOSE 8000
2022-04-24 15:51:25 +02:00
WORKDIR /app/src
2023-03-25 20:18:13 +01:00
HEALTHCHECK --start-period=30s CMD python -c "import requests; requests.get('http://localhost:8000', timeout=2)"
USER django
CMD ["gunicorn", "checkout.wsgi", "--graceful-timeout=5", "--worker-tmp-dir=/dev/shm", "--workers=2", "--threads=4", "--worker-class=gthread", "--bind=0.0.0.0:8000", "--log-file=-"]