registry

package
v1.8.0 Latest Latest
Warning

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

Go to latest
Published: Mar 4, 2022 License: MPL-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InvalidClientConfig
)

Variables

View Source
var (
	GetIteration_byID = func(id string) GetIterationOption {
		return func(params *packer_service.PackerServiceGetIterationParams) {
			params.IterationID = &id
		}
	}
	GetIteration_byFingerprint = func(fingerprint string) GetIterationOption {
		return func(params *packer_service.PackerServiceGetIterationParams) {
			params.Fingerprint = &fingerprint
		}
	}
)

Functions

func GetGitFingerprint

func GetGitFingerprint(opts IterationOptions) (string, error)

GetGitFingerprint returns the HEAD commit for some template dir defined in opt.TemplateBaseDir. If the base directory is not under version control an error is returned.

Types

type Bucket

type Bucket struct {
	Slug         string
	Description  string
	Destination  string
	BucketLabels map[string]string
	BuildLabels  map[string]string
	Iteration    *Iteration
	// contains filtered or unexported fields
}

Bucket represents a single Image bucket on the HCP Packer registry.

func NewBucketWithIteration

func NewBucketWithIteration(opts IterationOptions) (*Bucket, error)

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) Initialize

func (b *Bucket) Initialize(ctx context.Context) 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

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) PopulateIteration added in v1.7.7

func (b *Bucket) PopulateIteration(ctx context.Context) error

PopulateIteration populates the bucket iteration with the details needed for tracking builds for a Packer run. If an existing Packer registry iteration exists for the said iteration fingerprint, calling initialize on iteration that doesn't yet exist will call createIteration to create the entry on the HCP packer registry for the given bucket. All build details will be created (if they don't exists) and added to b.Iteration.builds for tracking during runtime.

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.

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 added in v1.8.0

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 added in v1.8.0

func (b *Build) AddImages(images ...registryimage.Image) error

AddImages appends one or more images artifacts to the build.

func (*Build) IsNotDone added in v1.8.0

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 added in v1.8.0

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 Client

type Client struct {
	Packer       packerSvc.ClientService
	Organization organizationSvc.ClientService
	Project      projectSvc.ClientService

	// OrganizationID  is the organization unique identifier on HCP.
	OrganizationID string

	// ProjectID  is the project unique identifier on HCP.
	ProjectID string
}

Client is an HCP client capable of making requests on behalf of a service principal

func NewClient

func NewClient() (*Client, error)

NewClient returns an authenticated client to a HCP Packer Registry. Client authentication requires the following environment variables be set HCP_CLIENT_ID and HCP_CLIENT_SECRET. Upon error a HCPClientError will be returned.

func (*Client) CreateBucket added in v1.7.9

func (client *Client) CreateBucket(
	ctx context.Context,
	bucketSlug,
	bucketDescription string,
	bucketLabels map[string]string,
) (*packer_service.PackerServiceCreateBucketOK, error)

func (*Client) CreateBuild added in v1.7.9

func (client *Client) CreateBuild(
	ctx context.Context,
	bucketSlug,
	runUUID,
	iterationID,
	fingerprint,
	componentType string,
	status models.HashicorpCloudPackerBuildStatus,
) (*packer_service.PackerServiceCreateBuildOK, error)

func (*Client) CreateIteration added in v1.7.9

func (client *Client) CreateIteration(
	ctx context.Context,
	bucketSlug,
	fingerprint string,
) (*packer_service.PackerServiceCreateIterationOK, error)

func (*Client) DeleteBucket added in v1.7.9

func (client *Client) DeleteBucket(
	ctx context.Context,
	bucketSlug string,
) (*packer_service.PackerServiceDeleteBucketOK, error)

func (*Client) GetIteration added in v1.7.9

func (client *Client) GetIteration(ctx context.Context, bucketSlug string, opts ...GetIterationOption) (*models.HashicorpCloudPackerIteration, error)

func (*Client) GetIterationFromChannel added in v1.7.9

func (client *Client) GetIterationFromChannel(
	ctx context.Context,
	bucketSlug string,
	channelName string,
) (*models.HashicorpCloudPackerIteration, error)

