ghalet

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 19, 2026 License: MIT Imports: 35 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

ghalet

Test Status Coverage Status MIT License PkgGoDev

English | 日本語

ghalet turns a Linux or macOS host into an automatically scaling self-hosted GitHub Actions runner environment. Put a spare Mac, a dedicated Linux machine, or an always-on VM to work for your trusted repositories, without setting up Kubernetes, Docker, or a VM for every job.

It is a Go daemon that manages GitHub Actions Runner Scale Sets and starts native runner processes as jobs arrive. Each runner handles one job, then exits; ghalet cleans up its runner directory and workspace. Several repositories or organizations can share the host with per-target and host-wide concurrency limits.

Use cases

  • Use a spare Mac for macOS builds. Run jobs directly on macOS with tools already installed on the machine.
  • Share a Linux host across trusted projects. Register several repository or organization targets and let ghalet start runners on demand within a shared capacity limit.
  • Keep the runner setup small and disposable. Run one daemon on a dedicated account or an always-on VM, including a Lima VM on macOS. Configuration defines the setup; small local state files support recovery without a separate database.

ghalet scales runner processes on one host, not the hosts themselves. It does not orchestrate multiple machines or provision per-job VMs or containers. Ephemeral registration is not job isolation: jobs share the execution user's HOME, tools, caches and privileges. Use only trusted workflows, not untrusted fork PRs or hostile code. Docker actions, job containers and service containers are unsupported.

Installation

# Install the latest version into ./bin/ by default.
% curl -sfL https://raw.githubusercontent.com/Songmu/ghalet/main/install.sh | sh -s

# Specify the installation directory and version.
% curl -sfL https://raw.githubusercontent.com/Songmu/ghalet/main/install.sh | sh -s -- -b $(go env GOPATH)/bin [vX.Y.Z]

# On Alpine Linux without curl.
% wget -O - -q https://raw.githubusercontent.com/Songmu/ghalet/main/install.sh | sh -s [vX.Y.Z]

# Or install with Go.
% go install github.com/Songmu/ghalet/cmd/ghalet@latest

Add the installation directory to your PATH. Install the build tools your workflows need and the official runner's OS prerequisites on the host. Run ghalet as a non-root user; root jobs are refused. See operations for execution users and environment settings.

Quick start

Create a configuration and authenticate with GitHub CLI as the user who will run ghalet. Replace OWNER/REPO below with your repository (or ORG for an organization):

mkdir -p ~/.config/ghalet
cat > ~/.config/ghalet/config.yaml <<'YAML'
targets:
  - id: project
    scope: OWNER/REPO
YAML
gh auth login
ghalet config validate
ghalet run

The default configuration path is ~/.config/ghalet/config.yaml; use --config /path/to/config.yaml to select another file. The default authentication uses your gh login; PAT and GitHub App credentials are also supported. For more settings, see the commented example.

Use the configured scale set name (scaleSet, or id when omitted) in a trusted workflow:

jobs:
  build:
    runs-on: project
    steps:
      - run: uname -a

In another terminal:

ghalet status
ghalet doctor
ghalet drain --target project

drain stops new job acceptance for that target and waits for accepted work; it leaves the daemon running. To stop the whole daemon, press Ctrl-C in its terminal. Both use the configured drain deadline, after which remaining jobs may be forcibly stopped. Restart the daemon to resume a drained target or apply configuration changes.

Commands

All commands accept --config PATH. A target is one configured repository or organization registration, identified locally by its id.

Command Purpose
ghalet run Run the daemon in the foreground, accepting jobs and managing runner processes for all configured targets.
ghalet config validate Check configuration syntax, values and local path constraints without registering runners or contacting GitHub.
ghalet status Read the running daemon's state and capacity snapshot. A successful response does not mean the daemon is healthy.
ghalet doctor Check the running daemon for diagnostic problems; exit nonzero when a problem is found.
ghalet drain [--target ID] Stop accepting new work and wait for accepted jobs, for one target or all targets. The daemon stays running.
ghalet gc [--dry-run] Recheck retained executions, clean up those verified safe to remove, and expire saved logs; use --dry-run to inspect without changes.
ghalet destroy --target ID --scale-set NAME Drain and delete an explicitly selected scale set after interactive yes confirmation. For an organization, also select --runner-group NAME. Runner groups are never deleted.

