ghalet

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2026 License: MIT Imports: 36 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 Ask DeepWiki

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

Linux .deb/.rpm packages with a systemd unit and a GHCR container image are also built for releases. See packages and containers for installation, configuration, and updates.

# 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. See authentication setup for the required permissions, PAT creation and GitHub App installation. 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

To stop the daemon, press Ctrl-C in its terminal. Normal shutdown stops new job acceptance for all targets and waits for accepted work, using the configured drain deadline. After that deadline, remaining jobs may be forcibly stopped. After editing configuration, use ghalet apply (or sudo systemctl reload ghalet for the packaged service) to drain and reconfigure without exiting the daemon.

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 for all configured targets.
ghalet apply Drain targets, reload configuration, and reconcile registrations, attempting to delete unused scale sets.
ghalet config validate Validate configuration and local paths without contacting GitHub.
ghalet auth setup NAME --target ID Create and install a private GitHub App for one GitHub.com target using a browser. See App setup for local/SSH setup and resumption.
ghalet credential set NAME --prompt Save an owner-only credential file and update defaults.credential. See ordinary credentials for App keys and replacement.
ghalet systemd credential set NAME --prompt Register an encrypted service PAT and update defaults.credential (Linux/root). See credentials for App keys, automation and rotation.
ghalet list List accessible daemons, management UIDs, sockets and running snapshots; filter with --config PATH.
ghalet status Read state and capacity; a successful response does not imply health.
ghalet doctor Diagnose the daemon; exit nonzero for any problem.
ghalet gc [--dry-run] Clean verified stopped executions and expired logs; preview with --dry-run.

ghalet --version prints the installed version. Management responses are JSON, except for the credential setup instructions. systemd credential set defaults to /etc/ghalet/config.yaml. Without --config, status, doctor, apply, and gc automatically select the single accessible daemon; multiple daemons require an explicit config. With none found, the per-user default ~/.config/ghalet/config.yaml is used, as it is for run and config validate. See configuration apply and diagnosis and cleanup for exit codes, offline maintenance and deletion safeguards.

Runtime behavior

Host capacity defaults to two, with per-target limits and optional idle warm pools. Assigned jobs take priority. Atomic state files and kernel process identities support crash recovery; unverifiable executions retain capacity.

Runner archives are automatically downloaded for the pinned version and verified against official SHA-256 digests. Daemon stdout is JSONL; runner logs are archived before cleanup by default. See operations for retries, recovery and log policy.

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.3"

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.

func StateDirectory added in v0.0.3

func StateDirectory() (string, error)

StateDirectory returns the persistent application directory used by this process.

Types

type ApplyResult added in v0.0.2

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

ApplyResult includes the applied snapshot and individual reconciliation results.

func Apply added in v0.0.2

func Apply(ctx context.Context, path string) (ApplyResult, error)

Apply asks the running daemon to reload its configuration and waits for completion.

type CapacityConfig

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

type Config

type Config struct {
	Defaults DefaultsConfig `yaml:"defaults"`
	Capacity CapacityConfig `yaml:"capacity"`
	Targets  []Target       `yaml:"targets"`
	Runner   RunnerConfig   `yaml:"runner"`
	Logs     LogsConfig     `yaml:"logs"`
	Path     string         `yaml:"-"`
	// contains filtered or unexported fields
}

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"`
}

func (*Credential) UnmarshalYAML added in v0.0.2

func (c *Credential) UnmarshalYAML(unmarshal func(any) error) error

type DaemonInfo added in v0.0.2

type DaemonInfo struct {
	UID    int    `json:"uid"`
	Socket string `json:"socket"`
	Status Status `json:"status"`
}

DaemonInfo identifies an accessible daemon and its running snapshot.

func ListDaemons added in v0.0.2

func ListDaemons(ctx context.Context, config string) ([]DaemonInfo, error)

ListDaemons finds responsive daemons accessible to the management user. A nonempty config path limits discovery to that configuration.

type DefaultsConfig added in v0.0.2

type DefaultsConfig struct {
	Credential *Credential `yaml:"credential"`
}

type Duration

type Duration time.Duration

func (*Duration) UnmarshalYAML

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

type LogsConfig added in v0.0.2

type LogsConfig struct {
	Preserve  bool     `yaml:"preserve"`
	Retention Duration `yaml:"retention"`
	Root      string   `yaml:"root"`
}

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 {
	TargetID string `json:"targetId,omitempty"`
	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:"-"`
	CacheRoot      string            `yaml:"-"`
	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 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"`
	// contains filtered or unexported fields
}

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
Package appsetup creates a private GitHub App from a Manifest and configures one GitHub.com target without starting or reconfiguring the daemon.
Package appsetup creates a private GitHub App from a Manifest and configures one GitHub.com target without starting or reconfiguring the daemon.
cmd
ghalet command
Package credentialstore manages encrypted systemd credentials for ghalet.
Package credentialstore manages encrypted systemd credentials for ghalet.
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