Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add artifact support for HCP Packer registry #190

Merged
merged 2 commits into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions builder/vultr/artifact.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"log"

registryimage "github.com/hashicorp/packer-plugin-sdk/packer/registry/image"

"github.com/vultr/govultr/v2"
)

Expand All @@ -15,8 +17,14 @@ type Artifact struct {
// The Description of the snapshot
Description string

// The client for making
// The client for making changes
client *govultr.Client

// config definition from the builder
config *Config

// State data used by HCP container registry
StateData map[string]interface{}
}

func (a *Artifact) BuilderId() string {
Expand All @@ -36,7 +44,20 @@ func (a *Artifact) String() string {
}

func (a *Artifact) State(name string) interface{} {
return nil
if name == registryimage.ArtifactStateURI {
img, err := registryimage.FromArtifact(a,
registryimage.WithID(a.SnapshotID),
registryimage.WithProvider("Vultr"),
registryimage.WithRegion(a.config.RegionID),
)

if err != nil {
log.Printf("[DEBUG] error encountered when creating a registry image %v", err)
return nil
}
return img
}
return a.StateData[name]
}

func (a *Artifact) Destroy() error {
Expand Down
4 changes: 2 additions & 2 deletions builder/vultr/artifact_test.go
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func TestArtifact_Impl(t *testing.T) {
}

func TestArtifactId(t *testing.T) {
a := &Artifact{"d455d0246e8e6", "packer-test", nil}
a := &Artifact{"d455d0246e8e6", "packer-test", nil, nil, nil}
expected := "d455d0246e8e6"

if a.Id() != expected {
Expand All @@ -24,7 +24,7 @@ func TestArtifactId(t *testing.T) {
}

func TestArtifactString(t *testing.T) {
a := &Artifact{"d455d0246e8e6", "packer-test", nil}
a := &Artifact{"d455d0246e8e6", "packer-test", nil, nil, nil}
expected := "Vultr Snapshot: packer-test (d455d0246e8e6)"

if a.String() != expected {
Expand Down
1 change: 1 addition & 0 deletions builder/vultr/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ func (b *Builder) Run(ctx context.Context, ui packer.Ui, hook packer.Hook) (ret
artifact := &Artifact{
SnapshotID: snapshot.ID,
Description: snapshot.Description,
config: &b.config,
client: client,
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ github.com/hashicorp/packer-plugin-sdk/multistep
github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps
github.com/hashicorp/packer-plugin-sdk/net
github.com/hashicorp/packer-plugin-sdk/packer
github.com/hashicorp/packer-plugin-sdk/packer/registry/image
github.com/hashicorp/packer-plugin-sdk/packerbuilderdata
github.com/hashicorp/packer-plugin-sdk/pathing
github.com/hashicorp/packer-plugin-sdk/plugin
Expand Down