registry

package
v1.9.1 Latest Latest
Warning

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

Go to latest
Published: Jun 1, 2023 License: MPL-2.0 Imports: 25 Imported by: 0

Documentation

Overview

Package registry provides access to the HCP registry.

Index

Constants

View Source
const BuilderId = "packer.post-processor.hpc-packer-registry"
View Source
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

func IsHCPEnabled(cfg packer.Handler) bool

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

func (b *Bucket) CreateInitialBuildForIteration(ctx context.Context, componentType string) error

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

func (b *Bucket) HeartbeatBuild(ctx context.Context, build string) (func(), error)

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

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

func (b *Bucket) IsExpectingBuildForComponent(buildName string) bool

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 (b *Bucket) RegisterBuildForComponent(sourceName string)

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

func (b *Bucket) UpdateLabelsForBuild(componentType string, data map[string]string) error

UpdateLabelsForBuild merges the contents of data to the labels associated with the build referred to by componentType.

func (*Bucket) Validate

func (b *Bucket) Validate() error

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

func (b *Build) IsNotDone() bool

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

func (b *Build) MergeLabels(data map[string]string)

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

func (h *HCLMetadataRegistry) StartBuild(ctx context.Context, build sdkpacker.Build) error

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

func (i *Iteration) AddLabelsToBuild(buildName string, data map[string]string) error

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

func (i *Iteration) AddSHAToBuildLabels(sha string)

AddSHAToBuildLabels adds the Git SHA for the current iteration (if set) as a label for all the builds of the iteration

func (*Iteration) Build

func (i *Iteration) Build(buildName string) (*Build, error)

Build gets the store build associated with buildName in the active iteration.

func (*Iteration) HasBuild

func (i *Iteration) HasBuild(buildName string) bool

HasBuild checks if iteration has a stored build associated with buildName.

func (*Iteration) Initialize

func (i *Iteration) Initialize() error

Initialize prepares the iteration to be used with an active HCP Packer registry bucket.

func (*Iteration) RemainingBuilds added in v1.9.0

func (i *Iteration) RemainingBuilds() []*Build

RemainingBuilds returns the list of builds that are not in a DONE status

func (*Iteration) StoreBuild

func (i *Iteration) StoreBuild(buildName string, build *Build)

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

func (h *JSONMetadataRegistry) StartBuild(ctx context.Context, build sdkpacker.Build) error

StartBuild is invoked when one build for the configuration is starting to be processed

type ParentIteration

type ParentIteration struct {
	IterationID string
	ChannelID   string
}

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

func New

func New(cfg packer.Handler, ui sdkpacker.Ui) (Registry, hcl.Diagnostics)

New instanciates the appropriate registry for the Packer configuration template type. A nullRegistry is returned for non-HCP Packer registry enabled templates.

Jump to

Keyboard shortcuts

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