services:
  web:
    build: .
    ports:
      - "54321:5000"
    volumes:
      - ./app/static/uploads:/app/app/static/uploads
      - ./pet_pictures.db:/app/pet_pictures.db
    environment:
      - FLASK_APP=main.py
      - FLASK_ENV=production
      - GUNICORN_CMD_ARGS=--workers=4 --bind=0.0.0.0:5000 --timeout=120 --keep-alive=5 --worker-class=sync --worker-connections=1000 --max-requests=1000 --max-requests-jitter=50
      # Application configuration
      - UPLOAD_FOLDER=app/static/uploads
      - DATABASE_PATH=pet_pictures.db
      - ADMIN_USERNAME=admin
      - ADMIN_PASSWORD=password123
    restart: unless-stopped
    healthcheck:
      test:
        [
          "CMD",
          "curl",
          "-f",
          "http://localhost:5000/",
          "--connect-timeout",
          "5",
          "--retry",
          "3",
          "--retry-delay",
          "5",
        ]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

  migrate:
    build: .
    volumes:
      - ./pet_pictures.db:/app/pet_pictures.db
    command: python migrate_session_changes.py
    profiles:
      - migrate
