build

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package build implements the Builds API (decision 0014): publishing, reading, appending to, renaming, promoting and deleting build-info runs, discarding old ones, and finding the items a run's artifacts are.

Role

artifacts module, core layer: the build-info service. A run is a store record and a document item in its project's build-info repository, and every change writes both through the item service (artifacts/core/item) in one transaction. As artifacts core, it never imports the module's adapters or an ecosystem http package (decision 0044, dependency rule 8).

Inputs

  • Driving: the Builds API handlers, the keyed append's, delete's and promotion's handlers and replay bindings (AppendKeyed, DeleteKeyed, PromoteKeyed and their Confirm functions, which the shared replay in platform/idempotency runs in its transaction), the build searches, and the request limits, which find a build's repository through ProjectKey.
  • Driven: the metadata store, through Store (the item service's store, item.Store, with build runs, their promotions and the keyed actions' reports), the blob store (platform/blob.Store) that holds each run's document, and the item service with the format registry (Formats) and the work queue (Work), so a document item runs its format's hooks as any write does.
  • Build-info documents as the JFrog CLI and the build tools send them (Parse), and the access check the caller passes for what a run may reach (Access).

Outputs

  • Published, appended, renamed, promoted and deleted runs (Published, Append, Promotion and PromotionResult, Delete), a keyed append's run ID and its confirmation (AppendKeyed, ConfirmAppend), a keyed delete's or promotion's report ID and the runs or messages it reported (DeleteKeyed, ConfirmDelete, PromoteKeyed, ConfirmPromote), and runs discarded under a retention setting (RetentionSettings, Discard).
  • Runs, names and numbers read back, and the items a run's artifacts are (Artifacts, SearchArtifacts, Find). NamePages and RunPages walk the names and numbers a page at a time for a list written as it is read, and NoRuns is the error of a build that showed the caller no numbers.
  • The started-time form JFrog writes (StartedLayout, FormatStarted, ParseStarted), LATEST (Latest) and a run's project (ProjectKey).
  • Errors: ErrInvalid, ErrNoTarget and the store's sentinels.

Invariants

  • A run's record and its document item change together or not at all, so the Builds API, the storage API and AQL agree (decision 0014).
  • A document whose module lists one file twice is refused, as 7.x does by default (build.block_duplicate_entries), unless the service allows it.
  • Error texts reach clients and stay byte-identical.
  • A keyed delete's or promotion's report commits with its effect and outlives its receipt, so a replay always finds what the action reported; a dry run or an aborted promotion stores none.

References

Status

Implemented P5 to P9c: the Builds API, promotion and retention in P5, and the idempotent append replay after it. Moved here in P9d. IDEM-01 (#1406) moved the receipt work to the replay keyed operations share (platform/idempotency), leaving the append's effect and reload here. IDEM-02 (#1410) added the keyed delete and promotion, with their reports.

Testing

  • build_test.go, duplicates_test.go and promote_test.go: publishing, reading, appending, renaming, deleting and promoting runs.
  • retention_test.go: discarding runs under a retention setting.
  • replay_test.go: the keyed append's, delete's and promotion's effects and reloads under the shared replay: bound to the run or report they first committed, refused once access is revoked or the run is renamed or deleted, rolled back with their receipt, and pruning expired reports.
  • format_test.go and sidecar_test.go: the document item through the format hooks, and its checksum sidecars.
  • fault_test.go: every store failure surfaces and changes nothing.

Index

Constants

View Source
const Latest = "LATEST"

Latest is the build number that stands for a build's most recently started run.

View Source
const StartedLayout = "2006-01-02T15:04:05.000-0700"

StartedLayout is the layout of started in build-info documents and in the started query parameter: yyyy-MM-dd'T'HH:mm:ss.SSSZ, as the JFrog CLI writes it (research 22 §3.2).

Variables

View Source
var (
	// ErrInvalid is a document or request the API refuses as malformed.
	ErrInvalid = errors.New("build: invalid request")
	// ErrNotFound is a build or run that does not exist.
	ErrNotFound = kernel.ErrNotFound
	// ErrNoRepository is a project whose build-info repository does not
	// exist. Projects are P11, so only the default project's is seeded.
	ErrNoRepository = errors.New("build: the build-info repository does not exist")
	// ErrForbidden is an operation the caller's permissions do not allow.
	ErrForbidden = errors.New("build: permission denied")
	// ErrConflict is a rename to a name that has runs.
	ErrConflict = kernel.ErrConflict
)
View Source
var ErrNoTarget = errors.New("build: the target repository does not exist")

ErrNoTarget is a promotion to a repository that does not exist.

Functions

func FormatStarted

func FormatStarted(t time.Time) string

FormatStarted renders t in StartedLayout, in UTC.

func NoRuns

func NoRuns(name string, seen bool) error

NoRuns is the error of a build whose runs the caller may read none of: ErrNotFound when the walk saw no run at all, ErrForbidden when it saw runs the caller may not read.

func Parse

func Parse(projectKey string, raw []byte) (model.Build, error)

Parse reads a build-info document into the run it publishes for a project. The run keeps raw as its document.

func ParseStarted

func ParseStarted(s string) (time.Time, error)

ParseStarted reads a started timestamp in StartedLayout, or in RFC 3339 as other clients write it.

func ProjectKey

func ProjectKey(p string) string

ProjectKey is the store's key for a project parameter: "" for the default project, which clients may also name "default".

Types

type Access

type Access interface {
	Build(repoKey, path string, folder bool, want api.Actions) bool
	Item(c repo.Config, path string, want api.Actions) bool
}

Access answers what the caller may do. Builds are the build resource of the permission model, matched against the paths of their document items in the build-info repository (decision 0014): a run's document file, or a build name's folder for a listing of names. Deleting a run's artifacts asks about each of their items as an artifact.

type Append

type Append struct {
	ProjectKey, Name, Number string
	// Started selects the run; zero selects the number's latest.
	Started time.Time
	// Modules is the request body: a JSON array of build-info modules.
	Modules []byte
	By      string
}

Append adds modules to a run.

type Delete

type Delete struct {
	ProjectKey, Name string
	// Numbers deletes one run per occurrence of a number.
	Numbers []string
	// All deletes every run, ignoring Numbers.
	All bool
	// Artifacts deletes the items the runs' artifacts are, too.
	Artifacts bool
	By        string
}

Delete selects runs of a build to delete.

type Discard

type Discard struct {
	ProjectKey, Name string
	Retention        model.BuildRetention
	By               string
}

Discard applies retention settings to the runs of a build.

type Promotion

type Promotion struct {
	ProjectKey, Name, Number string
	// Status is recorded with the promotion. Without one no promotion is
	// recorded, as in Artifactory, though files still move and properties
	// are still set.
	Status, Comment string
	// CIUser is the CI server's user; empty records By.
	CIUser string
	// Timestamp is when the promotion was requested; zero records now.
	Timestamp time.Time
	// SourceRepo limits the artifacts, not the dependencies, to one
	// repository, as Artifactory does.
	SourceRepo string
	// TargetRepo receives the files, each at the path it had; empty moves
	// none. A virtual repository stands for its default deployment
	// repository.
	TargetRepo string
	Copy       bool
	// Artifacts and Dependencies select what is promoted; Scopes limits the
	// dependencies to those in any one of them, and none means every scope.
	Artifacts, Dependencies bool
	Scopes                  []string
	// Properties replace the values of their keys on every promoted file:
	// where it landed, or where it is without a target.
	Properties model.Properties
	DryRun     bool
	// FailFast aborts at the first error or warning, changing nothing.
	FailFast bool
	By       string
}

Promotion promotes the latest run of a build number (decision 0014).

type PromotionResult

type PromotionResult struct {
	Messages []item.Message
	// Aborted is a fail-fast promotion that met an error or a warning.
	// Nothing was changed: what it had done was rolled back.
	Aborted bool
}

PromotionResult is a promotion's report, in Artifactory's wording.

type Published

type Published struct {
	Run model.Build
	// SHA256 is the stored document's, which the JFrog CLI reports.
	SHA256 string
	// Discarded are the runs the document's buildRetention discarded.
	Discarded []model.BuildRun
	// Retention is why the document's buildRetention discarded nothing,
	// such as a publisher without delete. The publish stands regardless,
	// as Artifactory's does.
	Retention error
}

Published is what a publish stored.

type RetentionSettings

type RetentionSettings struct {
	Count                        json.Number
	MinimumBuildDate             json.RawMessage
	DeleteBuildArtifacts         bool
	BuildNumbersNotToBeDiscarded []string
}

RetentionSettings are retention settings as clients send them, in a retention request or a build-info document's buildRetention. count may be a number or a numeric string: the JFrog CLI sends a string. Artifactory reads minimumBuildDate as a java.util.Date, which takes epoch milliseconds or a timestamp, so both are accepted.

func (RetentionSettings) Retention

func (r RetentionSettings) Retention(strict bool) (model.BuildRetention, error)

Retention reads the settings. A negative count keeps every run, as an absent one does: build-info's BuildRetention defaults count to -1. A count of 0 keeps every run too unless strict, which refuses it as Artifactory's retention endpoint does ("Max count retention needs to be a positive number").

type Service

type Service struct {
	Store Store
	Blobs blob.Store
	// Now supplies the time; nil means time.Now.
	Now func() time.Time
	// Page bounds the store pages a listing reads; zero means
	// kernel.MaxLimit.
	Page int
	// Formats and Work reach the item service's format hooks (decision
	// 0032); nil means the generic handler and the store's queue.
	Formats format.Registry
	Work    item.Enqueuer
	// AllowDuplicateEntries accepts a document whose module lists one file
	// twice, which the zero value refuses as Artifactory 7.x does by default
	// (build.block_duplicate_entries).
	AllowDuplicateEntries bool
}

Service works on the builds of one store.

func (*Service) Append

func (s *Service) Append(ctx context.Context, ap Append, a Access) error

Append adds modules to the end of a run's modules. It rewrites the run's document and its item, so, like a publish that replaces one, it needs deploy and delete. The added modules are checked for duplicate entries as a publish's are; the run's own are not, as it may have been published while they were allowed.

func (*Service) AppendKeyed

func (s *Service) AppendKeyed(
	ctx context.Context,
	ap Append,
	current func(context.Context) (Access, error),
) (int64, error)

AppendKeyed is a keyed append's effect, which the replay runs inside its transaction (decision 0043, "Optional protected build append"). It locks the run the request selects before anything else, so the receipt binds the append to that run even when a newer run of the same number appears later, appends to it with the access current gives, which the caller evaluates from the credential as it stands now rather than the evaluator cached at login, and returns the run's ID for the receipt. Only metadata mutations and the existing immutable document-blob write run here; no remote work is dispatched from the transaction.

func (*Service) Artifacts

func (s *Service) Artifacts(
	ctx context.Context,
	projectKey, name, number string,
	a Access,
) ([]model.Item, error)

Artifacts returns the items the artifacts of a number's latest run are: the files holding an artifact's checksum that the caller may read. Like the AQL the JFrog CLI otherwise runs, it matches by checksum alone; the CLI ranks the matches by their build properties itself (research 22 §3.1).

func (*Service) ConfirmAppend

func (s *Service) ConfirmAppend(
	ctx context.Context,
	ap Append,
	id int64,
	current func(context.Context) (Access, error),
) error

ConfirmAppend is a keyed append's reload: it locks the run id names, which the receipt holds, and confirms that it is still the run the request addresses and that the credential, as current gives it now, may still append to it. A run deleted since answers ErrNotFound, one renamed or moved ErrConflict, and revoked access ErrForbidden, so that a replay never outlives the access that made it.

func (*Service) ConfirmDelete

func (s *Service) ConfirmDelete(
	ctx context.Context,
	d Delete,
	id int64,
	current func(context.Context) (Access, error),
) ([]model.BuildRun, error)

ConfirmDelete is a keyed delete's reload: it locks the report id names, which the receipt holds, confirms that it is a delete of the build d names, and that the credential, as current gives it now, may still delete each run it lists, and returns those runs. A report of another action or build answers ErrConflict, and revoked access ErrForbidden.

func (*Service) ConfirmPromote

func (s *Service) ConfirmPromote(
	ctx context.Context,
	p Promotion,
	id int64,
	current func(context.Context) (Access, error),
) ([]item.Message, error)

ConfirmPromote is a keyed promotion's reload: it locks the report id names, which the receipt holds, and the run it promoted, confirms that the run is still the build and number p addresses and that the credential, as current gives it now, may still promote it, and returns the promotion's messages. A run deleted since answers ErrNotFound, one renamed ErrConflict, and revoked access ErrForbidden.

func (*Service) Delete

func (s *Service) Delete(ctx context.Context, d Delete, a Access) ([]model.BuildRun, error)

Delete deletes runs of a build: every run with All, otherwise one run per occurrence of a number in Numbers, the earliest-started first, which is what jf rt bp --overwrite expects (research 22 §3.3). Each run's document item goes with it. With Artifacts, so do the items holding an artifact's checksum that carry the run's build.name and build.number properties, as item deletes: to the trash can, and needing delete on each. It returns the deleted runs; ErrNotFound when none was.

func (*Service) DeleteKeyed

func (s *Service) DeleteKeyed(
	ctx context.Context,
	d Delete,
	current func(context.Context) (Access, error),
	retain time.Duration,
) ([]model.BuildRun, int64, error)

DeleteKeyed is a keyed delete's effect, which the replay runs inside its transaction (decision 0043): Delete, with the access current gives now, which also stores the deleted runs as a report kept for retain, in the delete's transaction. A replay answers from that report, since the runs are gone. It returns the deleted runs and the report's ID for the receipt.

func (*Service) Discard

func (s *Service) Discard(ctx context.Context, d Discard, a Access) ([]model.BuildRun, error)

Discard deletes the runs of a build that d does not keep, as a delete of them would (Delete): with their documents, and with their artifacts when d asks. It returns the deleted runs.

func (*Service) Discards

func (s *Service) Discards(ctx context.Context, d Discard, a Access) ([]model.BuildRun, error)

Discards returns the runs d discards, oldest first, having checked that the caller may: it needs delete on the build and on each run discarded. ErrNotFound when the build has no runs.

func (*Service) Find

func (s *Service) Find(
	ctx context.Context,
	projectKey, name, number, status string,
	a Access,
) (model.Build, error)

Find returns the most recently started run of a build number, or of the build when number is Latest, whose latest promotion has status when status is not empty, skipping runs the caller may not read. ErrNotFound when no run qualifies, ErrForbidden when the caller may read none that does.

func (*Service) NamePages

func (s *Service) NamePages(
	projectKey string,
	a Access,
) (*kernel.Pages[model.BuildName], func(model.BuildName) bool)

NamePages walks the build names of a project a store page at a time, in the store's name order. keep is the caller's filter: a name is listed when the caller may read a run of the build.

func (*Service) Names

func (s *Service) Names(
	ctx context.Context,
	projectKey string,
	a Access,
) ([]model.BuildName, error)

Names lists the build names of a project in which the caller may read a run, ordered by name, as NamePages walks and keeps them.

func (*Service) Promote

func (s *Service) Promote(ctx context.Context, p Promotion, a Access) (PromotionResult, error)

Promote moves or copies the files of the latest run of a number to a target repository, sets properties on them and records the promotion, as one transaction. It needs deploy on the build. Each file needs what a copy or move of it needs, and one that lacks it is reported, not refused, as Artifactory reports it. ErrNotFound when there is no such run, ErrNoTarget when the target does not exist.

func (*Service) PromoteKeyed

func (s *Service) PromoteKeyed(
	ctx context.Context,
	p Promotion,
	current func(context.Context) (Access, error),
	retain time.Duration,
) (PromotionResult, int64, error)

PromoteKeyed is a keyed promotion's effect, which the replay runs inside its transaction (decision 0043): Promote, with the access current gives now, which also stores the promotion's messages as a report kept for retain, in the promotion's transaction. The report's ID, for the receipt, is zero for a dry run or an aborted promotion, which changed nothing and so leaves nothing to replay.

func (*Service) Publish

func (s *Service) Publish(
	ctx context.Context,
	projectKey string,
	doc []byte,
	by string,
	a Access,
) (Published, error)

Publish stores the run a build-info document publishes, and the document as its item. Publishing needs deploy. A run with the same identity (project, name, number and started) is replaced, which, like overwriting an existing document item, needs delete as well. A buildRetention in the document is kept as the build name's retention and applied once the run is stored, as the publisher (decision 0014). A module that lists one file twice is ErrInvalid unless AllowDuplicateEntries.

func (*Service) Rename

func (s *Service) Rename(ctx context.Context, projectKey, from, to, by string, a Access) error

Rename moves every run of a build to another name, with its document, whose name field changes too. It needs deploy and delete on the runs, and deploy where they land.

func (*Service) Run

func (s *Service) Run(
	ctx context.Context,
	projectKey, name, number string,
	started time.Time,
	a Access,
) (model.Build, error)

Run returns a run of a build number: the one started at started, or the latest-started when started is zero.

func (*Service) RunPages

func (s *Service) RunPages(
	projectKey, name string,
	a Access,
) (*kernel.Pages[model.BuildRun], func(model.BuildRun) bool)

RunPages walks the runs of a build a store page at a time, newest first. keep is the caller's filter: a run is listed when the caller may read its document. A walk that keeps nothing answers NoRuns.

func (*Service) Runs

func (s *Service) Runs(
	ctx context.Context,
	projectKey, name string,
	a Access,
) ([]model.BuildRun, error)

Runs lists the runs of a build the caller may read, newest first, as RunPages walks and keeps them. ErrNotFound when the build has no runs, ErrForbidden when the caller may read none (NoRuns).

func (*Service) SearchArtifacts

func (s *Service) SearchArtifacts(
	ctx context.Context,
	b model.Build,
	in func(model.Item) bool,
	a Access,
) ([]model.Item, error)

SearchArtifacts returns the items run b's artifacts are that the caller may read, in module and artifact order, found as a promotion finds them: of the items that in passes (nil passes all), hold an artifact's checksum and carry the run's build properties, the one with its name, else the first. Artifacts, which the JFrog CLI ranks itself, matches by checksum alone.

type Store

type Store interface {
	item.Store
	Builds() port.BuildStore
}

Store is what the build service reads and writes: the item service's store, through which build-info documents and promotions write items (item.Store), with the build records (decision 0014). Every call joins the transaction ctx carries, a keyed append's replay transaction included. Each composite store in app is a Store.

Jump to

Keyboard shortcuts

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