# PragmaCloud — klijentska instalacija
# Koristi pre-built image s GHCR, NE gradi lokalno.
#
# Postavljanje:
#   cp .env.example .env   # pa uredi .env
#   docker compose -f docker-compose.client.yml up -d

services:
  pragmacloud:
    image: ghcr.io/slavkomatanovic/pragmacloud:latest
    container_name: pragmacloud
    restart: unless-stopped
    pull_policy: always       # uvijek provjeri novu verziju pri ručnom up
    ports:
      - "${APP_PORT:-8080}:8080"
    volumes:
      - ${SQLITE_DIR:-/opt/pragma/tabele}:/data:rw
    environment:
      ASPNETCORE_ENVIRONMENT: Production
      ConnectionStrings__PragmaCloud: "Data Source=/data/PRAGMA_be.sqlite"
      PRAGMA_LICENSE_KEY: "${PRAGMA_LICENSE_KEY}"
    env_file:
      - .env
    healthcheck:
      test: ["CMD", "curl", "-f", "-L", "http://localhost:8080/"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 25s

  # Automatsko ažuriranje — provjerava GHCR jednom dnevno u 02:00
  watchtower:
    image: containrrr/watchtower:latest
    container_name: watchtower
    restart: unless-stopped
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      # Ako GHCR repo je privatan, Watchtower treba credentials:
      # - ${HOME}/.docker/config.json:/config.json:ro
    environment:
      WATCHTOWER_CLEANUP: "true"
      WATCHTOWER_INCLUDE_STOPPED: "false"
      WATCHTOWER_SCHEDULE: "0 0 2 * * *"     # svaki dan u 02:00
      WATCHTOWER_TIMEOUT: "30s"
      WATCHTOWER_NOTIFICATIONS_LEVEL: warn
      # Opcionalno: Slack/email notifikacije pri ažuriranju
      # WATCHTOWER_NOTIFICATION_EMAIL_FROM: "${EMAIL_FROM}"
      # WATCHTOWER_NOTIFICATION_EMAIL_TO:   "${EMAIL_TO}"
    labels:
      - "com.centurylinklabs.watchtower.enable=false"   # Watchtower ne ažurira sam sebe
