gitops

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package gitops provides configuration-as-code support for runs-fleet. It watches for configuration changes in GitHub repositories and applies them to DynamoDB.

Package gitops provides GitHub API integration for configuration management.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeBase64Content

func DecodeBase64Content(encoded string) ([]byte, error)

DecodeBase64Content decodes base64-encoded content from GitHub API.

Types

type Commit

type Commit struct {
	ID       string   `json:"id"`
	Added    []string `json:"added"`
	Modified []string `json:"modified"`
	Removed  []string `json:"removed"`
}

Commit represents a commit from a push event.

type Config

type Config struct {
	Version string       `yaml:"version"`
	Pools   []PoolConfig `yaml:"pools"`
	Runners []RunnerSpec `yaml:"runners,omitempty"`
}

Config represents the runs-fleet configuration file schema. This maps to .github-private/.github/runs-fleet.yml

func ParseConfig

func ParseConfig(data []byte) (*Config, error)

ParseConfig parses a runs-fleet configuration from YAML bytes.

func (*Config) Validate

func (c *Config) Validate() error

Validate checks the configuration for errors.

type DBAPI

type DBAPI interface {
	SavePoolConfig(ctx context.Context, config *db.PoolConfig) error
	GetPoolConfig(ctx context.Context, poolName string) (*db.PoolConfig, error)
}

DBAPI defines database operations for applying configuration.

type GitHubAPI

type GitHubAPI interface {
	GetFileContent(ctx context.Context, owner, repo, path, ref string) ([]byte, error)
}

GitHubAPI defines GitHub operations for fetching configuration.

type GitHubClient

type GitHubClient struct {
	// contains filtered or unexported fields
}

GitHubClient wraps the go-github client for configuration operations.

func NewGitHubClient

func NewGitHubClient(client *github.Client) *GitHubClient

NewGitHubClient creates a new GitHub client for configuration operations.

func (*GitHubClient) GetFileContent

func (c *GitHubClient) GetFileContent(ctx context.Context, owner, repo, path, ref string) ([]byte, error)

GetFileContent fetches file content from a GitHub repository.

type HTTPClientGitHub

type HTTPClientGitHub struct {
	// contains filtered or unexported fields
}

HTTPClientGitHub provides a simple HTTP-based GitHub client for file fetching. This is an alternative when the go-github client is not available.

func NewHTTPClientGitHub

func NewHTTPClientGitHub(token string) *HTTPClientGitHub

NewHTTPClientGitHub creates a new HTTP-based GitHub client.

func (*HTTPClientGitHub) GetFileContent

func (c *HTTPClientGitHub) GetFileContent(ctx context.Context, owner, repo, path, ref string) ([]byte, error)

GetFileContent fetches file content from GitHub using the raw API.

type OwnerInfo

type OwnerInfo struct {
	Login string `json:"login"`
}

OwnerInfo contains owner information from webhook.

type PoolConfig

type PoolConfig struct {
	Name               string         `yaml:"name"`
	InstanceType       string         `yaml:"instance_type"`
	DesiredRunning     int            `yaml:"desired_running"`
	DesiredStopped     int            `yaml:"desired_stopped"`
	IdleTimeoutMinutes int            `yaml:"idle_timeout_minutes,omitempty"`
	Schedules          []PoolSchedule `yaml:"schedules,omitempty"`
	Environment        string         `yaml:"environment,omitempty"`
	Region             string         `yaml:"region,omitempty"`
}

PoolConfig defines a warm pool configuration.

type PoolSchedule

type PoolSchedule struct {
	Name           string `yaml:"name"`
	StartHour      int    `yaml:"start_hour"`   // 0-23
	EndHour        int    `yaml:"end_hour"`     // 0-23
	DaysOfWeek     []int  `yaml:"days_of_week"` // 0=Sunday, 1=Monday, etc.
	DesiredRunning int    `yaml:"desired_running"`
	DesiredStopped int    `yaml:"desired_stopped"`
}

PoolSchedule defines time-based pool sizing.

type PushEvent

type PushEvent struct {
	Ref        string   `json:"ref"`
	Repository RepoInfo `json:"repository"`
	Commits    []Commit `json:"commits"`
}

PushEvent represents a GitHub push webhook event.

func (*PushEvent) GetBranch

func (e *PushEvent) GetBranch() string

GetBranch extracts the branch name from the ref.

func (*PushEvent) GetModifiedFiles

func (e *PushEvent) GetModifiedFiles() []string

GetModifiedFiles returns all files that were added, modified, or removed in the push.

type RepoInfo

type RepoInfo struct {
	Owner    OwnerInfo `json:"owner"`
	Name     string    `json:"name"`
	FullName string    `json:"full_name"`
}

RepoInfo contains repository information from webhook.

type RunnerSpec

type RunnerSpec struct {
	Name         string   `yaml:"name"`          // e.g., "4cpu-linux-arm64"
	InstanceType string   `yaml:"instance_type"` // e.g., "c7g.xlarge"
	Labels       []string `yaml:"labels,omitempty"`
}

RunnerSpec defines a custom runner specification.

type Watcher

type Watcher struct {
	// contains filtered or unexported fields
}

Watcher monitors GitHub repositories for configuration changes.

func NewWatcher

func NewWatcher(gh GitHubAPI, db DBAPI, owner, repo, path string) *Watcher

NewWatcher creates a new configuration watcher.

func (*Watcher) ApplyConfig

func (w *Watcher) ApplyConfig(ctx context.Context, config *Config) error

ApplyConfig applies the configuration to DynamoDB.

func (*Watcher) GetRunnerSpec

func (w *Watcher) GetRunnerSpec(name string) (RunnerSpec, bool)

GetRunnerSpec returns the runner specification for a given name.

func (*Watcher) HandlePushEvent

func (w *Watcher) HandlePushEvent(ctx context.Context, owner, repo, ref string, modifiedFiles []string) error

HandlePushEvent processes a GitHub push event to check for configuration changes.

func (*Watcher) ReloadConfig

func (w *Watcher) ReloadConfig(ctx context.Context, ref string) error

ReloadConfig fetches the configuration from GitHub and applies it.

Jump to

Keyboard shortcuts

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