69 lines
1.5 KiB
Docker
Executable File
69 lines
1.5 KiB
Docker
Executable File
# Production Dockerfile for Customer Portal
|
|
# Multi-stage build for smaller image size
|
|
|
|
# Stage 1: Build dependencies
|
|
FROM python:3.12-slim AS builder
|
|
|
|
WORKDIR /app
|
|
|
|
# Install build dependencies
|
|
RUN apt-get update && apt-get install -y \
|
|
libpq-dev \
|
|
gcc \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Create virtual environment
|
|
RUN python -m venv /opt/venv
|
|
ENV PATH="/opt/venv/bin:$PATH"
|
|
|
|
# Install Python dependencies
|
|
COPY requirements.txt .
|
|
RUN pip install --no-cache-dir -r requirements.txt
|
|
|
|
|
|
# Stage 2: Production image
|
|
FROM python:3.12-slim
|
|
|
|
WORKDIR /app
|
|
|
|
# Install runtime dependencies only
|
|
RUN apt-get update && apt-get install -y \
|
|
libpq5 \
|
|
curl \
|
|
postgresql-client \
|
|
&& rm -rf /var/lib/apt/lists/*
|
|
|
|
# Copy virtual environment from builder
|
|
COPY --from=builder /opt/venv /opt/venv
|
|
ENV PATH="/opt/venv/bin:$PATH"
|
|
|
|
# Copy application code (includes migrations in customer_portal/migrations/)
|
|
COPY customer_portal/ customer_portal/
|
|
|
|
# Copy and prepare entrypoint
|
|
COPY entrypoint.sh /app/entrypoint.sh
|
|
|
|
# Create non-root user and set permissions
|
|
RUN useradd -m -r portal && \
|
|
chown -R portal:portal /app && \
|
|
chmod +x /app/entrypoint.sh
|
|
|
|
USER portal
|
|
|
|
# Environment
|
|
ENV PYTHONUNBUFFERED=1
|
|
ENV PYTHONDONTWRITEBYTECODE=1
|
|
ENV FLASK_ENV=production
|
|
|
|
EXPOSE 8000
|
|
|
|
# Health check
|
|
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
|
|
CMD curl -f http://localhost:8000/health || exit 1
|
|
|
|
# Entrypoint handles:
|
|
# 1. Wait for PostgreSQL
|
|
# 2. Run flask db upgrade
|
|
# 3. Start Gunicorn
|
|
ENTRYPOINT ["/app/entrypoint.sh"]
|