# Production: no Caddy here — TLS via /opt/sinsay Caddyfile (sinsaybuy.com stack).
services:
  app:
    container_name: morele-app
    build:
      context: .
      dockerfile: Dockerfile
    restart: unless-stopped
    env_file: .env
    environment:
      DATABASE_URL: postgresql://${POSTGRES_USER:-morele}:${POSTGRES_PASS:-morele_secret}@postgres:5432/${POSTGRES_DB:-moreledb}
      REDIS_URL: redis://redis:6379
      FLARESOLVERR_ENABLED: ${FLARESOLVERR_ENABLED:-true}
      FLARESOLVERR_URL: http://flaresolverr:8191
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
      flaresolverr:
        condition: service_started
    networks:
      - morele_proxy_net

  flaresolverr:
    image: ghcr.io/flaresolverr/flaresolverr:latest
    restart: unless-stopped
    environment:
      LOG_LEVEL: info
      CAPTCHA_SOLVER: none
    networks:
      - morele_proxy_net

  redis:
    image: redis:7-alpine
    restart: unless-stopped
    volumes:
      - morele_redis_data:/data
    command: redis-server --save 60 1 --appendonly yes --loglevel warning
    healthcheck:
      test: ['CMD', 'redis-cli', 'ping']
      interval: 5s
      timeout: 3s
      retries: 5
    networks:
      - morele_proxy_net

  postgres:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-morele}
      POSTGRES_PASSWORD: ${POSTGRES_PASS:-morele_secret}
      POSTGRES_DB: ${POSTGRES_DB:-moreledb}
    volumes:
      - morele_pg_data:/var/lib/postgresql/data
    healthcheck:
      test: ['CMD-SHELL', 'pg_isready -U ${POSTGRES_USER:-morele}']
      interval: 5s
      timeout: 3s
      retries: 10
    networks:
      - morele_proxy_net

volumes:
  morele_redis_data:
  morele_pg_data:

networks:
  morele_proxy_net:
    external: true
    name: sinsay_proxy_net
