Unverified Commit b10df3ab authored by Wilken Rivera's avatar Wilken Rivera Committed by GitHub
Browse files

Update HCP Packer registry image extraction, validation, publishing logic for...

Update HCP Packer registry image extraction, validation, publishing logic for registry capable plugins (#11221)

* Update handling of registry artifacts

This change uses the github.com/hashicorp/packer-plgin-sdk/packer/registryimage for querying
Artifact State for HCP Registry Image metadata. To handle the conversion
of the RPC response, mapstructure was introduced to conversion state
data into an registryimage.Image before publishing to a image bucket.

* Update to use registry image from packersdk

* Rename internal registry service pkg

* Update vendored plugins to latest version

* The latest release of Amazon, GoogleCompute, and Azure have support
  for publishing images to the HCP Packer registry.
Showing with 224 additions and 42 deletions
+224 -42
...@@ -4,6 +4,9 @@ import ( ...@@ -4,6 +4,9 @@ import (
"fmt" "fmt"
"log" "log"
"os" "os"
"path"
registryimage "github.com/hashicorp/packer-plugin-sdk/packer/registry/image"
) )
type FileArtifact struct { type FileArtifact struct {
...@@ -27,12 +30,18 @@ func (a *FileArtifact) String() string { ...@@ -27,12 +30,18 @@ func (a *FileArtifact) String() string {
} }
func (a *FileArtifact) State(name string) interface{} { func (a *FileArtifact) State(name string) interface{} {
if name == "par.artifact.metadata" { if name == registryimage.ArtifactStateURI {
metadata := make(map[string]string) img, err := registryimage.FromArtifact(a,
metadata["ImageID"] = a.filename registryimage.WithID(path.Base(a.filename)),
metadata["ProviderName"] = a.Id() registryimage.WithRegion(path.Dir(a.filename)),
)
return metadata
if err != nil {
log.Printf("[DEBUG] error encountered when creating a registry image %v", err)
return nil
}
return img
} }
return nil return nil
......
...@@ -2,7 +2,7 @@ package command ...@@ -2,7 +2,7 @@ package command
import ( import (
"github.com/hashicorp/hcl/v2" "github.com/hashicorp/hcl/v2"
packerregistry "github.com/hashicorp/packer/internal/packer_registry" packerregistry "github.com/hashicorp/packer/internal/registry"
"github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer"
plugingetter "github.com/hashicorp/packer/packer/plugin-getter" plugingetter "github.com/hashicorp/packer/packer/plugin-getter"
) )
......
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
"github.com/hashicorp/packer-plugin-sdk/hcl2helper" "github.com/hashicorp/packer-plugin-sdk/hcl2helper"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer" packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/template/config" "github.com/hashicorp/packer-plugin-sdk/template/config"
packerregistry "github.com/hashicorp/packer/internal/packer_registry" packerregistry "github.com/hashicorp/packer/internal/registry"
) )
type Datasource struct { type Datasource struct {
......
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
"github.com/hashicorp/packer-plugin-sdk/hcl2helper" "github.com/hashicorp/packer-plugin-sdk/hcl2helper"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer" packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/template/config" "github.com/hashicorp/packer-plugin-sdk/template/config"
packerregistry "github.com/hashicorp/packer/internal/packer_registry" packerregistry "github.com/hashicorp/packer/internal/registry"
) )
type Datasource struct { type Datasource struct {
......
...@@ -15,7 +15,7 @@ import ( ...@@ -15,7 +15,7 @@ import (
"github.com/hashicorp/packer-plugin-sdk/hcl2helper" "github.com/hashicorp/packer-plugin-sdk/hcl2helper"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer" packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/template/config" "github.com/hashicorp/packer-plugin-sdk/template/config"
packerregistry "github.com/hashicorp/packer/internal/packer_registry" packerregistry "github.com/hashicorp/packer/internal/registry"
) )
type Datasource struct { type Datasource struct {
......
module github.com/hashicorp/packer module github.com/hashicorp/packer
require ( require (
cloud.google.com/go/storage v1.16.1 // indirect cloud.google.com/go v0.94.1 // indirect
github.com/Azure/azure-sdk-for-go v57.0.0+incompatible // indirect github.com/Azure/azure-sdk-for-go v57.1.0+incompatible // indirect
github.com/Azure/go-autorest/autorest v0.11.20 // indirect github.com/Azure/go-autorest/autorest v0.11.20 // indirect
github.com/Azure/go-autorest/autorest/adal v0.9.15 // indirect github.com/Azure/go-autorest/autorest/adal v0.9.15 // indirect
github.com/Azure/go-autorest/autorest/azure/auth v0.5.8 // indirect github.com/Azure/go-autorest/autorest/azure/auth v0.5.8 // indirect
github.com/Azure/go-autorest/autorest/azure/cli v0.4.3 // indirect github.com/Azure/go-autorest/autorest/azure/cli v0.4.3 // indirect
github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c // indirect
github.com/StackExchange/wmi v1.2.1 // indirect github.com/StackExchange/wmi v1.2.1 // indirect
github.com/Telmate/proxmox-api-go v0.0.0-20210825163308-5e4c0d698a78 // indirect github.com/Telmate/proxmox-api-go v0.0.0-20210825163308-5e4c0d698a78 // indirect
github.com/aliyun/alibaba-cloud-sdk-go v1.61.1244 // indirect github.com/aliyun/alibaba-cloud-sdk-go v1.61.1244 // indirect
...@@ -37,15 +36,15 @@ require ( ...@@ -37,15 +36,15 @@ require (
github.com/hashicorp/hcl/v2 v2.10.1 github.com/hashicorp/hcl/v2 v2.10.1
github.com/hashicorp/hcp-sdk-go v0.10.1-0.20210727200019-239ce8d80646 github.com/hashicorp/hcp-sdk-go v0.10.1-0.20210727200019-239ce8d80646
github.com/hashicorp/packer-plugin-alicloud v1.0.0 github.com/hashicorp/packer-plugin-alicloud v1.0.0
github.com/hashicorp/packer-plugin-amazon v1.0.1-dev github.com/hashicorp/packer-plugin-amazon v1.0.1
github.com/hashicorp/packer-plugin-ansible v1.0.0 github.com/hashicorp/packer-plugin-ansible v1.0.0
github.com/hashicorp/packer-plugin-azure v1.0.2 github.com/hashicorp/packer-plugin-azure v1.0.3
github.com/hashicorp/packer-plugin-chef v1.0.1 github.com/hashicorp/packer-plugin-chef v1.0.1
github.com/hashicorp/packer-plugin-cloudstack v1.0.0 github.com/hashicorp/packer-plugin-cloudstack v1.0.0
github.com/hashicorp/packer-plugin-converge v1.0.0 github.com/hashicorp/packer-plugin-converge v1.0.0
github.com/hashicorp/packer-plugin-digitalocean v1.0.1 github.com/hashicorp/packer-plugin-digitalocean v1.0.1
github.com/hashicorp/packer-plugin-docker v1.0.1 github.com/hashicorp/packer-plugin-docker v1.0.1
github.com/hashicorp/packer-plugin-googlecompute v1.0.4 github.com/hashicorp/packer-plugin-googlecompute v1.0.5
github.com/hashicorp/packer-plugin-hcloud v1.0.1 github.com/hashicorp/packer-plugin-hcloud v1.0.1
github.com/hashicorp/packer-plugin-hyperone v1.0.0 github.com/hashicorp/packer-plugin-hyperone v1.0.0
github.com/hashicorp/packer-plugin-hyperv v1.0.0 github.com/hashicorp/packer-plugin-hyperv v1.0.0
...@@ -66,7 +65,7 @@ require ( ...@@ -66,7 +65,7 @@ require (
github.com/hashicorp/packer-plugin-qemu v1.0.0 github.com/hashicorp/packer-plugin-qemu v1.0.0
github.com/hashicorp/packer-plugin-salt v0.0.8 github.com/hashicorp/packer-plugin-salt v0.0.8
github.com/hashicorp/packer-plugin-scaleway v1.0.3 github.com/hashicorp/packer-plugin-scaleway v1.0.3
github.com/hashicorp/packer-plugin-sdk v0.2.4 github.com/hashicorp/packer-plugin-sdk v0.2.5
github.com/hashicorp/packer-plugin-tencentcloud v1.0.1 github.com/hashicorp/packer-plugin-tencentcloud v1.0.1
github.com/hashicorp/packer-plugin-triton v1.0.0 github.com/hashicorp/packer-plugin-triton v1.0.0
github.com/hashicorp/packer-plugin-ucloud v1.0.0 github.com/hashicorp/packer-plugin-ucloud v1.0.0
...@@ -82,7 +81,7 @@ require ( ...@@ -82,7 +81,7 @@ require (
github.com/masterzen/winrm v0.0.0-20210623064412-3b76017826b0 github.com/masterzen/winrm v0.0.0-20210623064412-3b76017826b0
github.com/mattn/go-runewidth v0.0.13 // indirect github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/mattn/go-tty v0.0.0-20191112051231-74040eebce08 github.com/mattn/go-tty v0.0.0-20191112051231-74040eebce08
github.com/mitchellh/cli v1.1.0 github.com/mitchellh/cli v1.1.2
github.com/mitchellh/go-fs v0.0.0-20180402235330-b7b9ca407fff // indirect github.com/mitchellh/go-fs v0.0.0-20180402235330-b7b9ca407fff // indirect
github.com/mitchellh/go-homedir v1.1.0 github.com/mitchellh/go-homedir v1.1.0
github.com/mitchellh/mapstructure v1.4.1 github.com/mitchellh/mapstructure v1.4.1
...@@ -105,7 +104,7 @@ require ( ...@@ -105,7 +104,7 @@ require (
golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect golang.org/x/crypto v0.0.0-20210817164053-32db794688a5 // indirect
golang.org/x/mobile v0.0.0-20210901025245-1fde1d6c3ca1 // indirect golang.org/x/mobile v0.0.0-20210901025245-1fde1d6c3ca1 // indirect
golang.org/x/mod v0.5.0 golang.org/x/mod v0.5.0
golang.org/x/net v0.0.0-20210825183410-e898025ed96a golang.org/x/net v0.0.0-20210902165921-8d991716f632
golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f golang.org/x/oauth2 v0.0.0-20210819190943-2bc19b11175f
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect golang.org/x/sys v0.0.0-20210831042530-f4d43177bf5e // indirect
...@@ -117,7 +116,7 @@ require ( ...@@ -117,7 +116,7 @@ require (
) )
require ( require (
cloud.google.com/go v0.94.0 // indirect cloud.google.com/go/storage v1.16.1 // indirect
github.com/1and1/oneandone-cloudserver-sdk-go v1.0.1 // indirect github.com/1and1/oneandone-cloudserver-sdk-go v1.0.1 // indirect
github.com/Azure/go-autorest v14.2.0+incompatible // indirect github.com/Azure/go-autorest v14.2.0+incompatible // indirect
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
...@@ -125,7 +124,11 @@ require ( ...@@ -125,7 +124,11 @@ require (
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
github.com/Azure/go-autorest/logger v0.2.1 // indirect github.com/Azure/go-autorest/logger v0.2.1 // indirect
github.com/Azure/go-autorest/tracing v0.6.0 // indirect github.com/Azure/go-autorest/tracing v0.6.0 // indirect
github.com/Azure/go-ntlmssp v0.0.0-20200615164410-66371956d46c // indirect
github.com/ChrisTrenkamp/goxpath v0.0.0-20210404020558-97928f7e12b6 // indirect github.com/ChrisTrenkamp/goxpath v0.0.0-20210404020558-97928f7e12b6 // indirect
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible // indirect
github.com/Microsoft/go-winio v0.4.16 // indirect github.com/Microsoft/go-winio v0.4.16 // indirect
github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.2.0 // indirect github.com/NaverCloudPlatform/ncloud-sdk-go-v2 v1.2.0 // indirect
github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect github.com/ProtonMail/go-crypto v0.0.0-20210428141323-04723f9f07d7 // indirect
...@@ -172,6 +175,7 @@ require ( ...@@ -172,6 +175,7 @@ require (
github.com/go-stack/stack v1.8.0 // indirect github.com/go-stack/stack v1.8.0 // indirect
github.com/gofrs/uuid v4.0.0+incompatible // indirect github.com/gofrs/uuid v4.0.0+incompatible // indirect
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 // indirect github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang-jwt/jwt/v4 v4.0.0 // indirect github.com/golang-jwt/jwt/v4 v4.0.0 // indirect
github.com/golang/protobuf v1.5.2 // indirect github.com/golang/protobuf v1.5.2 // indirect
github.com/golang/snappy v0.0.4 // indirect github.com/golang/snappy v0.0.4 // indirect
...@@ -196,10 +200,12 @@ require ( ...@@ -196,10 +200,12 @@ require (
github.com/hashicorp/go-sockaddr v1.0.2 // indirect github.com/hashicorp/go-sockaddr v1.0.2 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/hashicorp/hcl v1.0.0 // indirect github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/packer-plugin v0.0.0-20210226150414-64c03a35871c // indirect
github.com/hashicorp/serf v0.9.5 // indirect github.com/hashicorp/serf v0.9.5 // indirect
github.com/hashicorp/vault/api v1.1.1 // indirect github.com/hashicorp/vault/api v1.1.1 // indirect
github.com/hashicorp/vault/sdk v0.2.1 // indirect github.com/hashicorp/vault/sdk v0.2.1 // indirect
github.com/hashicorp/yamux v0.0.0-20210826001029-26ff87cf9493 // indirect github.com/hashicorp/yamux v0.0.0-20210826001029-26ff87cf9493 // indirect
github.com/huandu/xstrings v1.3.2 // indirect
github.com/hyperonecom/h1-client-go v0.0.0-20191203060043-b46280e4c4a4 // indirect github.com/hyperonecom/h1-client-go v0.0.0-20191203060043-b46280e4c4a4 // indirect
github.com/imdario/mergo v0.3.12 // indirect github.com/imdario/mergo v0.3.12 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
...@@ -217,6 +223,7 @@ require ( ...@@ -217,6 +223,7 @@ require (
github.com/mattn/go-colorable v0.1.8 // indirect github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.13 // indirect github.com/mattn/go-isatty v0.0.13 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-testing-interface v1.14.1 // indirect github.com/mitchellh/go-testing-interface v1.14.1 // indirect
github.com/mitchellh/go-vnc v0.0.0-20150629162542-723ed9867aed // indirect github.com/mitchellh/go-vnc v0.0.0-20150629162542-723ed9867aed // indirect
github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect
......
This diff is collapsed.
...@@ -14,7 +14,7 @@ import ( ...@@ -14,7 +14,7 @@ import (
"github.com/hashicorp/packer/builder/null" "github.com/hashicorp/packer/builder/null"
dnull "github.com/hashicorp/packer/datasource/null" dnull "github.com/hashicorp/packer/datasource/null"
. "github.com/hashicorp/packer/hcl2template/internal" . "github.com/hashicorp/packer/hcl2template/internal"
packerregistry "github.com/hashicorp/packer/internal/packer_registry" packerregistry "github.com/hashicorp/packer/internal/registry"
"github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer"
"github.com/zclconf/go-cty/cty" "github.com/zclconf/go-cty/cty"
) )
......
...@@ -2,7 +2,7 @@ package hcl2template ...@@ -2,7 +2,7 @@ package hcl2template
import ( import (
"github.com/hashicorp/hcl/v2" "github.com/hashicorp/hcl/v2"
packerregistry "github.com/hashicorp/packer/internal/packer_registry" packerregistry "github.com/hashicorp/packer/internal/registry"
) )
// ConfiguredArtifactMetadataPublisher returns a configured image bucket that can be used for publishing // ConfiguredArtifactMetadataPublisher returns a configured image bucket that can be used for publishing
......
...@@ -6,8 +6,8 @@ import ( ...@@ -6,8 +6,8 @@ import (
"github.com/hashicorp/hcl/v2" "github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/gohcl" "github.com/hashicorp/hcl/v2/gohcl"
"github.com/hashicorp/hcl/v2/hclsyntax" "github.com/hashicorp/hcl/v2/hclsyntax"
packerregistry "github.com/hashicorp/packer/internal/packer_registry" packerregistry "github.com/hashicorp/packer/internal/registry"
"github.com/hashicorp/packer/internal/packer_registry/env" "github.com/hashicorp/packer/internal/registry/env"
) )
const ( const (
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"github.com/hashicorp/hcl/v2" "github.com/hashicorp/hcl/v2"
"github.com/hashicorp/hcl/v2/gohcl" "github.com/hashicorp/hcl/v2/gohcl"
packerregistry "github.com/hashicorp/packer/internal/packer_registry" packerregistry "github.com/hashicorp/packer/internal/registry"
) )
type HCPPackerRegistryBlock struct { type HCPPackerRegistryBlock struct {
......
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"testing" "testing"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer" packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer/internal/packer_registry" packer_registry "github.com/hashicorp/packer/internal/registry"
"github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer"
) )
......
...@@ -12,7 +12,7 @@ import ( ...@@ -12,7 +12,7 @@ import (
"github.com/hashicorp/hcl/v2/hclsyntax" "github.com/hashicorp/hcl/v2/hclsyntax"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer" packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
pkrfunction "github.com/hashicorp/packer/hcl2template/function" pkrfunction "github.com/hashicorp/packer/hcl2template/function"
packerregistry "github.com/hashicorp/packer/internal/packer_registry" packerregistry "github.com/hashicorp/packer/internal/registry"
"github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer"
"github.com/zclconf/go-cty/cty" "github.com/zclconf/go-cty/cty"
"github.com/zclconf/go-cty/cty/function" "github.com/zclconf/go-cty/cty/function"
......
package packer_registry package registry
import ( import (
"fmt" "fmt"
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
projectSvc "github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/preview/2019-12-10/client/project_service" projectSvc "github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/preview/2019-12-10/client/project_service"
rmmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/preview/2019-12-10/models" rmmodels "github.com/hashicorp/hcp-sdk-go/clients/cloud-resource-manager/preview/2019-12-10/models"
"github.com/hashicorp/hcp-sdk-go/httpclient" "github.com/hashicorp/hcp-sdk-go/httpclient"
"github.com/hashicorp/packer/internal/packer_registry/env" "github.com/hashicorp/packer/internal/registry/env"
) )
// Client is an HCP client capable of making requests on behalf of a service principal // Client is an HCP client capable of making requests on behalf of a service principal
......
File moved
package packer_registry package registry
import ( import (
"fmt" "fmt"
......
package packer_registry package registry
import ( import (
"errors" "errors"
......
package packer_registry package registry
import ( import (
"context" "context"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment