Documentation
¶
Index ¶
- Constants
- type Arch
- type Batch
- type Batcher
- type Client
- type Email
- type Filter
- type ImageService
- type Installation
- type InstallationService
- type InstallationStore
- type Job
- type JobParams
- type JobStore
- type Machine
- type MachineStore
- type Membership
- type MembershipStore
- type Refresher
- type RegisterRunnerOpts
- type Resource
- type ResourceLimit
- type ResourceService
- type Runner
- type RunnerManager
- type RunnerService
- type RunnerStatus
- type RunnerStore
- type RunnerWithToken
- type Scheduler
- type Session
- type SnapshotMount
- type SnapshotService
- type Syncer
- type System
- type User
- type UserParams
- type UserService
- type UserStore
Constants ¶
const ( InstallationTypeOrganization = "organization" InstallationTypeUser = "user" )
const ( // JobStatusQueued indicates a job is waiting to be assigned to a runner. JobStatusQueued = "queued" // JobStatusInProgress indicates a job is currently running. JobStatusInProgress = "in_progress" // JobStatusCompleted indicates a job has finished execution. JobStatusCompleted = "completed" // JobStatusWaiting indicates a job is currently waiting. JobStatusWaiting = "waiting" )
const ( // MachineStatusOnline indicates the machine is online and available for jobs MachineStatusOnline = "online" // MachineStatusOffline indicates the machine is offline (graceful shutdown) MachineStatusOffline = "offline" // MachineStatusPaused indicates the machine is paused and will not accept new jobs MachineStatusPaused = "paused" )
const ( MembershipRoleAdmin = "admin" MembershipRoleMember = "member" MembershipRoleOwner = "owner" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Arch ¶
type Arch uint8
Arch represents a supported CPU architecture.
func (Arch) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface for serializing Arch to JSON.
func (*Arch) UnmarshalJSON ¶
UnmarshalJSON implements the json.Unmarshaler interface for deserializing Arch from JSON.
type Batch ¶
type Batch struct {
Insert []*Installation `json:"insert"`
Update []*Installation `json:"update"`
Revoke []*Installation `json:"revoke"`
}
Batch represents a Batch request to synchronize the local membership store for a user account.
type Client ¶
type Client interface {
// Join notifies the server the machine is joining the cluster.
Join(ctx context.Context) error
// Leave notifies the server the machine is leaving the cluster.
Leave(ctx context.Context) error
// Ping sends a ping message to the server to test connectivity.
Ping(ctx context.Context, resource *Resource) error
// Request requests the next available runner for execution.
Request(ctx context.Context) (*Runner, error)
// Accept accepts the runner for execution.
Accept(ctx context.Context, runner *Runner) error
// Register registers the runner to GitHub.
Register(ctx context.Context, runner *Runner) (*RunnerWithToken, error)
// Started signals the runner has started.
Started(ctx context.Context, runner *Runner) error
// Lock locks resources for a Runner.
Lock(ctx context.Context, runner *Runner) error
// Unlock unlocks resources for a Runner.
Unlock(ctx context.Context, runner *Runner) error
// Watch watches the runner for cancellation.
Watch(ctx context.Context, runner *Runner) (bool, error)
}
A Client manages communication with the server.
type Email ¶
type Email struct {
Email string `json:"email"`
Primary bool `json:"primary"`
Verified bool `json:"verified"`
}
Email represents a user email.
type Filter ¶
type Filter struct {
Arch string `json:"arch"`
CPU int64 `json:"cpu"`
Owner string `json:"owner"`
RAM int64 `json:"ram"`
}
Filter provides filter criteria to limit jobs requested from the scheduler.
type ImageService ¶
type ImageService interface {
// Pull downloads a container image from a registry.
Pull(ctx context.Context, ref string) error
// Exists checks if an image is available locally.
Exists(ctx context.Context, ref string) (bool, error)
// Delete removes an image from local storage.
Delete(ctx context.Context, ref string) error
}
ImageService manages container images used for runner VMs.
type Installation ¶
type Installation struct {
ID int64 `json:"id"`
Login string `json:"login"`
Avatar string `json:"avatar_url"`
Type string `json:"account_type"`
Membership *Membership `json:"membership,omitempty"`
Created int64 `json:"created_at"`
Suspended int64 `json:"suspended_at"`
Updated int64 `json:"updated_at"`
}
Installation represents a GitHub app installation
type InstallationService ¶
type InstallationService interface {
// List returns a slice of installation the user as access to.
List(ctx context.Context, user *User) ([]*Installation, error)
// FindMembership returns the membership of the user for an organization.
FindMembership(ctx context.Context, user *User, org string) (*Membership, error)
}
InstallationService provides access to installation from GitHub.
type InstallationStore ¶
type InstallationStore interface {
// Count returns a count of active installations from the datastore.
Count(ctx context.Context) (int64, error)
// Create persists a new installation to the datastore.
Create(ctx context.Context, installation *Installation) error
// Delete deletes an installation from the datastore.
Delete(ctx context.Context, installation *Installation) error
// Find returns installation by ID
Find(ctx context.Context, id int64) (*Installation, error)
// FindLogin returns installation by login
FindLogin(ctx context.Context, login string) (*Installation, error)
// List returns a slice of installations for a user from the datastore.
List(ctx context.Context, user *User) ([]*Installation, error)
// Update persists an updated installation to the datastore.
Update(ctx context.Context, installation *Installation) error
}
InstallationStore defines operations for working with installation on a datastore.
type Job ¶
type Job struct {
ID int64 `json:"id"` // GitHub workflow job ID
InstallationID int64 `json:"installation_id"` // GitHub App installation ID
RunnerID int64 `json:"runner_id"` // Assigned GitHub runner ID (0 if not assigned)
RunnerName string `json:"runner_name"` // Assigned runner name (empty if not assigned)
Owner string `json:"owner"` // Repository owner
Repo string `json:"repo"` // Repository name
RunID int64 `json:"run_id"` // GitHub workflow run ID
Workflow string `json:"workflow"` // Workflow name
Name string `json:"name"` // Job name
Branch string `json:"branch"` // Branch name where workflow run originated
SHA string `json:"sha"` // Commit SHA that triggered the workflow run
Status string `json:"status"` // Job status (queued, in_progress, completed, waiting)
Conclusion string `json:"conclusion"` // Job conclusion (success, failure, etc.)
Labels []string `json:"labels"` // Required runner labels
URL string `json:"url"` // URL to request runner registration token
AuthorLogin string `json:"author_login"` // Login of the job's author
AuthorAvatar string `json:"author_avatar"` // AvatarURL of the job's author
Completed int64 `json:"completed"` // Unix timestamp when job completed
Created int64 `json:"created"` // Unix timestamp when job record was created
Queued int64 `json:"queued"` // Unix timestamp when job was queued
Started int64 `json:"started"` // Unix timestamp when job started
Updated int64 `json:"updated"` // Unix timestamp when job was last updated
Version int64 `json:"version"` // Optimistic locking version
}
Job represents a GitHub Actions workflow job. A Job is associated with a Runner when assigned, but they have independent lifecycles. A runner created for job A may be assigned to job B.
type JobParams ¶
type JobParams struct {
After int64 // Pagination cursor (job ID)
Limit int // Maximum number of results
Status string // Filter by status
}
JobParams defines job query parameters.
type JobStore ¶
type JobStore interface {
// Count returns a count of all jobs.
Count(context.Context) (int64, error)
// Create persists a new job to the datastore.
Create(ctx context.Context, job *Job) error
// Delete deletes a job from the datastore.
Delete(ctx context.Context, job *Job) error
// Find returns a job from the datastore by its ID.
Find(ctx context.Context, owner string, id int64) (*Job, error)
// ListCompleted returns a list of jobs from the
// datastore with completed status.
ListCompleted(ctx context.Context, owner string, limit, offset int) ([]*Job, error)
// ListIncomplete returns a list of jobs from the
// datastore with imcomplete status.
ListIncomplete(ctx context.Context, owner string) ([]*Job, error)
// Purge deletes all completed jobs older than the given unix timestamp.
Purge(ctx context.Context, before int64) error
// Update persists an updated job to the datastore.
Update(ctx context.Context, job *Job) error
}
JobStore defines operations for working with jobs in a datastore.
type Machine ¶
type Machine struct {
Name string `json:"name"`
Owner string `json:"owner"`
Arch Arch `json:"arch"`
CPU int64 `json:"cpu"`
CPULimit int64 `json:"cpu_limit"`
CPUAllocated int64 `json:"cpu_allocated"`
Labels []string `json:"labels"`
RAMAvailable int64 `json:"ram_available"`
RAMLimit int64 `json:"ram_limit"`
RAMAllocated int64 `json:"ram_allocated"`
RAMTotal int64 `json:"ram_total"`
Status string `json:"status"`
Created int64 `json:"created_at"`
LastSeen int64 `json:"last_seen_at"`
Updated int64 `json:"updated_at"`
Token string `json:"-"`
}
Machine represents a server running an agent.
type MachineStore ¶
type MachineStore interface {
// Create persists a new machine to the datastore.
Create(ctx context.Context, machine *Machine) error
// Update persists an updated machine to the datastore.
Update(ctx context.Context, machine *Machine) error
// Delete deletes a machine from the datastore.
Delete(ctx context.Context, machine *Machine) error
// Find returns a machine by hostname and owner.
Find(ctx context.Context, owner, name string) (*Machine, error)
// FindToken returns a machine by its authentication token.
FindToken(ctx context.Context, token string) (*Machine, error)
// List returns all machines owned by a user.
List(ctx context.Context, owner string) ([]*Machine, error)
// Purge deletes offline machines (last_seen older than timestamp).
Purge(ctx context.Context, before int64) error
}
MachineStore defines operations for working with machine on a datastore.
type Membership ¶
type Membership struct {
InstallationID int64 `json:"-"`
UserID int64 `json:"-"`
Role string `json:"role"`
State string `json:"state"`
Created int64 `json:"-"`
Synced int64 `json:"-"`
Updated int64 `json:"-"`
}
Membership represents an individual membership between an installation and a user.
type MembershipStore ¶
type MembershipStore interface {
// Find returns an org membership from the datastore.
Find(ctx context.Context, installID, userID int64) (*Membership, error)
// Update persists an updated org member to the datastore.
Update(ctx context.Context, membership *Membership) error
}
type RegisterRunnerOpts ¶
type RegisterRunnerOpts struct {
GroupID int64
InstallationID int64
Labels []string
Name string
Owner string
}
RegisterRunnerOpts defines optional instructions for registering runner instances at the organization level.
type Resource ¶
type Resource struct {
Arch Arch `json:"arch"`
CPU int64 `json:"cpu"`
RAMTotal int64 `json:"ram_total"`
RAMAvailable int64 `json:"ram_available"`
}
Resource represents the resources of a machine.
type ResourceLimit ¶
ResourceLimit represents limits on machine resource utilisation.
type ResourceService ¶
type ResourceService interface {
// Report reports resource of the machine
Report(ctx context.Context) (*Resource, error)
}
ResourceService provides access to machine resources.
type Runner ¶
type Runner struct {
Name string `json:"name"`
Machine string `json:"machine"`
ID int64 `json:"id"`
InstallationID int64 `json:"installation_id"`
Owner string `json:"owner"`
Status RunnerStatus `json:"status"`
Arch Arch `json:"arch"`
CPU int64 `json:"cpu"`
RAM int64 `json:"ram"`
GroupID int64 `json:"group_id"`
Labels []string `json:"labels"`
Cancelled int64 `json:"cancelled"`
Created int64 `json:"created"`
Accepted int64 `json:"accepted"`
Started int64 `json:"started"`
Stopped int64 `json:"stopped"`
Updated int64 `json:"updated"`
Token string `json:"-"`
}
Runner represents a GitHub Actions runner.
type RunnerManager ¶
type RunnerManager interface {
// Request requests the next available runner that matches
// machine's capacities. Returns the runner if found, nil if no matching
// runner available.
Request(ctx context.Context, params *Filter) (*Runner, error)
// Accept accepts a runner for execution. This operation uses optimistic
// locking to prevent multiple agents from executing the same runner.
Accept(ctx context.Context, name, machine string) error
// Register registers the runner on GitHub and retrieve its just-in-time
// configuration.
Register(ctx context.Context, name string) (*RunnerWithToken, error)
// Watch watches the runner for cancellation.
// It returns true if the runner has been cancelled, false otherwise.
// The agent should call this method periodically during job execution to
// check for cancellation requests.
Watch(ctx context.Context, name string) (bool, error)
}
RunnerManager encapsulates complex runner operations and provides a simplified interface for runner agents.
type RunnerService ¶
type RunnerService interface {
// Delete deletes a self-hosted runner.
Delete(ctx context.Context, runner *Runner) error
// Find returns a runner for an organization.
Find(ctx context.Context, owner string, installationID, runnerID int64) (*Runner, error)
// Register registers a new self-hosted runner on GitHub.
Register(ctx context.Context, opts RegisterRunnerOpts) (*Runner, error)
}
RunnerService provides access to self-hosted runners from GitHub.
type RunnerStatus ¶ added in v0.2.0
type RunnerStatus uint8
RunnerStatus specifies the status of a runner.
const ( // RunnerStatusUnknown is an unknown status. RunnerStatusUnknown RunnerStatus = iota + 1 // RunnerStatusPending indicates a Runner is pending creation. RunnerStatusPending // RunnerStatusRegistered indicates a Runner is registered to GitHub. RunnerStatusRegistered // RunnerStatusIdle indicates a Runner is online and not running any job. RunnerStatusIdle // RunnerStatusBusy indicates a Runner is running a job. RunnerStatusBusy // RunnerStatusCompleted indicates a runner has completed running a job. RunnerStatusCompleted )
func (*RunnerStatus) Scan ¶ added in v0.2.0
func (r *RunnerStatus) Scan(v interface{}) error
Scan implements the sql.Scanner interface.
func (*RunnerStatus) Set ¶ added in v0.2.0
func (r *RunnerStatus) Set(s string) error
Set implements the flag.Value interface.
func (RunnerStatus) String ¶ added in v0.2.0
func (r RunnerStatus) String() string
String implements the fmt.Stringer interface.
type RunnerStore ¶
type RunnerStore interface {
// Create persists a new runner to the datastore.
Create(ctx context.Context, runner *Runner) error
// Delete deletes a runner from the datastore.
Delete(ctx context.Context, runner *Runner) error
// Find returns a runner from the datastore by its name.
Find(ctx context.Context, name string) (*Runner, error)
// FindID returns a runner from the datastore by its GitHub runner ID.
FindID(ctx context.Context, id int64) (*Runner, error)
// ListStatus returns a slice of runners by status.
ListStatus(ctx context.Context, status RunnerStatus) ([]*Runner, error)
// ListMachine returns a slice of runners for a given machine.
ListMachine(context.Context, *Machine) ([]*Runner, error)
// Purge deletes all stopped runners older than the given unix timestamp.
Purge(ctx context.Context, before int64) error
// Update persists an updated runner to the datastore.
Update(ctx context.Context, runner *Runner) error
}
RunnerStore defines operations for working with runners in a datastore.
type RunnerWithToken ¶
type Scheduler ¶
type Scheduler interface {
// Cancel cancels scheduled or running runner.
Cancel(ctx context.Context, runnerName string) error
// Cancelled blocks and listens for a cancellation event
// returning true if the runner has been cancelled.
Cancelled(ctx context.Context, runnerName string) (bool, error)
// Request requests the next job scheduled for execution.
Request(ctx context.Context, machine *Machine) (*Runner, error)
// Schedule schedules the runner for execution.
Schedule(ctx context.Context, runner *Runner) error
}
Scheduler schedules runners for execution.
type Session ¶
type Session interface {
// Create creates a new user session.
Create(http.ResponseWriter, *User) error
// Delete deletes the user session.
Delete(http.ResponseWriter) error
// Get returns the user session.
Get(*http.Request) (*User, error)
}
Session provides session management for authenticated users.
type SnapshotMount ¶
type SnapshotMount struct {
// Source is the path to mount source
Source string
// Type is the filesystem type
Type string
}
SnapshotMount contains mount point information for a snapshot.
type SnapshotService ¶
type SnapshotService interface {
// Create creates a new snapshot from an image for a runner.
Create(ctx context.Context, name string, ref string) (*SnapshotMount, error)
// Delete removes a snapshot and release its resources.
Delete(ctx context.Context, name string) error
// Exists checks if a snapshot exists.
Exists(ctx context.Context, name string) (bool, error)
// Find returns mount information for an existing snaphot.
Find(ctx context.Context, name string) (*SnapshotMount, error)
}
SnapshotService manages filesystem snapshots for runner VMs.
type User ¶
type User struct {
ID int64 `json:"id"`
Login string `json:"login"`
Email string `json:"email"`
Avatar string `json:"avatar_url"`
Active bool `json:"active"`
Admin bool `json:"admin"`
Created int64 `json:"created_at"`
Updated int64 `json:"updated_at"`
Synced int64 `json:"synced_at"`
Syncing bool `json:"syncing"`
Access string `json:"-"`
Refresh string `json:"-"`
Expiry int64 `json:"-"`
Token string `json:"-"`
}
User represents a user of the system
type UserParams ¶
UserParams defines user query parameters.
type UserService ¶
type UserService interface {
// Find returns the authenticated user.
Find(ctx context.Context, access, refresh string) (*User, error)
// FindEmail returns the authenticated user primary email.
FindEmail(ctx context.Context, user *User) (*Email, error)
// ListEmail returns the authenticated user email list.
ListEmail(ctx context.Context, user *User) ([]*Email, error)
}
UserService provides access to user account from GitHub.
type UserStore ¶
type UserStore interface {
// Count returns a count of users.
Count(context.Context) (int64, error)
// Create persists a new user to the datastore.
Create(ctx context.Context, user *User) error
// Delete deletes a user from the datastore.
Delete(ctx context.Context, user *User) error
// Find returns a user from the datastore by its ID.
Find(ctx context.Context, id int64) (*User, error)
// FindLogin returns a user from the datastore by its login.
FindLogin(ctx context.Context, login string) (*User, error)
// FindToken returns a user from the datastore by its token.
FindToken(ctx context.Context, token string) (*User, error)
// List returns a list of users from the datastore.
List(ctx context.Context, params UserParams) ([]*User, error)
// Update persists an updated user to the datastore.
Update(ctx context.Context, user *User) error
}
UserStore defines operations for working with user on a datastore.