services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: bot-tom-va-app
    env_file:
      - .env
    environment:
      APP_PORT: "3100"
      DATABASE_URL: postgresql://${POSTGRES_USER:-harvzjzg_admin}:${POSTGRES_PASSWORD:?POSTGRES_PASSWORD is required}@postgres:5432/${POSTGRES_DB:-harvzjzg_va}
      REDIS_URL: redis://redis:6379
    ports:
      - "127.0.0.1:${APP_PORT:-3100}:3100"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "wget -qO- http://127.0.0.1:3100/api/health || exit 1"]
      interval: 30s
      timeout: 5s
      retries: 5
    deploy:
      resources:
        limits:
          cpus: "1.00"
          memory: 768M

  postgres:
    image: postgres:16-alpine
    container_name: bot-tom-va-postgres
    environment:
      POSTGRES_DB: ${POSTGRES_DB:-harvzjzg_va}
      POSTGRES_USER: ${POSTGRES_USER:-harvzjzg_admin}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:?POSTGRES_PASSWORD is required}
    volumes:
      - bot_tom_va_pgdata:/var/lib/postgresql/data
    restart: unless-stopped
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-harvzjzg_admin} -d ${POSTGRES_DB:-harvzjzg_va}"]
      interval: 10s
      timeout: 5s
      retries: 5
    deploy:
      resources:
        limits:
          cpus: "1.00"
          memory: 768M

  redis:
    image: redis:7-alpine
    container_name: bot-tom-va-redis
    command: ["redis-server", "--appendonly", "yes"]
    volumes:
      - bot_tom_va_redisdata:/data
    restart: unless-stopped
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 5
    deploy:
      resources:
        limits:
          cpus: "0.50"
          memory: 256M

volumes:
  bot_tom_va_pgdata:
    name: bot_tom_va_pgdata
  bot_tom_va_redisdata:
    name: bot_tom_va_redisdata
