49 lines
1.4 KiB
Django/Jinja
49 lines
1.4 KiB
Django/Jinja
FROM registry-redhat.docker.bin.sbb.ch/rhel9/python-{{ python_version.replace(".", "") }} AS base
|
|
|
|
ENV PYTHONFAULTHANDLER=1 \
|
|
PYTHONUNBUFFERED=1 \
|
|
PYTHONHASHSEED=random \
|
|
PIP_NO_CACHE_DIR=off \
|
|
PIP_DISABLE_PIP_VERSION_CHECK=on \
|
|
PIP_DEFAULT_TIMEOUT=100
|
|
|
|
# need to be root in order to install packages
|
|
USER 0
|
|
|
|
# install necessary system dependencies here using `RUN dnf install -y <mypackage> && dnf clean all`
|
|
# for installable packages, see: https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/9/html-single/package_manifest/index#doc-wrapper
|
|
|
|
FROM base AS builder
|
|
|
|
ENV POETRY_PATH="/opt/poetry" \
|
|
POETRY_VERSION="2.2.1" \
|
|
POETRY_VIRTUALENVS_IN_PROJECT=true
|
|
|
|
ENV PATH="$POETRY_PATH/bin:$PATH"
|
|
|
|
RUN python -m venv $POETRY_PATH && \
|
|
$POETRY_PATH/bin/pip install poetry==$POETRY_VERSION
|
|
|
|
WORKDIR /app
|
|
|
|
# Initialize environment with packages
|
|
COPY README.md pyproject.toml poetry.lock ./
|
|
RUN poetry env use {{ python_version }} && \
|
|
poetry install --without dev --no-interaction --no-ansi --no-root
|
|
|
|
# Add project source code
|
|
COPY src/ ./src/
|
|
RUN poetry build -f wheel
|
|
RUN poetry run pip install dist/*.whl
|
|
|
|
FROM base AS final
|
|
|
|
# switch back to a non-root user for executing
|
|
USER 1001
|
|
|
|
ENV PATH="/app/.venv/bin:$PATH"
|
|
COPY --from=builder /app/.venv /app/.venv
|
|
|
|
# Default command. Can be overridden using docker run <image> <command>
|
|
CMD ["entrypoint"]
|