-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile_multi_layer
More file actions
45 lines (33 loc) · 1.45 KB
/
Copy pathDockerfile_multi_layer
File metadata and controls
45 lines (33 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# -----------------------------------------------------------------
# Stage 1: Build Dependencies
# -----------------------------------------------------------------
FROM ghcr.io/astral-sh/uv:latest AS uv-builder
# Set working directory for the build process
WORKDIR /app
# Enable bytecode compilation and unbuffered output for Python
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
# Install project dependencies first (this layer caches aggressively)
COPY pyproject.toml uv.lock ./
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --no-dev --no-install-project --locked
# Copy the rest of the source code and install the project itself
COPY . /app
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --no-dev --locked
# -----------------------------------------------------------------
# Stage 2: Final Runtime Image
# -----------------------------------------------------------------
FROM python:3.12-slim-bookworm
# Create a non-root user for security
RUN useradd -m --uid 1000 appuser
USER appuser
WORKDIR /app
# Copy the virtual environment and installed applications from the builder stage
COPY --from=uv-builder --chown=appuser:appuser /app/.venv /app/.venv
# Ensure the virtual environment's executables are on the PATH
ENV PATH="/app/.venv/bin:$PATH"
# Copy the application source code
COPY --chown=appuser:appuser . /app
# Command to run your application
CMD ["uv", "run", "your_entrypoint_here"]