Documentation
¶
Overview ¶
Package actionscache is the host-side cache of action archives (plan CI-4, D8). The host downloads the tarball of an action once per (repository, resolved commit) and every job, in any sandbox, is served the same bytes through the cache channel (see cachesvc): the forge is hit once, not once per job (codeload answered 429 during the CI-3 compare).
An entry is keyed by Key: a hash of the forge, the repository and the resolved commit sha. A mutable ref (a tag, a branch) is never part of it, so a moved tag cannot serve stale bytes: the server resolves the ref to a sha at each job.
The bytes come from the host's own download, never from a sandbox: the guest runs untrusted code and must not be able to plant an archive that other jobs would run. Each entry is two files in Dir, <key>.tgz and <key>.sum (the sha256 and the size of the archive). The sum is written after the archive, so an archive without one is a crash leftover and is removed at start. Every read re-hashes the archive; a mismatch drops the entry and the caller downloads it again.
The total size is capped; the least recently used entries go first. An entry handed out is pinned for a while (PinFor), so that it cannot be evicted between the host fetching it and the sandbox reading it.
Index ¶
Constants ¶
const ( // DefaultMax is the size cap when ERMITE_RUNNER_ACTIONS_CACHE_MAX is unset. DefaultMax = 2 << 30 // EnvMax is ERMITE_RUNNER_ACTIONS_CACHE_MAX: a size (2G, 500M…); 0 turns the // cache off. EnvMax = "ERMITE_RUNNER_ACTIONS_CACHE_MAX" // PinFor is how long a served entry is protected from eviction. PinFor = 30 * time.Minute )
Defaults and names.
Variables ¶
var ErrNotFound = errors.New("actionscache: no such entry")
ErrNotFound is an entry that is absent, corrupt or evicted.
var ErrTooLarge = errors.New("actionscache: archive larger than the cache")
ErrTooLarge is an archive that does not fit under the cap on its own.
Functions ¶
func Key ¶
Key is the entry key of an archive: the sha256 of the forge origin, the repository and the resolved commit. ok is false when sha is not a full git object name (40 or 64 hex digits): such an archive is not cached, whatever the ref said.
func NewClient ¶
NewClient returns the client that downloads the archives. It follows redirects (GitHub's codeload does redirect) but never carries credentials across an origin: the Authorization header is dropped as soon as the scheme, the host or the port changes, and a redirect from https to http is refused. (net/http alone would keep the header for subdomains and ignore the scheme and the port.) Tests may supply their own transport through Actions.HTTPClient; its redirect policy is replaced.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is the archive cache.
func (*Cache) Ensure ¶
Ensure makes sure the entry of key exists and is intact, calling fetch to download it when it does not (a miss: hit is false). Concurrent calls for the same key share one download; the others report a hit once it is in place. The entry is pinned for PinFor.