Documentation ¶
Overview ¶
Package registry provides access to the HCP registry.
Index ¶
- Constants
- func IsHCPEnabled(cfg packer.Handler) bool
- type Bucket
- func (b *Bucket) CreateInitialBuildForIteration(ctx context.Context, componentType string) error
- func (b *Bucket) HeartbeatBuild(ctx context.Context, build string) (func(), error)
- func (b *Bucket) Initialize(ctx context.Context, ...) error
- func (b *Bucket) IsExpectingBuildForComponent(buildName string) bool
- func (b *Bucket) LoadDefaultSettingsFromEnv()
- func (b *Bucket) ReadFromHCLBuildBlock(build *hcl2template.BuildBlock)
- func (b *Bucket) RegisterBuildForComponent(sourceName string)
- func (b *Bucket) UpdateBuildStatus(ctx context.Context, name string, ...) error
- func (b *Bucket) UpdateImageForBuild(componentType string, images ...registryimage.Image) error
- func (b *Bucket) UpdateLabelsForBuild(componentType string, data map[string]string) error
- func (b *Bucket) Validate() error
- type Build
- type ErrBuildAlreadyDone
- type HCLMetadataRegistry
- func (h *HCLMetadataRegistry) CompleteBuild(ctx context.Context, build sdkpacker.Build, artifacts []sdkpacker.Artifact, ...) ([]sdkpacker.Artifact, error)
- func (h *HCLMetadataRegistry) IterationStatusSummary()
- func (h *HCLMetadataRegistry) PopulateIteration(ctx context.Context) error
- func (h *HCLMetadataRegistry) StartBuild(ctx context.Context, build sdkpacker.Build) error
- type HCPConfigMode
- type Iteration
- func (i *Iteration) AddImageToBuild(buildName string, images ...registryimage.Image) error
- func (i *Iteration) AddLabelsToBuild(buildName string, data map[string]string) error
- func (i *Iteration) AddSHAToBuildLabels(sha string)
- func (i *Iteration) Build(buildName string) (*Build, error)
- func (i *Iteration) HasBuild(buildName string) bool
- func (i *Iteration) Initialize() error
- func (i *Iteration) RemainingBuilds() []*Build
- func (i *Iteration) StoreBuild(buildName string, build *Build)
- type IterationOptions
- type JSONMetadataRegistry
- func (h *JSONMetadataRegistry) CompleteBuild(ctx context.Context, build sdkpacker.Build, artifacts []sdkpacker.Artifact, ...) ([]sdkpacker.Artifact, error)
- func (h *JSONMetadataRegistry) IterationStatusSummary()
- func (h *JSONMetadataRegistry) PopulateIteration(ctx context.Context) error
- func (h *JSONMetadataRegistry) StartBuild(ctx context.Context, build sdkpacker.Build) error
- type ParentIteration
- type Registry
Constants ¶
const BuilderId = "packer.post-processor.hpc-packer-registry"
const HeartbeatPeriod = 2 * time.Minute
HeartbeatPeriod dictates how often a heartbeat is sent to HCP to signal a build is still alive.
Variables ¶
This section is empty.
Functions ¶
func IsHCPEnabled ¶
IsHCPEnabled returns true if HCP integration is enabled for a build
Types ¶
type Bucket ¶
type Bucket struct { Slug string Description string Destination string BucketLabels map[string]string BuildLabels map[string]string SourceImagesToParentIterations map[string]ParentIteration RunningBuilds map[string]chan struct{} Iteration *Iteration // contains filtered or unexported fields }
Bucket represents a single Image bucket on the HCP Packer registry.
func NewBucketWithIteration ¶
func NewBucketWithIteration() *Bucket
NewBucketWithIteration initializes a simple Bucket that can be used publishing Packer build images to the HCP Packer registry.
func (*Bucket) CreateInitialBuildForIteration ¶
CreateInitialBuildForIteration will create a build entry on the HCP Packer Registry for the named componentType. This initial creation is needed so that Packer can properly track when an iteration is complete.
func (*Bucket) HeartbeatBuild ¶
HeartbeatBuild periodically sends status updates for the build
This lets HCP infer that a build is still running and should not be marked as cancelled by the HCP Packer registry service.
Usage: defer (b.HeartbeatBuild(ctx, build, period))()
func (*Bucket) Initialize ¶
func (b *Bucket) Initialize(ctx context.Context, templateType models.HashicorpCloudPackerIterationTemplateType) error
Initialize registers the Bucket b with the configured HCP Packer Registry. Upon initialization a Bucket will be upserted to, and new iteration will be created for the build if the configured fingerprint has no associated iterations. Lastly, the initialization process with register the builds that need to be completed before an iteration can be marked as DONE.
b.Initialize() must be called before any data can be published to the configured HCP Packer Registry. TODO ensure initialize can only be called once
func (*Bucket) IsExpectingBuildForComponent ¶
IsExpectingBuildForComponent returns true if the component referenced by buildName is part of the iteration and is not marked as DONE on the HCP Packer registry.
func (*Bucket) LoadDefaultSettingsFromEnv ¶
func (b *Bucket) LoadDefaultSettingsFromEnv()
Load defaults from environment variables
func (*Bucket) ReadFromHCLBuildBlock ¶
func (b *Bucket) ReadFromHCLBuildBlock(build *hcl2template.BuildBlock)
ReadFromHCLBuildBlock reads the information for initialising a Bucket from a HCL2 build block
func (*Bucket) RegisterBuildForComponent ¶
func (*Bucket) UpdateBuildStatus ¶
func (b *Bucket) UpdateBuildStatus(ctx context.Context, name string, status models.HashicorpCloudPackerBuildStatus) error
UpdateBuildStatus updates the status of a build entry on the HCP Packer registry with its current local status. For updating a build status to DONE use CompleteBuild.
func (*Bucket) UpdateImageForBuild ¶
func (b *Bucket) UpdateImageForBuild(componentType string, images ...registryimage.Image) error
UpdateImageForBuild appends one or more images artifacts to the build referred to by componentType.
func (*Bucket) UpdateLabelsForBuild ¶
UpdateLabelsForBuild merges the contents of data to the labels associated with the build referred to by componentType.
type Build ¶
type Build struct { ID string CloudProvider string ComponentType string RunUUID string Labels map[string]string Images map[string]registryimage.Image Status models.HashicorpCloudPackerBuildStatus }
Build represents a build of a given component type for some bucket on the HCP Packer Registry.
func NewBuildFromCloudPackerBuild ¶
func NewBuildFromCloudPackerBuild(src *models.HashicorpCloudPackerBuild) (*Build, error)
NewBuildFromCloudPackerBuild converts a HashicorpCloudePackerBuild to a local build that can be tracked and published to the HCP Packer Registry. Any existing labels or images associated to src will be copied to the returned Build.
func (*Build) AddImages ¶
func (b *Build) AddImages(images ...registryimage.Image) error
AddImages appends one or more images artifacts to the build.
func (*Build) IsNotDone ¶
IsNotDone returns true if build does not satisfy all requirements of a completed build. A completed build must have a valid ID, one or more Images, and its Status is HashicorpCloudPackerBuildStatusDONE.
func (*Build) MergeLabels ¶
AddLabelsToBuild merges the contents of data to the labels associated with the build. Duplicate keys will be updated to reflect the new value.
type ErrBuildAlreadyDone ¶
type ErrBuildAlreadyDone struct {
Message string
}
ErrBuildAlreadyDone is the error returned by an HCP handler when a build cannot be started since it's already marked as DONE.
func (ErrBuildAlreadyDone) Error ¶
func (b ErrBuildAlreadyDone) Error() string
Error returns the message for the ErrBuildAlreadyDone type
type HCLMetadataRegistry ¶
type HCLMetadataRegistry struct {
// contains filtered or unexported fields
}
HCLMetadataRegistry is a HCP handler made for handling HCL configurations
func NewHCLMetadataRegistry ¶
func NewHCLMetadataRegistry(config *hcl2template.PackerConfig, ui sdkpacker.Ui) (*HCLMetadataRegistry, hcl.Diagnostics)
func (*HCLMetadataRegistry) CompleteBuild ¶
func (h *HCLMetadataRegistry) CompleteBuild( ctx context.Context, build sdkpacker.Build, artifacts []sdkpacker.Artifact, buildErr error, ) ([]sdkpacker.Artifact, error)
CompleteBuild is invoked when one build for the configuration has finished
func (*HCLMetadataRegistry) IterationStatusSummary ¶ added in v1.9.0
func (h *HCLMetadataRegistry) IterationStatusSummary()
IterationStatusSummary prints a status report in the UI if the iteration is not yet done
func (*HCLMetadataRegistry) PopulateIteration ¶
func (h *HCLMetadataRegistry) PopulateIteration(ctx context.Context) error
PopulateIteration creates the metadata on HCP for a build
func (*HCLMetadataRegistry) StartBuild ¶
StartBuild is invoked when one build for the configuration is starting to be processed
type HCPConfigMode ¶
type HCPConfigMode int
HCPConfigMode types specify the mode in which HCP configuration is defined for a given Packer build execution.
const ( // HCPConfigUnset mode is set when no HCP configuration has been found for the Packer execution. HCPConfigUnset HCPConfigMode = iota // HCPConfigEnabled mode is set when the HCP configuration is codified in the template. HCPConfigEnabled // HCPEnvEnabled mode is set when the HCP configuration is read from environment variables. HCPEnvEnabled )
type Iteration ¶
type Iteration struct { ID string AncestorSlug string Fingerprint string RunUUID string // contains filtered or unexported fields }
func NewIteration ¶
func NewIteration() *Iteration
NewIteration returns a pointer to an Iteration that can be used for storing Packer build details needed by PAR.
func (*Iteration) AddImageToBuild ¶
func (i *Iteration) AddImageToBuild(buildName string, images ...registryimage.Image) error
AddImageToBuild appends one or more images artifacts to the build referred to by buildName.
func (*Iteration) AddLabelsToBuild ¶
AddLabelsToBuild merges the contents of data to the labels associated with the build referred to by buildName.
func (*Iteration) AddSHAToBuildLabels ¶ added in v1.9.0
AddSHAToBuildLabels adds the Git SHA for the current iteration (if set) as a label for all the builds of the iteration
func (*Iteration) Build ¶
Build gets the store build associated with buildName in the active iteration.
func (*Iteration) HasBuild ¶
HasBuild checks if iteration has a stored build associated with buildName.
func (*Iteration) Initialize ¶
Initialize prepares the iteration to be used with an active HCP Packer registry bucket.
func (*Iteration) RemainingBuilds ¶ added in v1.9.0
RemainingBuilds returns the list of builds that are not in a DONE status
func (*Iteration) StoreBuild ¶
StoreBuild stores a build for buildName to an active iteration.
type IterationOptions ¶
type IterationOptions struct {
TemplateBaseDir string
}
type JSONMetadataRegistry ¶
type JSONMetadataRegistry struct {
// contains filtered or unexported fields
}
JSONMetadataRegistry is a HCP handler made to process legacy JSON templates
func NewJSONMetadataRegistry ¶
func NewJSONMetadataRegistry(config *packer.Core, ui sdkpacker.Ui) (*JSONMetadataRegistry, hcl.Diagnostics)
func (*JSONMetadataRegistry) CompleteBuild ¶
func (h *JSONMetadataRegistry) CompleteBuild( ctx context.Context, build sdkpacker.Build, artifacts []sdkpacker.Artifact, buildErr error, ) ([]sdkpacker.Artifact, error)
CompleteBuild is invoked when one build for the configuration has finished
func (*JSONMetadataRegistry) IterationStatusSummary ¶ added in v1.9.0
func (h *JSONMetadataRegistry) IterationStatusSummary()
IterationStatusSummary prints a status report in the UI if the iteration is not yet done
func (*JSONMetadataRegistry) PopulateIteration ¶
func (h *JSONMetadataRegistry) PopulateIteration(ctx context.Context) error
PopulateIteration creates the metadata on HCP for a build
func (*JSONMetadataRegistry) StartBuild ¶
StartBuild is invoked when one build for the configuration is starting to be processed
type ParentIteration ¶
type Registry ¶
type Registry interface { PopulateIteration(context.Context) error StartBuild(context.Context, sdkpacker.Build) error CompleteBuild(ctx context.Context, build sdkpacker.Build, artifacts []sdkpacker.Artifact, buildErr error) ([]sdkpacker.Artifact, error) IterationStatusSummary() }
Registry is an entity capable to orchestrate a Packer build and upload metadata to HCP