services:
  big-agi:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - "1004:3000"
    command: [ "next", "start", "-p", "3000" ]
    deploy:
      resources:
        limits:
          cpus: '0.2'
          memory: 256M
        reservations:
          memory: 128M
    restart: unless-stopped
    environment:
      - POSTGRES_PRISMA_URL=postgresql://bigagi:${POSTGRES_PASSWORD}@postgres:5432/bigagi?schema=public
      - HTTP_BASIC_AUTH_USERNAME=${HTTP_BASIC_AUTH_USERNAME}
      - HTTP_BASIC_AUTH_PASSWORD=${HTTP_BASIC_AUTH_PASSWORD}
    depends_on:
      - postgres

  postgres:
    image: postgres:15-alpine
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=bigagi
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=bigagi
    restart: unless-stopped
    deploy:
      resources:
        limits:
          cpus: '0.3'
          memory: 512M

  watchtower:
    image: containrrr/watchtower
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    command: --schedule "0 0 * * *" --cleanup
    restart: unless-stopped

volumes:
  postgres_data:
