registry

package
v1.7.8 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2021 License: MPL-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InvalidClientConfig
)

Variables

This section is empty.

Functions

func CreateBucket

func CreateBucket(ctx context.Context, client *Client, input *models.HashicorpCloudPackerCreateBucketRequest) (string, error)

CreateBucket creates a bucket on a HCP Packer Registry.

func CreateBuild

func CreateBuild(ctx context.Context, client *Client, input *models.HashicorpCloudPackerCreateBuildRequest) (string, error)

CreateBuild create a build entry to track for the IterationID and BucketSlug defined within input.

func CreateIteration

CreateIteration creates an Iteration for some Bucket on a HCP Packer Registry.

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.

func GetIteration

func GetIteration(ctx context.Context, client *Client, bucketslug string, fingerprint string) (*models.HashicorpCloudPackerIteration, error)

GetIteration queries the HCP Packer registry for an existing bucket iteration.

func GetIterationFromChannel

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

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

func GetIterationFromId

func GetIterationFromId(ctx context.Context, client *Client, bucketslug string, iterationId string) (*models.HashicorpCloudPackerIteration, error)

GetIteration queries the HCP Packer registry for an existing bucket iteration.

func ListBuilds

func ListBuilds(ctx context.Context, client *Client, 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 UpdateBuild

func UpdateBuild(ctx context.Context, client *Client, input *models.HashicorpCloudPackerUpdateBuildRequest) (string, error)

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

func UpsertBucket

func UpsertBucket(ctx context.Context, client *Client, input *models.HashicorpCloudPackerCreateBucketRequest) 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.

Types

type Bucket

type Bucket struct {
	Slug        string
	Description string
	Destination string
	Labels      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.

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.

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 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.

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

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

	// Mock Gets
	GetIterationResp *models.HashicorpCloudPackerGetIterationResponse

	ExistingBuilds []string

	packerSvc.ClientService
}

func NewMockPackerClientService

func NewMockPackerClientService() *MockPackerClientService

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