-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.stage
More file actions
54 lines (39 loc) · 1.49 KB
/
Copy pathDockerfile.stage
File metadata and controls
54 lines (39 loc) · 1.49 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
46
47
48
49
50
51
52
53
54
# ============================================================
# Stage 1 — Builder (uv only)
# ============================================================
FROM python:3.13-slim AS builder
WORKDIR /app
# System deps for building native wheels (pandas, numpy, etc.)
RUN apt-get update && apt-get install -y --no-install-recommends \
curl ca-certificates build-essential \
&& rm -rf /var/lib/apt/lists/*
# Install uv
RUN curl -LsSf https://astral.sh/uv/install.sh | sh
ENV PATH="/root/.local/bin:$PATH"
# Create venv
RUN uv venv /opt/venv
ENV PATH="/opt/venv/bin:$PATH"
WORKDIR /app
# Copy dependency file first (cache layer)
COPY requirements.txt .
# Install dependencies (ONLY ONCE)
RUN uv pip install --python /opt/venv/bin/python -r requirements.txt
# ============================================================
# Stage 2 — Runtime (distroless)
# ============================================================
FROM gcr.io/distroless/python3-debian12:nonroot
ARG BUILD_DATE="1970-01-01T00:00:00Z"
LABEL org.opencontainers.image.created="${BUILD_DATE}" \
org.opencontainers.image.title="python-uv-distroless"
WORKDIR /app
# Copy venv from builder
COPY --from=builder /opt/venv /opt/venv
# Copy app
COPY hello.py /app/hello.py
# Runtime environment
ENV PATH="/opt/venv/bin:$PATH" \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
USER nonroot:nonroot
# Use system python OR venv python (both OK, venv is safer for reproducibility)
ENTRYPOINT ["/opt/venv/bin/python", "-u", "/app/hello.py"]