2023-04-04 13:47:19 +00:00
|
|
|
# This is a Dockerfile for running unit tests
|
|
|
|
|
2023-04-01 16:00:09 +00:00
|
|
|
# Use the Python base image
|
|
|
|
FROM python:3.11.2-bullseye AS builder
|
|
|
|
|
2023-04-04 13:47:19 +00:00
|
|
|
# Define the version of Poetry to install (default is 1.4.2)
|
|
|
|
ARG POETRY_VERSION=1.4.2
|
2023-04-01 16:00:09 +00:00
|
|
|
|
2023-04-04 13:47:19 +00:00
|
|
|
# Define the directory to install Poetry to (default is /opt/poetry)
|
|
|
|
ARG POETRY_HOME=/opt/poetry
|
2023-04-01 16:00:09 +00:00
|
|
|
|
2023-04-04 13:47:19 +00:00
|
|
|
# Create a Python virtual environment for Poetry and install it
|
|
|
|
RUN python3 -m venv ${POETRY_HOME} && \
|
|
|
|
$POETRY_HOME/bin/pip install --upgrade pip && \
|
|
|
|
$POETRY_HOME/bin/pip install poetry==${POETRY_VERSION}
|
2023-04-01 16:00:09 +00:00
|
|
|
|
2023-04-04 13:47:19 +00:00
|
|
|
# Test if Poetry is installed in the expected path
|
|
|
|
RUN echo "Poetry version:" && $POETRY_HOME/bin/poetry --version
|
2023-04-01 16:00:09 +00:00
|
|
|
|
2023-04-04 13:47:19 +00:00
|
|
|
# Set the working directory for the app
|
2023-04-01 16:00:09 +00:00
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# Use a multi-stage build to install dependencies
|
|
|
|
FROM builder AS dependencies
|
|
|
|
|
|
|
|
# Copy only the dependency files for installation
|
|
|
|
COPY pyproject.toml poetry.lock poetry.toml ./
|
|
|
|
|
2023-04-04 13:47:19 +00:00
|
|
|
# Install the Poetry dependencies (this layer will be cached as long as the dependencies don't change)
|
2023-04-07 14:28:57 +00:00
|
|
|
RUN $POETRY_HOME/bin/poetry install --no-interaction --no-ansi --with test
|
2023-04-01 16:00:09 +00:00
|
|
|
|
|
|
|
# Use a multi-stage build to run tests
|
|
|
|
FROM dependencies AS tests
|
|
|
|
|
|
|
|
# Copy the rest of the app source code (this layer will be invalidated and rebuilt whenever the source code changes)
|
|
|
|
COPY . .
|
|
|
|
|
2023-04-07 14:28:57 +00:00
|
|
|
RUN /opt/poetry/bin/poetry install --no-interaction --no-ansi --with test
|
2023-04-04 13:47:19 +00:00
|
|
|
|
|
|
|
# Set the entrypoint to run tests using Poetry
|
|
|
|
ENTRYPOINT ["/opt/poetry/bin/poetry", "run", "pytest"]
|
2023-04-01 16:00:09 +00:00
|
|
|
|
2023-04-04 13:47:19 +00:00
|
|
|
# Set the default command to run all unit tests
|
2023-04-01 16:00:09 +00:00
|
|
|
CMD ["tests/unit_tests"]
|