# ============================================================
# WatchtowerDocker — Complete Docker Compose Setup
# Download from: https://watchtowerdocker.com
# ============================================================
#
# QUICK START:
#   1. Save this file as docker-compose.yml
#   2. Edit WATCHTOWER_NOTIFICATION_URL with your webhook
#   3. Run: docker compose up -d
#
# DOCS: https://watchtowerdocker.com/blog/watchtower-docker-compose-setup.html
# ============================================================

version: "3.8"

services:

  # ── Watchtower — Auto-update all Docker containers ──
  watchtower:
    image: containrrr/watchtower:latest
    container_name: watchtower
    restart: unless-stopped

    volumes:
      # Docker socket — required for Watchtower to monitor containers
      - /var/run/docker.sock:/var/run/docker.sock
      # Host timezone — ensures cron schedules run at correct local time
      - /etc/localtime:/etc/localtime:ro
      # Docker registry credentials — needed for private registries
      # Uncomment the line below if using private registries (Docker Hub, GHCR, ECR, etc.)
      # - $HOME/.docker/config.json:/config.json:ro

    environment:
      # ── Scheduling ──────────────────────────────────────────
      # Option A: Run at a fixed time every day (6-field cron, seconds first)
      WATCHTOWER_SCHEDULE: "0 0 4 * * *"      # 4:00 AM every day
      # Option B: Use polling interval in seconds (uncomment to use instead of SCHEDULE)
      # WATCHTOWER_POLL_INTERVAL: "86400"      # Every 24 hours

      # ── Timezone ────────────────────────────────────────────
      TZ: "America/New_York"                   # Change to your timezone (e.g. Europe/London)

      # ── Update Behaviour ────────────────────────────────────
      WATCHTOWER_CLEANUP: "true"               # Remove old images after successful update
      WATCHTOWER_ROLLING_RESTART: "true"       # Update one container at a time (safer)
      WATCHTOWER_TIMEOUT: "30s"                # Graceful stop timeout before forced kill

      # ── Container Scope ─────────────────────────────────────
      # Set to "true" to ONLY update containers with label:
      #   com.centurylinklabs.watchtower.enable=true
      WATCHTOWER_LABEL_ENABLE: "false"

      # ── Notifications (choose one method) ───────────────────
      # Modern method — Shoutrrr URL (supports 20+ services):
      # WATCHTOWER_NOTIFICATION_URL: "slack://TOKEN@CHANNEL"
      # WATCHTOWER_NOTIFICATION_URL: "telegram://BOT_TOKEN@telegram?channels=CHAT_ID"
      # WATCHTOWER_NOTIFICATION_URL: "discord://TOKEN@WEBHOOK_ID"
      # WATCHTOWER_NOTIFICATION_URL: "ntfy://TOPIC@ntfy.sh"
      # WATCHTOWER_NOTIFICATION_URL: "gotify://HOSTNAME/TOKEN"

      # Legacy Slack method:
      # WATCHTOWER_NOTIFICATIONS: "slack"
      # WATCHTOWER_NOTIFICATION_SLACK_HOOK_URL: "https://hooks.slack.com/services/..."

      # Email (SMTP):
      # WATCHTOWER_NOTIFICATIONS: "email"
      # WATCHTOWER_NOTIFICATION_EMAIL_FROM: "watchtower@example.com"
      # WATCHTOWER_NOTIFICATION_EMAIL_TO: "admin@example.com"
      # WATCHTOWER_NOTIFICATION_EMAIL_SERVER: "smtp.gmail.com"
      # WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PORT: "587"
      # WATCHTOWER_NOTIFICATION_EMAIL_SERVER_USER: "user@gmail.com"
      # WATCHTOWER_NOTIFICATION_EMAIL_SERVER_PASSWORD: "yourAppPassword"

      # ── HTTP API (trigger updates from CI/CD) ───────────────
      # WATCHTOWER_HTTP_API_UPDATE: "true"
      # WATCHTOWER_HTTP_API_TOKEN: "yourSecretToken"

      # ── Debug / Logging ─────────────────────────────────────
      # WATCHTOWER_DEBUG: "true"              # Uncomment to enable verbose logging

    # Expose API port (only needed if HTTP API is enabled above)
    # ports:
    #   - "8080:8080"

    labels:
      # Prevent Watchtower from updating itself (optional — remove to allow self-update)
      com.centurylinklabs.watchtower.enable: "true"

# ============================================================
# EXAMPLE: Adding your own app containers alongside Watchtower
# ============================================================
# Uncomment and adapt the example below to add your own services.
# Watchtower will auto-update them based on your schedule above.
#
# my-app:
#   image: myapp:latest
#   container_name: my-app
#   restart: unless-stopped
#   ports:
#     - "3000:3000"
#   labels:
#     # Set to "false" to exclude this container from auto-updates:
#     com.centurylinklabs.watchtower.enable: "true"
#
# ── Common self-hosted apps (all have Docker Hub images) ──
#
# vaultwarden:
#   image: vaultwarden/server:latest
#   container_name: vaultwarden
#   restart: unless-stopped
#   volumes:
#     - vaultwarden_data:/data
#
# n8n:
#   image: n8nio/n8n
#   container_name: n8n
#   restart: unless-stopped
#   ports:
#     - "5678:5678"
#   volumes:
#     - n8n_data:/home/node/.n8n
#
# ollama:
#   image: ollama/ollama
#   container_name: ollama
#   restart: unless-stopped
#   volumes:
#     - ollama_data:/root/.ollama
#
# jellyfin:
#   image: jellyfin/jellyfin
#   container_name: jellyfin
#   restart: unless-stopped
#   ports:
#     - "8096:8096"
#
# volumes:
#   vaultwarden_data:
#   n8n_data:
#   ollama_data:

# ============================================================
# MORE DOCS & GUIDES:
#   Install Guide:       https://watchtowerdocker.com/blog/how-to-install-watchtower-docker.html
#   Environment Vars:    https://watchtowerdocker.com/blog/watchtower-environment-variables.html
#   Notifications:       https://watchtowerdocker.com/blog/watchtower-docker-notifications.html
#   Troubleshooting:     https://watchtowerdocker.com/blog/watchtower-troubleshooting.html
#   Self-Hosted Apps:    https://watchtowerdocker.com/blog/watchtower-selfhosted-apps.html
# ============================================================
