Skip to content

Commit

Permalink
Add Dockerfile that was changed by mistake
Browse files Browse the repository at this point in the history
  • Loading branch information
stvoutsin committed Oct 17, 2024
1 parent a26e708 commit 8ce125b
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
# This Dockerfile has four stages:
# This Dockerfile has three stages:
#
# base-image
# Updates the base Python image with security patches and common system
# packages. This image becomes the base of all other images.
# dependencies-image
# Installs third-party dependencies (requirements/main.txt) into a virtual
# environment. This virtual environment is ideal for copying across build
# stages.
# install-image
# Installs the app into the virtual environment.
# Installs third-party dependencies (requirements/main.txt) and the
# application into a virtual environment. This virtual environment is
# ideal for copying across build stages.
# runtime-image
# - Copies the virtual environment into place.
# - Runs a non-root user.
# - Sets up the entrypoint and port.

FROM python:3.12.7-slim-bookworm as base-image
FROM python:3.12.7-slim-bookworm AS base-image

# Update system packages
COPY scripts/install-base-packages.sh .
RUN ./install-base-packages.sh && rm ./install-base-packages.sh

FROM base-image AS dependencies-image
FROM base-image AS install-image

# Install uv.
COPY --from=ghcr.io/astral-sh/uv:0.4.9 /uv /bin/uv

# Install system packages only needed for building dependencies.
COPY scripts/install-dependency-packages.sh .
Expand All @@ -29,23 +30,19 @@ RUN ./install-dependency-packages.sh
# Create a Python virtual environment
ENV VIRTUAL_ENV=/opt/venv
RUN python -m venv $VIRTUAL_ENV

# Make sure we use the virtualenv
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
# Put the latest pip and setuptools in the virtualenv
RUN pip install --upgrade --no-cache-dir pip setuptools wheel

# Install the app's Python runtime dependencies
COPY requirements/main.txt ./requirements.txt
RUN pip install --quiet --no-cache-dir -r requirements.txt

FROM dependencies-image AS install-image

# Use the virtualenv
ENV PATH="/opt/venv/bin:$PATH"
RUN uv pip install --compile-bytecode --verify-hashes --no-cache \
-r requirements.txt

# Install the application.
COPY . /workdir
WORKDIR /workdir
RUN pip install --no-cache-dir .
RUN uv pip install --compile-bytecode --no-cache .

FROM base-image AS runtime-image

Expand All @@ -55,6 +52,8 @@ RUN useradd --create-home appuser
# Copy the virtualenv
COPY --from=install-image /opt/venv /opt/venv

WORKDIR /app

# Make sure we use the virtualenv
ENV PATH="/opt/venv/bin:$PATH"

Expand Down

0 comments on commit 8ce125b

Please sign in to comment.