-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
55 lines (40 loc) · 1.57 KB
/
Dockerfile
File metadata and controls
55 lines (40 loc) · 1.57 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
# =============================================================================
# Stage 1: Builder
# =============================================================================
FROM python:3.11-slim AS builder
# Copy uv from official image
COPY --from=ghcr.io/astral-sh/uv:0.8.21 /uv /uvx /bin/
# Set working directory
WORKDIR /app
# Configure uv for optimal Docker builds
ENV UV_COMPILE_BYTECODE=1 \
UV_LINK_MODE=copy
# Copy dependency files
COPY pyproject.toml uv.lock ./
# Install dependencies with cache mount for faster rebuilds
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --locked --no-dev --no-install-project
# =============================================================================
# Stage 2: Runtime
# =============================================================================
FROM python:3.11-slim
# Create non-root user and group
RUN groupadd --system --gid 1001 appgroup && \
useradd --system --uid 1001 --gid appgroup --create-home appuser
# Set working directory
WORKDIR /app
# Copy virtual environment from builder
COPY --from=builder --chown=appuser:appgroup /app/.venv /app/.venv
# Copy application code
COPY --chown=appuser:appgroup ./app ./app
# Create data directory with proper ownership
RUN mkdir -p /app/data && chown appuser:appgroup /app/data
# Add .venv to PATH
ENV PATH="/app/.venv/bin:$PATH"
# Switch to non-root user
USER appuser
# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=10s --retries=3 \
CMD python -c "import sys; sys.exit(0)" || exit 1
# Run the application
CMD ["python", "-m", "app.main"]