artifact

package
v0.16.3 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

View Source
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.

View Source
var ErrTarballTooLarge = errors.New("artifact: tarball too large")

ErrTarballTooLarge means a repository tarball exceeded the cap Put was given; nothing was stored.

Functions

func Ref added in v0.16.3

func Ref(repoURL, sha string) string

Ref is the source ref a tarball is shared under: the repository URL and the commit SHA it was archived at.

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.

func (*Client) Put added in v0.9.3

func (c *Client) Put(ctx context.Context, digest string, r io.Reader, size int64) error

Put streams the tarball to the cache under its digest. The server verifies the digest; a mismatch surfaces as ErrDigestMismatch, an oversize upload as ErrBlobTooLarge.

func (*Client) Stat added in v0.9.3

func (c *Client) Stat(ctx context.Context, digest string) (bool, error)

Stat reports whether the blob is cached.

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

func NewStore(dir, baseURL string) (*Store, error)

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

func (s *Store) Adopt(key, ref string) (*Info, bool)

Adopt points the owner key at the tarball already stored for ref, without fetching anything, and reports whether there was one.

func (*Store) Delete

func (s *Store) Delete(key string)

Delete lets go of the owner key's tarball, if any; the file goes with its last owner.

func (*Store) Get

func (s *Store) Get(key string) (*Info, bool)

Get returns the stored artifact info for the owner key, if present.

func (*Store) Handler

func (s *Store) Handler() http.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

func (s *Store) InternalHandler(token string, maxBytes int64) http.Handler

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

func (s *Store) Put(key, ref string, r io.Reader, maxBytes int64) (*Info, error)

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

func (s *Store) PutBlob(digest string, r io.Reader, maxBytes int64) (bool, error)

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.

func (*Store) StatBlob added in v0.9.3

func (s *Store) StatBlob(digest string) (int64, bool)

StatBlob reports whether the digest is cached and its size. A hit counts as an access: anything that checks a blob (submission validation, the dedupe HEAD) is keeping it alive.

func (*Store) SweepBlobs added in v0.9.3

func (s *Store) SweepBlobs(before time.Time) int

SweepBlobs removes every blob last accessed before the cutoff and returns how many were removed. A swept-but-needed blob resurfaces as a WorkspaceLost unit failure, prompting the client to re-upload.

Jump to

Keyboard shortcuts

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