services:
  postgres:
    image: timescale/timescaledb:latest-pg16
    container_name: hexawetter-postgres
    restart: unless-stopped
    environment:
      POSTGRES_DB: hexawetter
      POSTGRES_USER: hexawetter
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-hexawetter}
    volumes:
      - postgres_data:/var/lib/postgresql/data
      - ./db/init.sql:/docker-entrypoint-initdb.d/01-init.sql:ro
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U hexawetter -d hexawetter"]
      interval: 10s
      timeout: 5s
      retries: 8

  redis:
    image: redis:7-alpine
    container_name: hexawetter-redis
    restart: unless-stopped
    command: ["redis-server", "--save", "60", "1", "--loglevel", "warning"]
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 8

  api:
    build:
      context: ./api
    container_name: hexawetter-api
    restart: unless-stopped
    env_file:
      - .env
    environment:
      DATABASE_URL: postgresql://hexawetter:${POSTGRES_PASSWORD:-hexawetter}@postgres:5432/hexawetter
      REDIS_URL: redis://redis:6379/0
    volumes:
      - ./data:/data
    ports:
      - "${API_PORT:-8081}:8080"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy

  frontend:
    image: nginx:1.27-alpine
    container_name: hexawetter-frontend
    restart: unless-stopped
    depends_on:
      - api
    volumes:
      - ./frontend:/usr/share/nginx/html:ro
      - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
    ports:
      - "${WEB_PORT:-8080}:80"

  radar-worker:
    build:
      context: ./worker
    container_name: hexawetter-radar-worker
    restart: unless-stopped
    env_file:
      - .env
    volumes:
      - ./data:/data
    command: ["python", "worker.py"]
    depends_on:
      - api

  radar-renderer:
    build:
      context: ./renderer
    container_name: hexawetter-radar-renderer
    restart: unless-stopped
    env_file:
      - .env
    environment:
      DATABASE_URL: postgresql://hexawetter:${POSTGRES_PASSWORD:-hexawetter}@postgres:5432/hexawetter
    volumes:
      - ./data:/data
    depends_on:
      postgres:
        condition: service_healthy
      radar-worker:
        condition: service_started

volumes:
  postgres_data:
  redis_data:
