Documentation
¶
Overview ¶
Package build implements the Builds API (decision 0014): publishing, reading, appending to, renaming and deleting build-info runs, and finding the items a run's artifacts are. A run is a store record and a document item in its project's build-info repository. Every change writes both in one transaction, so the Builds API, the storage API and AQL agree.
Index ¶
- Constants
- Variables
- func FormatStarted(t time.Time) string
- func Parse(projectKey string, raw []byte) (types.Build, error)
- func ParseStarted(s string) (time.Time, error)
- func ProjectKey(p string) string
- type Access
- type Append
- type Delete
- type Discard
- type Promotion
- type PromotionResult
- type Published
- type RetentionSettings
- type Service
- func (s *Service) Append(ctx context.Context, ap Append, a Access) error
- func (s *Service) AppendOnce(ctx context.Context, ap Append, r store.ReplayRequest, ...) (store.ReplayReceipt, error)
- func (s *Service) Artifacts(ctx context.Context, projectKey, name, number string, a Access) ([]types.Item, error)
- func (s *Service) Delete(ctx context.Context, d Delete, a Access) ([]types.BuildRun, error)
- func (s *Service) Discard(ctx context.Context, d Discard, a Access) ([]types.BuildRun, error)
- func (s *Service) Discards(ctx context.Context, d Discard, a Access) ([]types.BuildRun, error)
- func (s *Service) Find(ctx context.Context, projectKey, name, number, status string, a Access) (types.Build, error)
- func (s *Service) Names(ctx context.Context, projectKey string, a Access) ([]types.BuildName, error)
- func (s *Service) Promote(ctx context.Context, p Promotion, a Access) (PromotionResult, error)
- func (s *Service) Publish(ctx context.Context, projectKey string, doc []byte, by string, a Access) (Published, error)
- func (s *Service) Rename(ctx context.Context, projectKey, from, to, by string, a Access) error
- func (s *Service) Run(ctx context.Context, projectKey, name, number string, started time.Time, ...) (types.Build, error)
- func (s *Service) Runs(ctx context.Context, projectKey, name string, a Access) ([]types.BuildRun, error)
- func (s *Service) SearchArtifacts(ctx context.Context, b types.Build, in func(types.Item) bool, a Access) ([]types.Item, error)
Constants ¶
const Latest = "LATEST"
Latest is the build number that stands for a build's most recently started run.
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 ¶
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 = store.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 = store.ErrConflict )
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 ¶
FormatStarted renders t in StartedLayout, in UTC.
func Parse ¶
Parse reads a build-info document into the run it publishes for a project. The run keeps raw as its document.
func ParseStarted ¶
ParseStarted reads a started timestamp in StartedLayout, or in RFC 3339 as other clients write it.
func ProjectKey ¶
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 types.Actions) bool
Item(c repo.Config, path string, want types.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 types.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 types.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 types.Build
// SHA256 is the stored document's, which the JFrog CLI reports.
SHA256 string
// Discarded are the runs the document's buildRetention discarded.
Discarded []types.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) (types.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.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
// store.MaxLimit.
Page int
// Formats and Work reach the item service's format hooks (decision
// 0032); nil means formats.For and the store's queue.
Formats func(repo.PackageType) format.Handler
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 ¶
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) AppendOnce ¶
func (s *Service) AppendOnce( ctx context.Context, ap Append, r store.ReplayRequest, current func(context.Context) (Access, error), ) (store.ReplayReceipt, error)
AppendOnce commits the append and its receipt together. A replay stays bound to the original run even when a newer run of the same number exists. The caller supplies current authorization, not the evaluator cached at login. 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, ) ([]types.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) Delete ¶
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) Discard ¶
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 ¶
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, ) (types.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) Names ¶
func (s *Service) Names( ctx context.Context, projectKey string, a Access, ) ([]types.BuildName, error)
Names lists the build names of a project in which the caller may read a run, ordered by name.
func (*Service) Promote ¶
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) 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 ¶
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, ) (types.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) Runs ¶
func (s *Service) Runs( ctx context.Context, projectKey, name string, a Access, ) ([]types.BuildRun, error)
Runs lists the runs of a build the caller may read, newest first. ErrNotFound when the build has no runs, ErrForbidden when the caller may read none.
func (*Service) SearchArtifacts ¶
func (s *Service) SearchArtifacts( ctx context.Context, b types.Build, in func(types.Item) bool, a Access, ) ([]types.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.