Documentation
¶
Index ¶
- Constants
- Variables
- func GetGitFingerprint(opts IterationOptions) (string, error)
- type Bucket
- func (b *Bucket) CreateInitialBuildForIteration(ctx context.Context, componentType string) error
- func (b *Bucket) Initialize(ctx context.Context) error
- func (b *Bucket) IsExpectingBuildForComponent(buildName string) bool
- func (b *Bucket) LoadDefaultSettingsFromEnv()
- func (b *Bucket) PopulateIteration(ctx context.Context) error
- 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 Client
- func (client *Client) CreateBucket(ctx context.Context, bucketSlug, bucketDescription string, ...) (*packer_service.PackerServiceCreateBucketOK, error)
- func (client *Client) CreateBuild(ctx context.Context, ...) (*packer_service.PackerServiceCreateBuildOK, error)
- func (client *Client) CreateIteration(ctx context.Context, bucketSlug, fingerprint string) (*packer_service.PackerServiceCreateIterationOK, error)
- func (client *Client) DeleteBucket(ctx context.Context, bucketSlug string) (*packer_service.PackerServiceDeleteBucketOK, error)
- func (client *Client) GetIteration(ctx context.Context, bucketSlug string, opts ...GetIterationOption) (*models.HashicorpCloudPackerIteration, error)
- func (client *Client) GetIterationFromChannel(ctx context.Context, bucketSlug string, channelName string) (*models.HashicorpCloudPackerIteration, error)
- func (client *Client) ListBuilds(ctx context.Context, bucketSlug string, iterationID string) ([]*models.HashicorpCloudPackerBuild, error)
- func (client *Client) UpdateBuild(ctx context.Context, buildID, runUUID, cloudProvider, sourceImageID string, ...) (string, error)
- func (client *Client) UpsertBucket(ctx context.Context, bucketSlug, bucketDescription string, ...) error
- type ClientError
- type GetIterationOption
- type Iteration
- type IterationOptions
- type MockPackerClientService
- func (svc *MockPackerClientService) PackerServiceCreateBucket(params *packerSvc.PackerServiceCreateBucketParams, ...) (*packerSvc.PackerServiceCreateBucketOK, error)
- func (svc *MockPackerClientService) PackerServiceCreateBuild(params *packerSvc.PackerServiceCreateBuildParams, ...) (*packerSvc.PackerServiceCreateBuildOK, error)
- func (svc *MockPackerClientService) PackerServiceCreateIteration(params *packerSvc.PackerServiceCreateIterationParams, ...) (*packerSvc.PackerServiceCreateIterationOK, error)
- func (svc *MockPackerClientService) PackerServiceGetIteration(params *packerSvc.PackerServiceGetIterationParams, ...) (*packerSvc.PackerServiceGetIterationOK, error)
- func (svc *MockPackerClientService) PackerServiceListBuilds(params *packerSvc.PackerServiceListBuildsParams, ...) (*packerSvc.PackerServiceListBuildsOK, error)
- func (svc *MockPackerClientService) PackerServiceUpdateBucket(params *packerSvc.PackerServiceUpdateBucketParams, ...) (*packerSvc.PackerServiceUpdateBucketOK, error)
- func (svc *MockPackerClientService) PackerServiceUpdateBuild(params *packerSvc.PackerServiceUpdateBuildParams, ...) (*packerSvc.PackerServiceUpdateBuildOK, error)
Constants ¶
const (
InvalidClientConfig
)
Variables ¶
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 ¶
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 ¶
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) PopulateIteration ¶ added in v1.7.7
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 (*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 ¶
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.
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 ¶
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 ¶
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.
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 (svc *MockPackerClientService) PackerServiceCreateBucket(params *packerSvc.PackerServiceCreateBucketParams, _ runtime.ClientAuthInfoWriter) (*packerSvc.PackerServiceCreateBucketOK, error)
func (*MockPackerClientService) PackerServiceCreateBuild ¶ added in v1.7.7
func (svc *MockPackerClientService) PackerServiceCreateBuild(params *packerSvc.PackerServiceCreateBuildParams, _ runtime.ClientAuthInfoWriter) (*packerSvc.PackerServiceCreateBuildOK, error)
func (*MockPackerClientService) PackerServiceCreateIteration ¶ added in v1.7.7
func (svc *MockPackerClientService) PackerServiceCreateIteration(params *packerSvc.PackerServiceCreateIterationParams, _ runtime.ClientAuthInfoWriter) (*packerSvc.PackerServiceCreateIterationOK, error)
func (*MockPackerClientService) PackerServiceGetIteration ¶ added in v1.7.7
func (svc *MockPackerClientService) PackerServiceGetIteration(params *packerSvc.PackerServiceGetIterationParams, _ runtime.ClientAuthInfoWriter) (*packerSvc.PackerServiceGetIterationOK, error)
func (*MockPackerClientService) PackerServiceListBuilds ¶ added in v1.7.7
func (svc *MockPackerClientService) PackerServiceListBuilds(params *packerSvc.PackerServiceListBuildsParams, _ runtime.ClientAuthInfoWriter) (*packerSvc.PackerServiceListBuildsOK, error)
func (*MockPackerClientService) PackerServiceUpdateBucket ¶ added in v1.7.7
func (svc *MockPackerClientService) PackerServiceUpdateBucket(params *packerSvc.PackerServiceUpdateBucketParams, _ runtime.ClientAuthInfoWriter) (*packerSvc.PackerServiceUpdateBucketOK, error)
func (*MockPackerClientService) PackerServiceUpdateBuild ¶ added in v1.7.7
func (svc *MockPackerClientService) PackerServiceUpdateBuild(params *packerSvc.PackerServiceUpdateBuildParams, _ runtime.ClientAuthInfoWriter) (*packerSvc.PackerServiceUpdateBuildOK, error)