GetIterationFromChannel loads the iterationId associated with a current channel. If the channel does not exist in HCP Packer, GetChannel returns an error.

func (*Client) ListBuilds added in v1.7.9

func (client *Client) ListBuilds(
	ctx context.Context,
	bucketSlug string,
	iterationID string,
) ([]*models.HashicorpCloudPackerBuild, error)

ListBuilds queries an Iteration on HCP Packer registry for all of it's associated builds. Currently all builds are returned regardless of status.

func (*Client) UpdateBuild added in v1.7.9

func (client *Client) UpdateBuild(
	ctx context.Context,
	buildID,
	runUUID,
	cloudProvider,
	sourceImageID string,
	labels map[string]string,
	status models.HashicorpCloudPackerBuildStatus,
	images []*models.HashicorpCloudPackerImageCreateBody,
) (string, error)

UpdateBuild updates a single iteration build entry with the incoming input data.

func (*Client) UpsertBucket added in v1.7.9

func (client *Client) UpsertBucket(
	ctx context.Context,
	bucketSlug,
	bucketDescription string,
	bucketLabels map[string]string,
) error

UpsertBucket tries to create a bucket on a HCP Packer Registry. If the bucket exists it will handle the error and update the bucket with the provided details.

type ClientError

type ClientError struct {
	StatusCode uint
	Err        error
}

ClientError represents a generic error for the Cloud Packer Service client.

func (*ClientError) Error

func (c *ClientError) Error() string

Error returns the string message for some ClientError.

type GetIterationOption added in v1.7.9

type GetIterationOption func(*packer_service.PackerServiceGetIterationParams)

type Iteration

type Iteration struct {
	ID           string
	AncestorSlug string
	Fingerprint  string
	RunUUID      string
	Labels       map[string]string
	// contains filtered or unexported fields
}

func NewIteration

func NewIteration(opts IterationOptions) (*Iteration, error)

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) Build added in v1.8.0

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

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

func (*Iteration) HasBuild added in v1.8.0

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

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

func (*Iteration) StoreBuild added in v1.8.0

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 MockPackerClientService

type MockPackerClientService struct {
	CreateBucketCalled, UpdateBucketCalled, BucketAlreadyExist                           bool
	CreateIterationCalled, GetIterationCalled, IterationAlreadyExist, IterationCompleted bool
	CreateBuildCalled, UpdateBuildCalled, ListBuildsCalled, BuildAlreadyDone             bool
	TrackCalledServiceMethods                                                            bool

	// Mock Creates
	CreateBucketResp    *models.HashicorpCloudPackerCreateBucketResponse
	CreateIterationResp *models.HashicorpCloudPackerCreateIterationResponse
	CreateBuildResp     *models.HashicorpCloudPackerCreateBuildResponse

	// Mock Gets
	GetIterationResp *models.HashicorpCloudPackerGetIterationResponse

	ExistingBuilds      []string
	ExistingBuildLabels map[string]string

	packerSvc.ClientService
}

MockPackerClientService represents a basic mock of the Cloud Packer Service. Upon calling a service method a boolean is set to true to indicate that a method has been called. To skip the setting of these booleans set TrackCalledServiceMethods to false; defaults to true in NewMockPackerClientService().

func NewMockPackerClientService

func NewMockPackerClientService() *MockPackerClientService

NewMockPackerClientService returns a basic mock of the Cloud Packer Service. Upon calling a service method a boolean is set to true to indicate that a method has been called. To skip the setting of these booleans set TrackCalledServiceMethods to false. By default it is true.

func (*MockPackerClientService) PackerServiceCreateBucket added in v1.7.7

func (*MockPackerClientService) PackerServiceCreateBuild added in v1.7.7

func (*MockPackerClientService) PackerServiceCreateIteration added in v1.7.7

func (*MockPackerClientService) PackerServiceGetIteration added in v1.7.7

func (*MockPackerClientService) PackerServiceListBuilds added in v1.7.7

func (*MockPackerClientService) PackerServiceUpdateBucket added in v1.7.7

func (*MockPackerClientService) PackerServiceUpdateBuild added in v1.7.7

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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