wulukewu's picture
feat(hf): add Hugging Face Spaces compatible GitLab runner
66a1d1b
|
Raw History Blame Contribute Delete
3.28 kB
metadata
title: GitLab Runner Docker HF
sdk: docker
app_port: 7860

GitLab Runner Docker — Hugging Face Spaces Edition

A highly customizable GitLab Runner packaged in a Docker container, designed for Hugging Face Spaces. Features automatic configuration generation and a built-in status dashboard.

Features

  • Multi-Token Support: Register and run multiple GitLab Runners using a comma-separated list of tokens.
  • Auto-Configuration: Generates config.toml dynamically from environment variables on startup.
  • Built-in Dashboard: Lightweight Python-based dashboard to monitor runner status and jobs.
  • Supervisor Managed: Ensures both the GitLab Runner and the dashboard stay running.
  • Hugging Face Spaces Ready: Pre-configured for 2 vCPU / 16 GB RAM free tier, non-root user (UID 1000).

Deploy on Hugging Face Spaces

  1. Fork this repository to your GitHub account.

  2. Create a new Space on Hugging Face:

    • SDK: Docker
    • Space hardware: CPU basic (free)
    • Set app_port to 7860
  3. Connect your repository to the Space (Settings → Repository).

  4. Set secrets in your Space settings:

    • RUNNER_TOKEN: Your GitLab runner authentication token(s), comma-separated for multiple runners.
    • GITLAB_API_TOKEN: Personal Access Token with read_api scope (for the dashboard).
    • RUNNER_NAME: Name prefix for the runners.
    • GITLAB_GROUP_ID: Optional group ID to scope the dashboard.
  5. Keep awake (free tier sleeps after 48h of inactivity):

    • Use UptimeRobot (free) to ping https://your-space.hf.space/health every 5 minutes.
    • Or use a GitHub Actions cron job with curl.

Quick Start (Local)

cp .env.example .env
# Edit .env and set RUNNER_TOKEN
docker compose up -d
# Dashboard at http://localhost:7860

Configuration

Variable Description Default
RUNNER_TOKEN Required. One or more runner tokens (comma-separated). -
GITLAB_API_TOKEN PAT with read_api for the dashboard. -
GITLAB_URL Your GitLab instance URL. https://gitlab.com
RUNNER_NAME Base name for the runners. gitlab-runner
RUNNER_EXECUTOR Executor type (shell, docker). shell
RUNNER_CONCURRENT Max parallel jobs. 2
DASHBOARD_PORT Dashboard port. 7860

Docker Executor (requires privileged mode, not available on HF Spaces free tier)

If RUNNER_EXECUTOR=docker is used:

  • RUNNER_DOCKER_IMAGE: Default image (default: docker:24.0.5).
  • RUNNER_DOCKER_PRIVILEGED: Enable privileged mode (default: true).

Keep Alive

Free Hugging Face Spaces sleep after 48 hours of no traffic. To keep your runner online:

  1. Sign up for UptimeRobot (free, no credit card).
  2. Add a new monitor → HTTP(s) → https://your-space.hf.space/health → 5-minute interval.
  3. The dashboard's /health endpoint keeps the Space awake.

Architecture

  • Dockerfile: Inherits from gitlab/gitlab-runner:latest, adds Node.js 20, Python 3, Supervisor.
  • entrypoint.sh: Generates config.toml dynamically from environment variables.
  • supervisord.conf: Manages runner + dashboard lifecycle.
  • dashboard/: Status page and Python API server.