-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
68 lines (49 loc) · 1.77 KB
/
Dockerfile
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
67
68
# ------------------------------- Builder Satge -------------------------------
# Build stage (with dev tools for linting, testing, etc.)
FROM python:3.12-slim-bookworm AS builder
# The installer requires curl (and certificates) to download the release archive
RUN apt-get update && apt-get install -y --no-install-recommends curl ca-certificates && \
apt-get clean && rm -rf /var/lib/apt/lists/*
# Download the latest installer, install it, and remove it
ADD https://astral.sh/uv/install.sh /uv-installer.sh
RUN chmod -R 655 /uv-installer.sh && /uv-installer.sh && rm /uv-installer.sh
# Set up uv environment PATH
ENV PATH="/root/.local/bin/:$PATH"
WORKDIR /app
# Prevent Python from writing pyc files and buffering output
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
# Copy dependency files first for caching
COPY pyproject.toml /app/
# Sync dependencies (includes streamlit, ruff, pytest if in pyproject.toml)
RUN uv sync
# Copy the rest of the project
COPY . /app
# ------------------------- Production Stage -------------------------
# Final stage (production, lean image)
FROM python:3.12-slim-bookworm AS production
WORKDIR /app
# Prevent Python from writing pyc files and buffering output
ENV PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1
# Create a non-privileged user
ARG UID=10001
RUN adduser \
--disabled-password \
--gecos "" \
--home "/nonexistent" \
--shell "/sbin/nologin" \
--no-create-home \
--uid "${UID}" \
appuser
# Copy the virtual env and project files
COPY --from=builder /app/.venv /app/.venv
COPY . /app
# Set PATH to use the virtual env
ENV PATH="/app/.venv/bin:$PATH"
# Switch to non-privileged user
USER appuser
# Expose Streamlit's default port
EXPOSE 8501
# Run Streamlit app
CMD ["streamlit", "run", "src/app.py"]