# Portainer Stack Configuration
# This file is used when deploying via Portainer's Git repository feature

services:
  postgres:
    image: postgres:16-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-rmtpw}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-pass}
      POSTGRES_DB: ${POSTGRES_DB:-rmtpocketwatcher}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    networks:
      - rmtpw-network
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER:-rmtpw} -d ${POSTGRES_DB:-rmtpocketwatcher}"]
      interval: 10s
      timeout: 5s
      retries: 5

  backend:
    build:
      context: ../backend
      dockerfile: Dockerfile
    pull_policy: build
    restart: unless-stopped
    depends_on:
      postgres:
        condition: service_healthy
    environment:
      DATABASE_URL: postgresql://${POSTGRES_USER:-rmtpw}:${POSTGRES_PASSWORD}@postgres:5432/${POSTGRES_DB:-rmtpocketwatcher}?schema=public
      PORT: 3000
      HOST: 0.0.0.0
      NODE_ENV: production
      SCRAPE_INTERVAL_MINUTES: ${SCRAPE_INTERVAL:-5}
      SCRAPER_HEADLESS: "true"
      SCRAPER_TIMEOUT: ${SCRAPER_TIMEOUT:-30000}
      SCRAPER_MAX_RETRIES: ${SCRAPER_MAX_RETRIES:-3}
    ports:
      - "3043:3000"
    networks:
      - rmtpw-network
    labels:
      - "com.centurylinklabs.watchtower.enable=true"

volumes:
  postgres_data:
    driver: local

networks:
  rmtpw-network:
    driver: bridge