ghalet --version prints the installed version. Management responses are JSON. See diagnosis and cleanup for exit codes, offline maintenance and deletion safeguards.

Runtime behavior

The default host capacity is two. Targets support minimum idle runners and per-target limits; real assigned jobs take precedence over idle warm pools. Normal termination drains accepted work. Crashes recover from small atomic state files and kernel process identities, retaining uncertain executions rather than guessing which process to kill.

Runner archives are automatically downloaded for the pinned version and verified against official SHA-256 digests. Daemon stdout is JSONL; optional runner logs are archived before execution cleanup. Configuration changes and faulted targets require a normal stop/restart. Scale sets remain registered until an explicit, interactively confirmed destroy.

Documentation

Development

go test -race ./...
go vet ./...
go build ./cmd/ghalet

After changing GitHub Actions dependencies, run gh actions-lock and commit .github/workflows/actions.lock with the workflow changes. Install the tool with gh extension install github/gh-actions-lock.

Author

Songmu

Documentation

Index

Constants

View Source
const Version = "0.0.1"

Version is the application version.

Variables

View Source
var Revision = "HEAD"

Revision is the source revision, set at build time.

Functions

func RunDaemon

func RunDaemon(ctx context.Context, config *Config) error

RunDaemon runs the daemon until ctx is canceled and its runners are drained.

Types

type CapacityConfig

type CapacityConfig struct {
	MaxRunners int `yaml:"maxRunners"`
}

type CleanupConfig

type CleanupConfig struct {
	PreserveLogs bool     `yaml:"preserveLogs"`
	LogRetention Duration `yaml:"logRetention"`
	LogRoot      string   `yaml:"logRoot"`
}

type Config

type Config struct {
	Capacity CapacityConfig `yaml:"capacity"`
	Targets  []Target       `yaml:"targets"`
	Runner   RunnerConfig   `yaml:"runner"`
	Cleanup  CleanupConfig  `yaml:"cleanup"`
	Path     string         `yaml:"-"`
}

func LoadConfig

func LoadConfig(path string) (*Config, error)

func (*Config) Validate

func (c *Config) Validate() error

type Credential

type Credential struct {
	Type           string `yaml:"type"`
	Hostname       string `yaml:"hostname"`
	TokenEnv       string `yaml:"tokenEnv"`
	TokenFile      string `yaml:"tokenFile"`
	ClientID       string `yaml:"clientId"`
	PrivateKeyFile string `yaml:"privateKeyFile"`
}

type DestroyOptions

type DestroyOptions struct {
	Target      string
	RunnerGroup string
	ScaleSet    string
}

DestroyOptions identifies the registration to delete explicitly.

type DestroyPlan

type DestroyPlan struct {
	Target      string
	URL         string
	RunnerGroup string
	ScaleSet    string
	ScaleSetID  int
	GroupID     int
}

DestroyPlan describes the registration requiring approval before deletion.

type DestroyResult

type DestroyResult struct {
	Status  *Status
	Results []OperationResult
}

DestroyResult includes the drain snapshot when destruction stops before deletion.

func Destroy

func Destroy(ctx context.Context, path string, options DestroyOptions, confirm func(DestroyPlan) error) (DestroyResult, error)

Destroy drains and deletes an explicitly selected registration only after confirm approves its plan. When the daemon is unavailable, it uses locked offline execution.

type Duration

type Duration time.Duration

func (*Duration) UnmarshalYAML

func (d *Duration) UnmarshalYAML(unmarshal func(any) error) error

type OperationError

type OperationError string

OperationError reports a management failure returned with the daemon's results.

func (OperationError) Error

func (e OperationError) Error() string

type OperationResult

type OperationResult struct {
	RunID  string `json:"runId,omitempty"`
	Path   string `json:"path,omitempty"`
	Action string `json:"action,omitempty"`
	Error  string `json:"error,omitempty"`
}

func GC

func GC(ctx context.Context, path string, dryRun bool) ([]OperationResult, error)

GC cleans stopped executions and expired logs, returning partial results on error.

type Problem

type Problem struct {
	Path     string `json:"path,omitempty"`
	TargetID string `json:"targetId,omitempty"`
	RunID    string `json:"runId,omitempty"`
	Reason   string `json:"reason"`
}

type ProcessIdentity

