2022-01-26 12:20:38 +01:00
|
|
|
##############################################
|
|
|
|
# Build virtualenv
|
|
|
|
##############################################
|
2022-03-25 19:33:15 +01:00
|
|
|
FROM python:3.10.4-bullseye AS venv
|
2021-05-29 16:22:13 +02:00
|
|
|
|
2022-01-26 12:20:38 +01:00
|
|
|
# Prepare system
|
|
|
|
##############################################
|
2021-05-29 16:22:13 +02:00
|
|
|
# https://python-poetry.org/docs/#installation
|
2022-03-25 19:33:15 +01:00
|
|
|
ENV POETRY_VERSION=1.1.13
|
|
|
|
RUN curl -sSL https://install.python-poetry.org | python3 -
|
2021-05-29 16:22:13 +02:00
|
|
|
|
2022-01-26 12:07:03 +01:00
|
|
|
ENV PATH /root/.local/bin:$PATH
|
2021-05-29 16:22:13 +02:00
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
|
2022-01-26 12:20:38 +01:00
|
|
|
# Install python dependencies
|
|
|
|
##############################################
|
2021-05-29 16:22:13 +02:00
|
|
|
COPY pyproject.toml poetry.lock ./
|
|
|
|
|
|
|
|
RUN python -m venv --copies /app/venv \
|
|
|
|
&& . /app/venv/bin/activate \
|
|
|
|
&& poetry install --no-dev
|
|
|
|
|
2022-01-26 12:20:38 +01:00
|
|
|
# Collect static files & build assets
|
|
|
|
##############################################
|
|
|
|
ENV PATH /app/venv/bin:$PATH
|
|
|
|
WORKDIR /app/src
|
|
|
|
COPY ./src ./
|
|
|
|
|
|
|
|
# Build assets so that we don't need the build tools later
|
|
|
|
RUN python manage.py collectstatic --noinput --clear
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
##############################################
|
|
|
|
# write git info
|
|
|
|
##############################################
|
2021-05-29 16:22:13 +02:00
|
|
|
|
|
|
|
## Get git versions
|
|
|
|
FROM alpine/git:v2.30.2 AS git
|
|
|
|
ADD . /app
|
|
|
|
WORKDIR /app
|
|
|
|
RUN git rev-parse HEAD | tee /version
|
|
|
|
|
|
|
|
|
2022-01-26 12:20:38 +01:00
|
|
|
|
|
|
|
##############################################
|
|
|
|
# Main image
|
|
|
|
##############################################
|
2022-03-25 19:33:15 +01:00
|
|
|
FROM python:3.10.4-slim-bullseye as prod
|
2021-05-29 16:22:13 +02:00
|
|
|
|
2022-03-25 19:33:15 +01:00
|
|
|
ENV TZ "Europe/Paris"
|
2021-05-29 16:22:13 +02:00
|
|
|
|
|
|
|
COPY --from=venv /app/venv /app/venv/
|
|
|
|
ENV PATH /app/venv/bin:$PATH
|
|
|
|
ENV PYTHONPATH $PYTHONPATH:/app
|
|
|
|
|
|
|
|
WORKDIR /app
|
|
|
|
COPY pyproject.toml ./
|
2021-06-07 16:30:11 +02:00
|
|
|
COPY contrib/run ./run
|
|
|
|
COPY src ./src/
|
2021-05-29 16:22:13 +02:00
|
|
|
COPY --from=git /version /app/.version
|
2022-01-26 12:20:38 +01:00
|
|
|
ARG STATIC_ROOT=/app/src/staticfiles
|
|
|
|
COPY --chown=django:django --from=venv $STATIC_ROOT $STATIC_ROOT
|
2021-05-29 16:22:13 +02:00
|
|
|
|
2021-06-07 16:30:11 +02:00
|
|
|
HEALTHCHECK --start-period=30s CMD python -c "import requests; requests.get('http://localhost:8000', timeout=2)"
|
|
|
|
|
|
|
|
WORKDIR /app/src
|
|
|
|
CMD ["/app/run"]
|