From 3c5c61cd2a50bc49dff6174644c01266c96aff5f Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 1 Oct 2021 15:52:26 -0700 Subject: [PATCH] add source image id to build from PARtifact --- internal/registry/types.bucket.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/internal/registry/types.bucket.go b/internal/registry/types.bucket.go index eb6cce66a..27380e2e0 100644 --- a/internal/registry/types.bucket.go +++ b/internal/registry/types.bucket.go @@ -104,7 +104,6 @@ func (b *Bucket) RegisterBuildForComponent(sourceName string) { // 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 (b *Bucket) CreateInitialBuildForIteration(ctx context.Context, componentType string) error { - status := models.HashicorpCloudPackerBuildStatusUNSET buildInput := &models.HashicorpCloudPackerCreateBuildRequest{ BucketSlug: b.Slug, @@ -214,16 +213,23 @@ func (b *Bucket) markBuildComplete(ctx context.Context, name string) error { return fmt.Errorf("setting a build to DONE with no published images is not currently supported.") } - var providerName string + var providerName, sourceID string images := make([]*models.HashicorpCloudPackerImageCreateBody, 0, len(buildToUpdate.Images)) for _, image := range buildToUpdate.Images { + // These values will always be the same for all images in a single build, + // so we can just set it inside the loop without consequence if providerName == "" { providerName = image.ProviderName } + if image.SourceImageID != "" { + sourceID = image.SourceImageID + } + images = append(images, &models.HashicorpCloudPackerImageCreateBody{ImageID: image.ImageID, Region: image.ProviderRegion}) } buildInput.Updates.CloudProvider = providerName + buildInput.Updates.SourceImageID = sourceID buildInput.Updates.Images = images _, err := UpdateBuild(ctx, b.client, buildInput)