Files
bakery-ia/gateway/Dockerfile

67 lines
2.0 KiB
Docker
Raw Normal View History

2026-01-19 16:31:11 +01:00
# =============================================================================
# Gateway Dockerfile - Environment-Configurable Base Images
# =============================================================================
# Build arguments for registry configuration:
# - BASE_REGISTRY: Registry URL (default: docker.io for Docker Hub)
# - PYTHON_IMAGE: Python image name and tag (default: python:3.11-slim)
#
# Usage:
# Dev: docker build --build-arg BASE_REGISTRY=localhost:5000 --build-arg PYTHON_IMAGE=python_3.11-slim .
# Prod: docker build --build-arg BASE_REGISTRY=ghcr.io/your-org --build-arg PYTHON_IMAGE=python:3.11-slim .
# =============================================================================
# Build arguments - can be overridden at build time
ARG BASE_REGISTRY=docker.io
ARG PYTHON_IMAGE=python:3.11-slim
# Stage 1: Copy shared libraries
FROM ${BASE_REGISTRY}/${PYTHON_IMAGE} AS shared
2025-07-17 15:55:23 +02:00
WORKDIR /shared
COPY shared/ /shared/
2026-01-19 16:31:11 +01:00
# Stage 2: Main service
ARG BASE_REGISTRY=docker.io
ARG PYTHON_IMAGE=python:3.11-slim
FROM ${BASE_REGISTRY}/${PYTHON_IMAGE}
2025-07-17 13:54:51 +02:00
# Create non-root user for security
RUN groupadd -r appgroup && useradd -r -g appgroup appuser
2025-07-17 13:54:51 +02:00
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
curl \
&& rm -rf /var/lib/apt/lists/*
# Copy requirements
2025-07-17 15:55:23 +02:00
COPY gateway/requirements.txt .
2025-07-17 13:54:51 +02:00
# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt
2025-07-17 15:55:23 +02:00
# Copy shared libraries from the shared stage
COPY --from=shared /shared /app/shared
2025-07-17 13:54:51 +02:00
# Copy application code
2025-07-17 15:55:23 +02:00
COPY gateway/ .
2025-07-17 13:54:51 +02:00
# Change ownership to non-root user
RUN chown -R appuser:appgroup /app
2025-07-17 13:54:51 +02:00
# Add shared libraries to Python path
ENV PYTHONPATH="/app:/app/shared:${PYTHONPATH:-}"
2025-07-17 13:54:51 +02:00
# Switch to non-root user
USER appuser
2025-07-17 13:54:51 +02:00
# Expose port
EXPOSE 8000
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD curl -f http://localhost:8000/health || exit 1
# Run application
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]