Files
turf_saas/Dockerfile
DevOps Engineer dce1e9b744 feat(devops): CI/CD + Docker + Monitoring infrastructure
- Multi-stage Dockerfile (builder+runner, <500MB target)
- docker-compose.yml: app(x4) + postgres + redis + prometheus + grafana + nginx
- .env.example with all required secrets (never hardcoded)
- requirements.txt with all dependencies including prometheus-client, alembic
- GitHub Actions CI: lint (flake8+bandit+safety) + tests + Docker build/push
- GitHub Actions CD: staging deploy -> smoke tests -> production deploy + rollback
- Alembic migration setup + initial PostgreSQL schema (001_initial_schema)
- SQLite→PostgreSQL data migration script
- Prometheus metrics module (HTTP, ML, DB, business metrics)
- Prometheus alert rules (5xx >1%, latency >2s, disk >80%, ML accuracy)
- Grafana dashboard (overview: req/s, p95, ML accuracy, error rate)
- Nginx reverse proxy config (HTTPS/TLS, rate limiting, security headers)
- Structured JSON logging module
- Automated daily DB backup script (pg_dump + 30-day retention)

Branch: feature/devops-cicd

Co-Authored-By: Paperclip <noreply@paperclip.ing>
2026-04-25 17:32:02 +02:00

69 lines
2.1 KiB
Docker

# ============================================================
# Stage 1: Builder — install deps + compile Python bytecode
# ============================================================
FROM python:3.12-slim AS builder
WORKDIR /build
# System deps needed to compile psycopg2, xgboost, etc.
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
g++ \
libpq-dev \
libffi-dev \
libssl-dev \
&& rm -rf /var/lib/apt/lists/*
# Upgrade pip + install wheel for faster builds
RUN pip install --upgrade pip wheel
# Copy only requirements first (layer caching)
COPY requirements.txt .
# Install into a prefix we can copy cleanly
RUN pip install --prefix=/install --no-cache-dir -r requirements.txt
# ============================================================
# Stage 2: Runner — minimal production image
# ============================================================
FROM python:3.12-slim AS runner
LABEL maintainer="DevOps <devops@h3r7tech.ai>"
LABEL org.opencontainers.image.title="Turf SaaS"
LABEL org.opencontainers.image.description="H3R7Tech Turf Predictions SaaS"
# Runtime system deps only
RUN apt-get update && apt-get install -y --no-install-recommends \
libpq5 \
curl \
&& rm -rf /var/lib/apt/lists/*
# Create non-root app user
RUN groupadd -r appuser && useradd -r -g appuser appuser
WORKDIR /app
# Copy installed packages from builder
COPY --from=builder /install /usr/local
# Copy application source (exclude files via .dockerignore)
COPY . .
# Create directories for persistent data
RUN mkdir -p /app/data/db /app/data/models /app/logs \
&& chown -R appuser:appuser /app
# Switch to non-root user
USER appuser
# Expose all service ports
EXPOSE 8790 8791 8792 8793
# Health check — hits the combined API
HEALTHCHECK --interval=30s --timeout=10s --start-period=60s --retries=3 \
CMD curl -f http://localhost:8790/health || exit 1
# Default: run combined API via gunicorn
# Override CMD per service in docker-compose
CMD ["gunicorn", "--bind", "0.0.0.0:8790", "--workers", "2", "--timeout", "120", "combined_api:app"]