|
| 1 | +# The default base image |
| 2 | +ARG from_image=python:3.12.9-slim |
| 3 | +ARG image_tag=0.0.0 |
| 4 | +FROM ${from_image} AS python-base |
| 5 | + |
| 6 | +# Labels |
| 7 | +LABEL maintainer='Alan Christie <achristie@informaticsmatters.com>' |
| 8 | + |
| 9 | +# Force the binary layer of the stdout and stderr streams |
| 10 | +# to be unbuffered |
| 11 | +ENV PYTHONUNBUFFERED 1 |
| 12 | + |
| 13 | +# Base directory for the application |
| 14 | +# Also used for user directory |
| 15 | +ENV APP_ROOT /home/es |
| 16 | + |
| 17 | +WORKDIR ${APP_ROOT} |
| 18 | + |
| 19 | +################################################################## |
| 20 | +# |
| 21 | +# Second stage, poetry installation. |
| 22 | +# |
| 23 | +################################################################## |
| 24 | +FROM python-base AS poetry-base |
| 25 | +ARG image_tag |
| 26 | +ARG POETRY_VERSION=1.8.5 |
| 27 | + |
| 28 | +RUN pip install --no-cache-dir poetry==${POETRY_VERSION} |
| 29 | + |
| 30 | +WORKDIR / |
| 31 | +COPY poetry.lock pyproject.toml / |
| 32 | + |
| 33 | +# Despite letting poetry create virtualenv here, we're not using it in |
| 34 | +# the final container, we just let poetry install the packages and |
| 35 | +# copy them later. POETRY_VIRTUALENVS_IN_PROJECT flag tells poetry to |
| 36 | +# create the venv to project's directory (.venv). This way the |
| 37 | +# location is predictable |
| 38 | +RUN POETRY_VIRTUALENVS_IN_PROJECT=true poetry install --no-root --only main --no-directory |
| 39 | + |
| 40 | +################################################################## |
| 41 | +# |
| 42 | +# Final stage. |
| 43 | +# Only copy the venv with installed packages and point paths to it |
| 44 | +# |
| 45 | +################################################################## |
| 46 | +FROM python-base AS final |
| 47 | +ARG image_tag |
| 48 | + |
| 49 | +COPY --from=poetry-base /.venv /.venv |
| 50 | + |
| 51 | +ENV PYTHONPATH="${PYTHONPATH}:/.venv/lib/python3.13/site-packages/" |
| 52 | +ENV PATH=/.venv/bin:$PATH |
| 53 | +ENV IMAGE_TAG=${image_tag} |
| 54 | + |
| 55 | +COPY app/ ./app/ |
| 56 | +COPY docker-entrypoint.sh . |
| 57 | + |
| 58 | +# Probes... |
| 59 | +COPY probes/*.sh . |
| 60 | +# Kubernetes lifecycle hooks... |
| 61 | +COPY hooks/*.sh . |
| 62 | + |
| 63 | +# Create a base directory for file-based logging |
| 64 | +WORKDIR /log |
| 65 | + |
| 66 | +# Switch to container user |
| 67 | +ENV HOME ${APP_ROOT} |
| 68 | +WORKDIR ${APP_ROOT} |
| 69 | +USER root |
| 70 | + |
| 71 | +# Start the application |
| 72 | +CMD ./docker-entrypoint.sh |
0 commit comments