-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
executable file
·66 lines (48 loc) · 1.89 KB
/
Dockerfile
File metadata and controls
executable file
·66 lines (48 loc) · 1.89 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
55
56
57
58
59
60
61
62
63
64
65
66
# ===== Stage 1: Assembler =====
FROM python:3.13-slim AS builder
# Base python runtime env + uv settings + venv in /opt/venv
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
UV_LINK_MODE=copy \
UV_PROJECT_ENVIRONMENT=/opt/venv \
PATH="/opt/venv/bin:$PATH"
WORKDIR /app
# Install uv binary (fast deps resolver/installer)
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Copy only dependency manifests first (better layer cache)
COPY pyproject.toml uv.lock ./
# Create venv + install prod deps (locked, without dev)
RUN uv venv /opt/venv \
&& uv sync --frozen --no-dev --no-install-project
# Copy source code after deps to keep caching efficient
COPY . .
# Install your package into the venv (so `python -m app.main` works)
RUN uv sync --frozen --no-dev
# ===== Stage 2: Final =====
FROM python:3.13-slim AS final
# Runtime python env; use the prebuilt venv binaries
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
PATH="/opt/venv/bin:$PATH"
# Runtime-only deps (keep image slim)
RUN apt-get update && apt-get install --no-install-recommends -y \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create unprivileged user (fixed UID/GID for k8s-friendly perms)
RUN groupadd -g 10000 shrimp && \
useradd -m -u 10000 -g shrimp shrimp
WORKDIR /app
# Bring in venv + app from builder stage
COPY --from=builder /opt/venv /opt/venv
COPY --from=builder /app /app
# Fix ownership so non-root user can read/run everything
RUN chown -R shrimp:shrimp /app /opt/venv
USER shrimp
# Optional app port (e.g., streamlit default)
# EXPOSE 8501
# Optional healthcheck (uncomment if you want container-level health)
# HEALTHCHECK --interval=30s --timeout=10s --start-period=20s --retries=3 \
# CMD curl --fail http://localhost:8501/_stcore/health || exit 1
# Run module as entrypoint; CMD left empty for optional args override
ENTRYPOINT ["python", "-m", "app.main"]
CMD [""]