Skip to content

Commit

Permalink
internal: publicise CompleteBuild function
Browse files Browse the repository at this point in the history
The markBuildComplete private function used to be called from a final
status update to DONE, through the UpdateBuildStatus function.

The problem being that the (now) CompleteBuild function not only updates
the status of the build, but also all its metadata.

For consistency, we remove the indirection, and explicitely call
CompleteBuild when we want to finish a build.
  • Loading branch information
lbajolet-hashicorp committed Jun 22, 2022
1 parent 74e5c53 commit 03f1a12
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
8 changes: 2 additions & 6 deletions internal/registry/types.bucket.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,10 +145,6 @@ func (b *Bucket) CreateInitialBuildForIteration(ctx context.Context, componentTy

// UpdateBuildStatus updates the status of a build entry on the HCP Packer registry with its current local status.
func (b *Bucket) UpdateBuildStatus(ctx context.Context, name string, status models.HashicorpCloudPackerBuildStatus) error {
if status == models.HashicorpCloudPackerBuildStatusDONE {
return b.markBuildComplete(ctx, name)
}

buildToUpdate, err := b.Iteration.Build(name)
if err != nil {
return err
Expand Down Expand Up @@ -176,10 +172,10 @@ func (b *Bucket) UpdateBuildStatus(ctx context.Context, name string, status mode
return nil
}

// markBuildComplete should be called to set a build on the HCP Packer registry to DONE.
// CompleteBuild should be called to set a build on the HCP Packer registry to DONE.
// Upon a successful call markBuildComplete will publish all images created by the named build,
// and set the registry build to done. A build with no images can not be set to DONE.
func (b *Bucket) markBuildComplete(ctx context.Context, name string) error {
func (b *Bucket) CompleteBuild(ctx context.Context, name string) error {
buildToUpdate, err := b.Iteration.Build(name)
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion packer/registry_post_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (p *RegistryPostProcessor) PostProcess(ctx context.Context, ui packersdk.Ui
// This is a bit of a hack for now to denote that this pp should just update the state of a build in the Packer registry.
// TODO create an actual post-processor that we can embed here that will do the updating and printing.
if p.PostProcessor == nil {
if parErr := p.ArtifactMetadataPublisher.UpdateBuildStatus(ctx, p.BuilderType, models.HashicorpCloudPackerBuildStatusDONE); parErr != nil {
if parErr := p.ArtifactMetadataPublisher.CompleteBuild(ctx, p.BuilderType); parErr != nil {
err := fmt.Errorf("[TRACE] failed to update Packer registry with image artifacts for %q: %s", p.BuilderType, parErr)
return nil, false, true, err
}
Expand Down

0 comments on commit 03f1a12

Please sign in to comment.