-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
46 lines (33 loc) · 921 Bytes
/
Copy pathDockerfile
File metadata and controls
46 lines (33 loc) · 921 Bytes
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
# -----------------------
# Stage 1: Build
# -----------------------
FROM ghcr.io/astral-sh/uv:python3.14-alpine AS builder
# Set work directory
WORKDIR /app
# Create virtual environment
RUN uv venv
# Copy pyproject.toml and uv.lock
COPY pyproject.toml uv.lock .
# Install Python modules
RUN uv sync --no-cache --no-group dev
# -----------------------
# Stage 2: Runtime
# -----------------------
FROM python:3.14-alpine3.23 AS runner
# Set work directory
WORKDIR /app
# Copy venv from builder stage
COPY --from=builder /app/.venv /app/.venv
# Copy application code
COPY src .
# Create a non-root user
RUN addgroup -S demo && adduser -S demo -G demo
# Give the non-root user permission to run the script
RUN chown demo:demo /app/main.py && \
chmod u+rwx /app/main.py
# Ensure venv is used
ENV PATH="/app/.venv/bin:$PATH"
# Switch to non-root user
USER demo
# Run the program
CMD ["python", "main.py"]