Documentation
¶
Overview ¶
Package artifact stores and serves the SHA-pinned repository tarballs that source-controller produces and agent jobs fetch. Paths embed a 128-bit random id, so a URL is unguessable by other workloads that can reach the serving port; the fetching init container verifies the sha256 digest end-to-end. The store is plain files with an in-memory index.
A repository tarball is stored once per source ref (the repository URL and commit SHA) and shared by every owner (Repository object) pinned to that ref: findings on the same repository at the same head cost one download. The file is removed when its last owner lets go. Tarballs are reproducible (a restart re-fetches them), so their index is not persisted. Content-addressed workspace blobs (blob.go) are not reproducible, so their index is rebuilt from disk at startup.
Index ¶
- Variables
- func Ref(repoURL, sha string) string
- type Client
- type Info
- type Store
- func (s *Store) Adopt(key, ref string) (*Info, bool)
- func (s *Store) Delete(key string)
- func (s *Store) Get(key string) (*Info, bool)
- func (s *Store) Handler() http.Handler
- func (s *Store) InternalHandler(token string, maxBytes int64) http.Handler
- func (s *Store) Put(key, ref string, r io.Reader, maxBytes int64) (*Info, error)
- func (s *Store) PutBlob(digest string, r io.Reader, maxBytes int64) (bool, error)
- func (s *Store) StatBlob(digest string) (int64, bool)
- func (s *Store) SweepBlobs(before time.Time) int
Constants ¶
This section is empty.
Variables ¶
var ( // ErrDigestMismatch means the uploaded bytes do not hash to the digest // they were uploaded under. ErrDigestMismatch = errors.New("artifact: digest mismatch") // ErrBlobTooLarge means the upload exceeded the configured cap. ErrBlobTooLarge = errors.New("artifact: blob too large") )
Blob errors the upload API maps onto HTTP statuses.
var ErrTarballTooLarge = errors.New("artifact: tarball too large")
ErrTarballTooLarge means a repository tarball exceeded the cap Put was given; nothing was stored.
Functions ¶
Types ¶
type Client ¶ added in v0.9.3
type Client struct {
// BaseURL of the internal endpoint, e.g.
// http://patchy-source-controller.patchy.svc.cluster.local:9791.
BaseURL string
// Token is the optional shared bearer token.
Token string
// HTTPClient defaults to http.DefaultClient.
HTTPClient *http.Client
}
Client talks to the store's internal blob endpoint (PUT|HEAD /internal/blobs/{digest}) from another process, such as evaluation-controller checking a workspace before launch or streaming an upload through to the cache.
type Info ¶
type Info struct {
// URL the artifact is served at.
URL string
// Digest is the hex sha256 of the tarball.
Digest string
// Size in bytes.
Size int64
// FetchedAt is when the tarball was stored, by whichever owner fetched
// it first.
FetchedAt time.Time
}
Info describes one stored artifact.
type Store ¶
type Store struct {
// contains filtered or unexported fields
}
Store keeps artifacts on disk and serves them over HTTP. Repository tarballs are addressed by owner key (the Repository object's namespaced name) and shared by source ref.
func NewStore ¶
NewStore builds a Store rooted at dir, minting URLs under baseURL (the cluster-internal address agents reach, e.g. http://patchy-source-controller.patchy.svc:9790).
func (*Store) Adopt ¶ added in v0.16.3
Adopt points the owner key at the tarball already stored for ref, without fetching anything, and reports whether there was one.
func (*Store) Delete ¶
Delete lets go of the owner key's tarball, if any; the file goes with its last owner.
func (*Store) Handler ¶
Handler serves GET /artifacts/<id>.tar.gz: 32-hex ids are repository tarballs, 64-hex ids are content-addressed workspace blobs.
func (*Store) InternalHandler ¶ added in v0.9.3
InternalHandler serves the NetworkPolicy-gated upload endpoint evaluation-controller streams workspace bundles to:
HEAD /internal/blobs/{digest} → 204 cached / 404
PUT /internal/blobs/{digest} → 201 created / 200 already cached /
422 digest mismatch / 413 too large
A non-empty token requires Authorization: Bearer <token> (constant-time compared) as defense-in-depth atop the NetworkPolicy; maxBytes caps uploads (0 = unbounded).
func (*Store) Put ¶
Put stores the tarball read from r under ref for the owner key, replacing whatever the key held before, and returns its serving info. maxBytes caps the tarball (0 means unbounded): a larger one is discarded with ErrTarballTooLarge. If another owner stored the same ref meanwhile, the key joins that copy and the new bytes are discarded.
func (*Store) PutBlob ¶ added in v0.9.3
PutBlob stores the tarball read from r under its sha256 digest, idempotently: a digest already present is not re-read. The stream is hashed while writing and discarded on mismatch (ErrDigestMismatch) or when it exceeds maxBytes (ErrBlobTooLarge; 0 means unbounded). It reports whether the blob was newly created.