Skip to content

Commit

Permalink
chore: removes some extra comments in the Containerfile and moves poe…
Browse files Browse the repository at this point in the history
…try envs

Some of the comments are explained by the code so removes to make this more
readable. The poetry environment variables should not be in the base because
poetry is not installed in the final image.

Signed-off-by: Jennifer Power <[email protected]>
  • Loading branch information
jpower432 committed Nov 29, 2023
1 parent f41cd32 commit 3bb6a87
Showing 1 changed file with 16 additions and 25 deletions.
41 changes: 16 additions & 25 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,18 @@
FROM registry.access.redhat.com/ubi8/ubi-minimal:latest as python-base

ENV PYTHONUNBUFFERED=1 \
# prevents python creating .pyc files
PYTHONDONTWRITEBYTECODE=1 \
\
# pip
PIP_DISABLE_PIP_VERSION_CHECK=on \
PIP_DEFAULT_TIMEOUT=100 \
\
# poetry
# https://python-poetry.org/docs/configuration/#using-environment-variables
POETRY_VERSION=1.5.1 \
# make poetry install to this location
POETRY_HOME="/opt/poetry" \
# make poetry create the virtual environment in the project's root
# it gets named `.venv`
POETRY_VIRTUALENVS_IN_PROJECT=true \
# do not ask any interactive question
POETRY_NO_INTERACTION=1 \
\
# paths
# this is where our requirements + virtual environment will live
# Paths for the virtual environment and working directory
PYSETUP_PATH="/trestle-bot" \
VENV_PATH="/trestle-bot/.venv"

LABEL maintainer="Red Hat Product Security" \
summary="Trestle Bot"


# prepend poetry and venv to path
ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH"
# Ensure we use the virtualenv
ENV PATH="$VENV_PATH/bin:$PATH"

RUN microdnf update -y \
&& microdnf install -y python3.9 git \
Expand All @@ -40,28 +23,36 @@ RUN microdnf update -y \

FROM python-base as dependencies

# install poetry - respects $POETRY_VERSION & $POETRY_HOME
ARG POETRY_VERSION=1.5.1

# https://python-poetry.org/docs/configuration/#using-environment-variables
ENV POETRY_HOME="/opt/poetry" \
POETRY_VIRTUALENVS_IN_PROJECT=true \
POETRY_NO_INTERACTION=1

ENV PATH="$POETRY_HOME/bin:$PATH"

# install poetry - respects $POETRY_HOME
RUN python3.9 -m pip install --no-cache-dir --upgrade pip \
&& pip install --no-cache-dir poetry=="$POETRY_VERSION"

# Cache runtime deps
WORKDIR "/build"
COPY . "/build"

# Install runtime deps and install the project in non-editable mode.
RUN python -m venv $VENV_PATH && \
RUN python3.9 -m venv $VENV_PATH && \
. $VENV_PATH/bin/activate && \
poetry install --without tests,dev --no-root && \
poetry build -f wheel -n && \
pip install --no-cache-dir --no-deps dist/*.whl && \
rm -rf dist *.egg-info

# final image

FROM python-base as final

COPY --from=dependencies $PYSETUP_PATH $PYSETUP_PATH

# Add wrappers for entrypoints that provide support the actions
# Add wrappers for entrypoints that provide support for the actions
COPY ./actions/autosync/auto-sync-entrypoint.sh /
COPY ./actions/rules-transform/rules-transform-entrypoint.sh /
COPY ./actions/create-cd/create-cd-entrypoint.sh /
Expand Down

0 comments on commit 3bb6a87

Please sign in to comment.