Documentation
¶
Overview ¶
Package mirror keeps a one-way mirror from motte to external git remotes.
Index ¶
- Constants
- Variables
- func GitRef(stored string) (string, bool)
- func MaybeAskpass(args []string, stdout io.Writer) bool
- func Mirrorable(stored string) bool
- func StoredRef(git string) (string, bool)
- type Class
- type Clock
- type Config
- type Engine
- func (e *Engine) Deliver(ctx context.Context, body []byte, signature string) error
- func (e *Engine) Mirror(name string) (Entry, bool)
- func (e *Engine) Mirrors() []Entry
- func (e *Engine) Refs(ctx context.Context, name, after string, limit int) ([]Ref, error)
- func (e *Engine) Registry() *prometheus.Registry
- func (e *Engine) RequestReconcile(name string) bool
- func (e *Engine) RequestReset()
- func (e *Engine) Run(ctx context.Context) error
- func (e *Engine) SeedState(name string) (state, message string)
- func (e *Engine) Stats(ctx context.Context) ([]Stats, error)
- type Entry
- type GitHubApp
- type Hit
- type HookResult
- type MotteConfig
- type Options
- type Ref
- type SeedRef
- type Service
- type Stats
- type Store
Constants ¶
const ( // DefaultDiskBudget is the default size of the clone cache. DefaultDiskBudget = 20 << 30 // DefaultIdleTTL is the default idle time of a clone. DefaultIdleTTL = 168 * time.Hour )
const ( // StateSeeding and StateSeedRefused are the mirror states that a seed reports. StateSeeding = "seeding" StateSeedRefused = "seed_refused" // DefaultSeedMaxObjects and DefaultSeedMaxBytes are the size of one seed push. Both are below the limits of a push to motte. DefaultSeedMaxObjects = 50000 DefaultSeedMaxBytes = 32 << 20 // DefaultSeedMaxInflated bounds the whole size of the objects of one seed push, as motte bounds its inflated data. DefaultSeedMaxInflated = 32 << 20 )
const DefaultGitHubAPI = forgeapp.DefaultAPI
DefaultGitHubAPI is the API base URL of the GitHub App credential when the configuration names none.
Variables ¶
var ( // ErrSignature is the error of a delivery that the secret does not sign. ErrSignature = errors.New("mirror: bad signature") // ErrBody is the error of a signed delivery that is not an event. ErrBody = errors.New("mirror: bad event body") )
Functions ¶
func GitRef ¶
GitRef maps a stored ref name to the git ref name. A stored name under refs/heads/ has none.
func MaybeAskpass ¶
MaybeAskpass runs the askpass helper when the environment asks for it. It returns false for a normal start. git runs the program of GIT_ASKPASS with the prompt as its only argument, and the program is the ward binary.
func Mirrorable ¶ added in v0.2.1
Mirrorable reports whether a stored ref name is a branch (a bare name) or a tag (under refs/tags/). ward never touches any other name on the remote.
Types ¶
type Clock ¶
Clock is the source of time and of waits. Inside a synctest bubble the real clock is a fake one.
type Config ¶
type Config struct {
DataDir string
Motte MotteConfig
PublicURL string
HookSecret []byte
Mirrors []Entry
// GitHubAPI is the API base URL for the GitHub App credential. Empty means DefaultGitHubAPI.
GitHubAPI string
DiskBudget int64
IdleTTL time.Duration
// SeedMaxObjects and SeedMaxBytes bound one push of a seed. Zero means the default.
SeedMaxObjects int
SeedMaxBytes int64
// SeedMaxInflated bounds the sum of the object sizes of one push of a seed.
SeedMaxInflated int64
// Askpass is the program that git runs for the remote credential. It is the ward binary.
Askpass string
}
Config is the configuration of the engine.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine runs the mirror.
func (*Engine) Deliver ¶
Deliver handles one delivery of a ref event. It answers before any git work: it only records state.
func (*Engine) Registry ¶
func (e *Engine) Registry() *prometheus.Registry
Registry is the Prometheus registry of the engine.
func (*Engine) RequestReconcile ¶
RequestReconcile asks the worker of a mirror for a Reconcile. It returns at once.
func (*Engine) RequestReset ¶
func (e *Engine) RequestReset()
RequestReset asks for a Reset. It returns at once.
func (*Engine) Run ¶
Run drives the engine until ctx ends. A failed step of the control work retries with the backoff of a failed action.
type Entry ¶
type Entry struct {
Name string `json:"name"`
Repo string `json:"repo"`
Remote string `json:"remote"`
Refs []string `json:"refs"`
Username string `json:"username"`
CredentialFile string `json:"credential_file,omitempty"`
GitHubApp *GitHubApp `json:"github_app,omitempty"`
PruneUnknown bool `json:"prune_unknown"`
Seed bool `json:"seed"`
}
Entry is one mirror of the configuration.
func ParseEntries ¶
ParseEntries decodes and checks the WARD_MIRRORS list. It rejects an unknown field.
type GitHubApp ¶
type GitHubApp struct {
AppID int64 `json:"app_id"`
InstallationID int64 `json:"installation_id"`
KeyFile string `json:"key_file"`
}
GitHubApp is a GitHub App installation that supplies the remote credential.
type HookResult ¶
type HookResult int
HookResult is how the sequence of a delivered event compares with the partition state.
const ( HookBaseline HookResult = iota HookInOrder HookRepeat HookGap )
type MotteConfig ¶
type MotteConfig struct {
URL string
Kid string
Key ed25519.PrivateKey
}
MotteConfig says how ward reaches motte and signs its grants.
type Options ¶
type Options struct {
Clock Clock
Logger *slog.Logger
// Remote talks to the git remotes of the mirrors. Nil means the git binary.
Remote gitremote.Remote
// Done is called after a unit of work ends: kind is batch, reconcile, catchup, reset, init, seed or seed_refused, and mirror is empty
// for work that belongs to no mirror. It must not block.
Done func(kind, mirror string)
}
Options are the parts that a caller may replace.
type Ref ¶
type Ref struct {
Mirror string
Name string
LastPartition int
LastSeq int64
Dirty bool
Version int64
DirtySince time.Time
Pushed string
PushedSet bool
Attempts int
NextAttempt time.Time
Failure Class
Message string
FailureSince time.Time
PushedAt time.Time
}
Ref is the state of one ref of one mirror. PushedSet is false while ward knows nothing about the remote value.
type SeedRef ¶ added in v0.2.0
type SeedRef struct{ Commit, Next string }
SeedRef is the motte value that a seed expects for a ref. Commit is the last value that ward wrote or found (empty for absence). Next is the value of a push that may or may not have landed (empty when none is under way).
type Stats ¶
type Stats struct {
Mirror string
Reconciled bool
Dirty int
Failing map[Class]int
OldestDirty time.Time
}
Stats summarises the refs of one mirror.
type Store ¶
type Store interface {
Ping(ctx context.Context) error
Service(ctx context.Context) (Service, error)
// SetSubscription stores the subscription and the events cursor. With clearSeq it also clears last_seq of every partition.
SetSubscription(ctx context.Context, id, cursor string, clearSeq bool) error
// RecordHook compares the sequence of the event with its partition, stores last_seq and the triggers, and says how.
RecordHook(ctx context.Context, hit Hit, now time.Time) (HookResult, error)
// RecordPage stores the triggers of a catch-up page, last_seq where it is higher, and the new cursor.
RecordPage(ctx context.Context, hits []Hit, cursor string, now time.Time) error
// Due returns the dirty refs of a mirror that may be acted on now, and the earliest later next_attempt (zero if none).
Due(ctx context.Context, mirror string, now time.Time) ([]Ref, time.Time, error)
// RecordPush stores a push result. It clears dirty only when the version of the ref is still version.
RecordPush(ctx context.Context, mirror, ref string, version int64, pushed string, now time.Time) error
// RecordFailure counts a failed action. It moves next_attempt only when the version of the ref is still version.
RecordFailure(ctx context.Context, mirror, ref string, version int64, class Class, message string, next, now time.Time) error
SetPushed(ctx context.Context, mirror, ref, pushed string) error
// Reconciled triggers each ref of targets, sets its pushed value, and records the mirror.
Reconciled(ctx context.Context, mirror string, targets map[string]string, now time.Time) error
// Seed returns the seed record of a mirror: empty, started or done.
Seed(ctx context.Context, mirror string) (string, error)
SetSeed(ctx context.Context, mirror, state string) error
// SeedRefs returns what a seed expects motte to hold for each ref it has written or may write.
SeedRefs(ctx context.Context, mirror string) (map[string]SeedRef, error)
SetSeedRef(ctx context.Context, mirror, ref string, r SeedRef) error
// SeedCleaned reports whether the cleanup of the seed record has run.
SeedCleaned(ctx context.Context, mirror string) (bool, error)
// FinishSeedCleanup removes refs from the seed record and from the ref state of the mirror, and records the cleanup.
FinishSeedCleanup(ctx context.Context, mirror string, refs []string) error
HasMirror(ctx context.Context, name string) (bool, error)
StateRefs(ctx context.Context, mirror string) ([]string, error)
Refs(ctx context.Context, mirror, after string, limit int) ([]Ref, error)
Stats(ctx context.Context) ([]Stats, error)
}
Store is the transactional state store. Each method that writes is one transaction.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package mirrortest is the conformance suite of mirror.Store.
|
Package mirrortest is the conformance suite of mirror.Store. |