-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile.api
More file actions
74 lines (56 loc) · 2.01 KB
/
Dockerfile.api
File metadata and controls
74 lines (56 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
72
73
74
# CI/CD build — used by .github/workflows/docker-publish.yml
# Janua API - Multi-stage Dockerfile for FastAPI
# Build stage
FROM python:3.11-slim AS builder
WORKDIR /app
# Install build dependencies (including xmlsec/lxml requirements)
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
curl \
pkg-config \
libxml2-dev \
libxmlsec1-dev \
libxmlsec1-openssl \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements file
COPY apps/api/requirements.txt ./
# Install dependencies
RUN pip install --no-cache-dir -r requirements.txt
# Production stage
FROM python:3.11-slim AS runner
WORKDIR /app
# Install runtime dependencies for xmlsec
RUN apt-get update && apt-get install -y --no-install-recommends \
libxml2 \
libxmlsec1 \
libxmlsec1-openssl \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create non-root user
RUN groupadd --system --gid 1001 python && \
useradd --system --uid 1001 --gid python janua
# Copy installed packages 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 application code
COPY apps/api/app ./app
# Copy alembic for database migrations
COPY apps/api/alembic ./alembic
COPY apps/api/alembic.ini ./alembic.ini
# Copy entrypoint script
COPY apps/api/docker-entrypoint.sh ./docker-entrypoint.sh
# Set ownership
RUN chown -R janua:python /app
USER janua
# Default to MADFAM ecosystem standard port 4100
ENV PORT=4100
ENV PYTHONUNBUFFERED=1
ENV ENVIRONMENT=production
EXPOSE 4100
# Health check - uses PORT environment variable
HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \
CMD curl -f http://localhost:${PORT:-4100}/health || exit 1
# Use entrypoint script that runs migrations before starting
ENTRYPOINT ["./docker-entrypoint.sh"]
# Use shell form to read PORT environment variable (set via K8s or docker-compose)
CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-4100}"]