-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.python
More file actions
71 lines (52 loc) · 2.01 KB
/
Dockerfile.python
File metadata and controls
71 lines (52 loc) · 2.01 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
67
68
69
70
71
# =============================================================================
# UDC Enterprise Platform — Python Services Multi-Stage Dockerfile
# =============================================================================
# Usage: docker build -f Dockerfile.python --build-arg SERVICE=udc_metacatalog .
# =============================================================================
FROM python:3.11-slim AS base
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
build-essential \
libpq-dev \
&& rm -rf /var/lib/apt/lists/*
# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Set working directory
WORKDIR /app
# --- Builder stage ---
FROM base AS builder
ARG SERVICE
# Copy the specific service and shared config
COPY src/${SERVICE}/pyproject.toml ./pyproject.toml
RUN uv pip install --system --no-cache -r pyproject.toml || true
# Copy source code
COPY src/${SERVICE}/ ./
COPY shared/ /app/shared/
# --- Runtime stage ---
FROM python:3.11-slim AS runtime
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
libpq5 \
&& rm -rf /var/lib/apt/lists/*
# Install uv for runtime
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Create non-root user
RUN groupadd -r udc && useradd -r -g udc -d /app -s /sbin/nologin udc
WORKDIR /app
# Copy installed packages and source from builder
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
COPY --from=builder /app /app
# Set ownership
RUN chown -R udc:udc /app
USER udc
# Default environment
ENV PYTHONUNBUFFERED=1 \
PYTHONDONTWRITEBYTECODE=1 \
LOG_LEVEL=INFO
# Health check
HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
CMD curl -f http://localhost:${PORT:-8000}/health || exit 1
# Default command (override per service in docker-compose)
CMD ["uvicorn", "api.app:app", "--host", "0.0.0.0", "--port", "8000"]