-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
63 lines (45 loc) · 1.65 KB
/
Dockerfile
File metadata and controls
63 lines (45 loc) · 1.65 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
# ============================================
# Stage 1: Builder
# Install dependencies in isolated environment
# ============================================
FROM python:3.14-slim AS builder
# Install uv package manager
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
WORKDIR /app
# Copy dependency files first (for better layer caching)
COPY pyproject.toml uv.lock ./
# Install dependencies into virtual environment
RUN uv sync --frozen --no-install-project --no-dev
# Copy source code
COPY src ./src
# Install the project itself
RUN uv sync --frozen --no-dev
# ============================================
# Stage 2: Runtime
# Minimal image for running the application
# ============================================
FROM python:3.14-slim AS runtime
WORKDIR /app
# Create non-root user for security
RUN groupadd --gid 1000 appgroup && \
useradd --uid 1000 --gid appgroup --shell /bin/bash --create-home appuser
# Copy virtual environment from builder
COPY --from=builder /app/.venv /app/.venv
# Copy source code
COPY --from=builder /app/src /app/src
# Set environment variables
ENV PATH="/app/.venv/bin:$PATH" \
PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
PORT=8000
# Change ownership to non-root user
RUN chown -R appuser:appgroup /app
# Switch to non-root user
USER appuser
# Expose port
EXPOSE 8000
# Health check - calls /api/health endpoint
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:${PORT}/api/health')" || exit 1
# Run the application
CMD ["fastapi", "run", "src/kasir_api/app.py", "--host", "0.0.0.0", "--port", "8000"]