Skip to content

Commit

Permalink
hcp: replace packersdk.Build by *CoreBuild
Browse files Browse the repository at this point in the history
As the rest of the build process was updated to remove references to the
Build interface exposed by the SDK, we change the usage of such types in
the hcp internal package, so they are typed with *CoreBuild too.
  • Loading branch information
lbajolet-hashicorp authored and mogrogan committed Feb 13, 2025
1 parent 98198b5 commit 62befd7
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 25 deletions.
21 changes: 5 additions & 16 deletions internal/hcp/registry/hcl.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,30 +65,19 @@ func (h *HCLRegistry) PopulateVersion(ctx context.Context) error {
}

// StartBuild is invoked when one build for the configuration is starting to be processed
func (h *HCLRegistry) StartBuild(ctx context.Context, build sdkpacker.Build) error {
name := build.Name()
cb, ok := build.(*packer.CoreBuild)
if ok {
name = cb.Type
}

return h.bucket.startBuild(ctx, name)
func (h *HCLRegistry) StartBuild(ctx context.Context, build *packer.CoreBuild) error {
return h.bucket.startBuild(ctx, build.Type)
}

// CompleteBuild is invoked when one build for the configuration has finished
func (h *HCLRegistry) CompleteBuild(
ctx context.Context,
build sdkpacker.Build,
build *packer.CoreBuild,
artifacts []sdkpacker.Artifact,
buildErr error,
) ([]sdkpacker.Artifact, error) {
buildName := build.Name()
cb, ok := build.(*packer.CoreBuild)
if ok {
buildName = cb.Type
}

buildMetadata, envMetadata := cb.GetMetadata(), h.metadata
buildName := build.Type
buildMetadata, envMetadata := build.GetMetadata(), h.metadata
err := h.bucket.Version.AddMetadataToBuild(ctx, buildName, buildMetadata, envMetadata)
if err != nil {
return nil, err
Expand Down
9 changes: 4 additions & 5 deletions internal/hcp/registry/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,19 @@ func (h *JSONRegistry) PopulateVersion(ctx context.Context) error {
}

// StartBuild is invoked when one build for the configuration is starting to be processed
func (h *JSONRegistry) StartBuild(ctx context.Context, build sdkpacker.Build) error {
name := build.Name()
return h.bucket.startBuild(ctx, name)
func (h *JSONRegistry) StartBuild(ctx context.Context, build *packer.CoreBuild) error {
return h.bucket.startBuild(ctx, build.Name())
}

// CompleteBuild is invoked when one build for the configuration has finished
func (h *JSONRegistry) CompleteBuild(
ctx context.Context,
build sdkpacker.Build,
build *packer.CoreBuild,
artifacts []sdkpacker.Artifact,
buildErr error,
) ([]sdkpacker.Artifact, error) {
buildName := build.Name()
buildMetadata, envMetadata := build.(*packer.CoreBuild).GetMetadata(), h.metadata
buildMetadata, envMetadata := build.GetMetadata(), h.metadata
err := h.bucket.Version.AddMetadataToBuild(ctx, buildName, buildMetadata, envMetadata)
if err != nil {
return nil, err
Expand Down
5 changes: 3 additions & 2 deletions internal/hcp/registry/null_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"

sdkpacker "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer/packer"
)

// nullRegistry is a special handler that does nothing
Expand All @@ -16,13 +17,13 @@ func (r nullRegistry) PopulateVersion(context.Context) error {
return nil
}

func (r nullRegistry) StartBuild(context.Context, sdkpacker.Build) error {
func (r nullRegistry) StartBuild(context.Context, *packer.CoreBuild) error {
return nil
}

func (r nullRegistry) CompleteBuild(
ctx context.Context,
build sdkpacker.Build,
build *packer.CoreBuild,
artifacts []sdkpacker.Artifact,
buildErr error,
) ([]sdkpacker.Artifact, error) {
Expand Down
4 changes: 2 additions & 2 deletions internal/hcp/registry/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
// Registry is an entity capable to orchestrate a Packer build and upload metadata to HCP
type Registry interface {
PopulateVersion(context.Context) error
StartBuild(context.Context, sdkpacker.Build) error
CompleteBuild(ctx context.Context, build sdkpacker.Build, artifacts []sdkpacker.Artifact, buildErr error) ([]sdkpacker.Artifact, error)
StartBuild(context.Context, *packer.CoreBuild) error
CompleteBuild(ctx context.Context, build *packer.CoreBuild, artifacts []sdkpacker.Artifact, buildErr error) ([]sdkpacker.Artifact, error)
VersionStatusSummary()
Metadata() Metadata
}
Expand Down

0 comments on commit 62befd7

Please sign in to comment.