67 lines
2.0 KiB
Docker
67 lines
2.0 KiB
Docker
# =============================================================================
|
|
# 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
|
|
WORKDIR /shared
|
|
COPY shared/ /shared/
|
|
|
|
# Stage 2: Main service
|
|
ARG BASE_REGISTRY=docker.io
|
|
ARG PYTHON_IMAGE=python:3.11-slim
|
|
FROM ${BASE_REGISTRY}/${PYTHON_IMAGE}
|
|
|
|
# Create non-root user for security
|
|
RUN groupadd -r appgroup && useradd -r -g appgroup appuser
|
|
|
|
WORKDIR /app
|
|
|
|
# Install system dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
gcc \
|
|
curl \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy requirements
|
|
COPY gateway/requirements.txt .
|
|
|
|
# Install Python dependencies
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
# Copy shared libraries from the shared stage
|
|
COPY --from=shared /shared /app/shared
|
|
|
|
# Copy application code
|
|
COPY gateway/ .
|
|
|
|
# Change ownership to non-root user
|
|
RUN chown -R appuser:appgroup /app
|
|
|
|
# Add shared libraries to Python path
|
|
ENV PYTHONPATH="/app:/app/shared:${PYTHONPATH:-}"
|
|
|
|
# Switch to non-root user
|
|
USER appuser
|
|
|
|
# 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"] |