version: "3.9"

# Gitea Runner für automatische CI/CD Deployments
# Dieses Compose-File wird auf der Synology NAS deployed

services:
  gitea-runner:
    image: gitea/act_runner:latest
    container_name: gitea-runner
    restart: unless-stopped

    environment:
      # Gitea Instance URL - Passe dies an deine Gitea-Installation an
      - GITEA_INSTANCE_URL=${GITEA_URL:-http://gitea:3000}

      # Runner Registration Token - Wird aus Gitea UI generiert
      - GITEA_RUNNER_REGISTRATION_TOKEN=${RUNNER_TOKEN}

      # Runner Name - Wird in Gitea angezeigt
      - GITEA_RUNNER_NAME=${RUNNER_NAME:-synology-runner}

      # Runner Labels - Definiert welche Workflows dieser Runner ausführen kann
      # Format: label:docker://image
      - GITEA_RUNNER_LABELS=ubuntu-latest:docker://catthehacker/ubuntu:act-latest,ubuntu-22.04:docker://catthehacker/ubuntu:act-22.04,ubuntu-20.04:docker://catthehacker/ubuntu:act-20.04

      # Runner Capacity - Maximale Anzahl gleichzeitiger Jobs
      - GITEA_RUNNER_CAPACITY=${RUNNER_CAPACITY:-1}

      # Log Level
      - GITEA_RUNNER_LOG_LEVEL=${LOG_LEVEL:-info}

    volumes:
      # Runner Daten (Config, Cache, etc.)
      - runner-data:/data

      # Docker Socket - Ermöglicht dem Runner Docker-Container zu starten
      - /var/run/docker.sock:/var/run/docker.sock

      # Optional: Workspace für Job-Artefakte
      - runner-workspace:/workspace

    networks:
      - gitea-network

    # Health Check
    healthcheck:
      test: ["CMD", "pgrep", "-f", "act_runner"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s

    # Resource Limits (optional, aber empfohlen)
    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 2G
        reservations:
          cpus: '1'
          memory: 512M

volumes:
  runner-data:
    driver: local
  runner-workspace:
    driver: local

networks:
  gitea-network:
    # Wenn Gitea in einem separaten Netzwerk läuft, verwende:
    # external: true
    # Ansonsten:
    driver: bridge