type ProcessIdentity struct {
	PID     int    `json:"pid"`
	PGID    int    `json:"pgid"`
	UID     int    `json:"uid"`
	Started string `json:"started"`
}

type RunState

type RunState struct {
	Schema   int    `json:"schema"`
	RunID    string `json:"runId"`
	TargetID string `json:"targetId"`
	// Retained for existing state files, not used to identify registrations.
	ScopeRef     string            `json:"scopeRef,omitempty"`
	ScopeURL     string            `json:"scopeUrl"`
	GroupName    string            `json:"groupName"`
	GroupID      int               `json:"groupId"`
	ScaleSetName string            `json:"scaleSetName"`
	ScaleSetID   int               `json:"scaleSetId"`
	RunnerName   string            `json:"runnerName"`
	RunnerID     int               `json:"runnerId,omitempty"`
	User         string            `json:"user"`
	UID          int               `json:"uid"`
	Home         string            `json:"home"`
	RunnerDir    string            `json:"runnerDir"`
	Workspace    string            `json:"workspace"`
	Phase        string            `json:"phase"`
	Process      ProcessIdentity   `json:"process"`
	Members      []ProcessIdentity `json:"members,omitempty"`
	UpdatedAt    time.Time         `json:"updatedAt"`
	StartedAt    time.Time         `json:"startedAt,omitempty"`
	Ready        bool              `json:"ready"`
	Busy         bool              `json:"busy"`
	ProcessDone  bool              `json:"processDone"`
	Error        string            `json:"error,omitempty"`
}

type RunnerConfig

type RunnerConfig struct {
	Version          string            `yaml:"version"`
	User             string            `yaml:"user"`
	StartupTimeout   Duration          `yaml:"startupTimeout"`
	DrainTimeout     Duration          `yaml:"drainTimeout"`
	WorkRoot         string            `yaml:"workRoot"`
	DistributionRoot string            `yaml:"distributionRoot"`
	CacheRoot        string            `yaml:"cacheRoot"`
	Env              map[string]string `yaml:"env"`
}

type ScalingConfig

type ScalingConfig struct {
	MinRunners int `yaml:"minRunners"`
	MaxRunners int `yaml:"maxRunners"`
}

type Status

type Status struct {
	Config   string         `json:"config"`
	Capacity int            `json:"capacity"`
	Occupied int            `json:"occupied"`
	Targets  []TargetStatus `json:"targets"`
	Runs     []*RunState    `json:"runs"`
	Problems []Problem      `json:"problems"`
}

func Doctor

func Doctor(ctx context.Context, path string) (*Status, error)

Doctor returns diagnostics, including a snapshot when problems are found.

func Drain

func Drain(ctx context.Context, path, target string) (*Status, error)

Drain stops accepting work and waits for the selected target, or all targets.

func GetStatus

func GetStatus(ctx context.Context, path string) (*Status, error)

GetStatus returns the running daemon's snapshot without reloading its config.

type Target

type Target struct {
	ID             string        `yaml:"id"`
	URL            string        `yaml:"scope"`
	Credential     Credential    `yaml:"credential"`
	InstallationID int64         `yaml:"installationId"`
	RunnerGroup    string        `yaml:"runnerGroup"`
	ScaleSetName   string        `yaml:"scaleSet"`
	Scaling        ScalingConfig `yaml:"scaling"`
}

func (*Target) UnmarshalYAML

func (t *Target) UnmarshalYAML(unmarshal func(any) error) error

type TargetStatus

type TargetStatus struct {
	ID         string `json:"id"`
	Assigned   int    `json:"assignedJobs"`
	Pending    int    `json:"pendingAcquisitions"`
	Active     int    `json:"activeRunners"`
	Draining   bool   `json:"draining"`
	Forced     bool   `json:"forced"`
	Fault      string `json:"fault,omitempty"`
	ScaleSetID int    `json:"scaleSetId,omitempty"`
}

Directories

Path Synopsis
cmd
ghalet command
Package fshelper provides directory validation and atomic file writes for ghalet's managed files.
Package fshelper provides directory validation and atomic file writes for ghalet's managed files.
Package logreduct masks registered secrets in log text and slog attributes.
Package logreduct masks registered secrets in log text and slog attributes.
Package runnerdist downloads, verifies, caches, and extracts GitHub Actions runner distributions.
Package runnerdist downloads, verifies, caches, and extracts GitHub Actions runner distributions.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL