# Docker Compose for {{ project_name }} - Linux Server Deployment
# Infrastructure stack: Traefik + PostgreSQL
#
# Usage:
#   docker compose up -d traefik db   # Start infrastructure
#   docker compose logs -f            # Follow logs
#   docker compose down               # Stop all services
#
# Note: App containers are managed by deploy.sh (blue-green deployment),
#       not by this compose file.

{% raw %}
services:
  traefik:
    image: traefik:latest
    restart: unless-stopped
    command:
      - "--providers.docker=true"
      - "--providers.docker.exposedbydefault=false"
      - "--providers.docker.network=traefik-public"
      - "--providers.file.directory=/etc/traefik/dynamic"
      - "--entrypoints.web.address=:80"
      - "--entrypoints.websecure.address=:443"
      - "--api.dashboard=false"
      - "--log.level=INFO"
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - ./certs:/etc/traefik/certs:ro
      - ./traefik-dynamic.yml:/etc/traefik/dynamic/traefik-dynamic.yml:ro
    networks:
      - traefik-public

  db:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres}
      - POSTGRES_DB={% endraw %}{{ project_name | replace("-", "_") }}{% raw %}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 3s
      retries: 5
    networks:
      - backend

networks:
  traefik-public:
    external: true
  backend:
    external: true

volumes:
  postgres_data:
{% endraw %}
