mirror of
https://github.com/hashicorp/packer.git
synced 2026-06-09 08:42:33 -04:00
Packer tracks Version and Plugins Metadata (#12860)
This commit is contained in:
parent
1c7930bec1
commit
595b45e67c
11 changed files with 139 additions and 21 deletions
|
|
@ -57,6 +57,7 @@ func Test_ParseHCPPackerRegistryBlock(t *testing.T) {
|
|||
Builder: emptyMockBuilder,
|
||||
Provisioners: []packer.CoreBuildProvisioner{},
|
||||
PostProcessors: [][]packer.CoreBuildPostProcessor{},
|
||||
BuilderType: "virtualbox-iso",
|
||||
},
|
||||
},
|
||||
false,
|
||||
|
|
@ -110,6 +111,7 @@ func Test_ParseHCPPackerRegistryBlock(t *testing.T) {
|
|||
Builder: emptyMockBuilder,
|
||||
Provisioners: []packer.CoreBuildProvisioner{},
|
||||
PostProcessors: [][]packer.CoreBuildPostProcessor{},
|
||||
BuilderType: "virtualbox-iso",
|
||||
},
|
||||
},
|
||||
false,
|
||||
|
|
@ -241,6 +243,7 @@ func Test_ParseHCPPackerRegistryBlock(t *testing.T) {
|
|||
Provisioners: []packer.CoreBuildProvisioner{},
|
||||
PostProcessors: [][]packer.CoreBuildPostProcessor{},
|
||||
Prepared: true,
|
||||
BuilderType: "null",
|
||||
},
|
||||
},
|
||||
false,
|
||||
|
|
|
|||
|
|
@ -283,6 +283,7 @@ func TestParse_build(t *testing.T) {
|
|||
[]packersdk.Build{
|
||||
&packer.CoreBuild{
|
||||
Type: "virtualbox-iso.ubuntu-1204",
|
||||
BuilderType: "virtualbox-iso",
|
||||
Prepared: true,
|
||||
Builder: emptyMockBuilder,
|
||||
Provisioners: []packer.CoreBuildProvisioner{},
|
||||
|
|
@ -317,6 +318,7 @@ func TestParse_build(t *testing.T) {
|
|||
},
|
||||
&packer.CoreBuild{
|
||||
Type: "amazon-ebs.aws-ubuntu-16.04",
|
||||
BuilderType: "amazon-ebs",
|
||||
Prepared: true,
|
||||
Builder: emptyMockBuilder,
|
||||
Provisioners: []packer.CoreBuildProvisioner{},
|
||||
|
|
@ -397,9 +399,10 @@ func TestParse_build(t *testing.T) {
|
|||
false, false,
|
||||
[]packersdk.Build{
|
||||
&packer.CoreBuild{
|
||||
Type: "virtualbox-iso.ubuntu-1204",
|
||||
Prepared: true,
|
||||
Builder: emptyMockBuilder,
|
||||
Type: "virtualbox-iso.ubuntu-1204",
|
||||
BuilderType: "virtualbox-iso",
|
||||
Prepared: true,
|
||||
Builder: emptyMockBuilder,
|
||||
Provisioners: []packer.CoreBuildProvisioner{
|
||||
{
|
||||
PType: "shell",
|
||||
|
|
@ -427,9 +430,10 @@ func TestParse_build(t *testing.T) {
|
|||
PostProcessors: [][]packer.CoreBuildPostProcessor{},
|
||||
},
|
||||
&packer.CoreBuild{
|
||||
Type: "amazon-ebs.aws-ubuntu-16.04",
|
||||
Prepared: true,
|
||||
Builder: emptyMockBuilder,
|
||||
Type: "amazon-ebs.aws-ubuntu-16.04",
|
||||
BuilderType: "amazon-ebs",
|
||||
Prepared: true,
|
||||
Builder: emptyMockBuilder,
|
||||
Provisioners: []packer.CoreBuildProvisioner{
|
||||
{
|
||||
PType: "file",
|
||||
|
|
@ -486,9 +490,10 @@ func TestParse_build(t *testing.T) {
|
|||
false, false,
|
||||
[]packersdk.Build{
|
||||
&packer.CoreBuild{
|
||||
Type: "virtualbox-iso.ubuntu-1204",
|
||||
Prepared: true,
|
||||
Builder: emptyMockBuilder,
|
||||
Type: "virtualbox-iso.ubuntu-1204",
|
||||
BuilderType: "virtualbox-iso",
|
||||
Prepared: true,
|
||||
Builder: emptyMockBuilder,
|
||||
Provisioners: []packer.CoreBuildProvisioner{
|
||||
{
|
||||
PType: "shell",
|
||||
|
|
@ -550,6 +555,7 @@ func TestParse_build(t *testing.T) {
|
|||
&packer.CoreBuild{
|
||||
BuildName: "build-name",
|
||||
Type: "virtualbox-iso.ubuntu-1204",
|
||||
BuilderType: "virtualbox-iso",
|
||||
Prepared: true,
|
||||
Builder: emptyMockBuilder,
|
||||
Provisioners: []packer.CoreBuildProvisioner{},
|
||||
|
|
@ -604,6 +610,7 @@ func TestParse_build(t *testing.T) {
|
|||
&packer.CoreBuild{
|
||||
BuildName: "test-build",
|
||||
Type: "virtualbox-iso.ubuntu-1204",
|
||||
BuilderType: "virtualbox-iso",
|
||||
Prepared: true,
|
||||
Builder: emptyMockBuilder,
|
||||
Provisioners: []packer.CoreBuildProvisioner{},
|
||||
|
|
@ -659,10 +666,11 @@ func TestParse_build(t *testing.T) {
|
|||
false, false,
|
||||
[]packersdk.Build{
|
||||
&packer.CoreBuild{
|
||||
BuildName: "build-name-test",
|
||||
Type: "virtualbox-iso.ubuntu-1204",
|
||||
Prepared: true,
|
||||
Builder: emptyMockBuilder,
|
||||
BuildName: "build-name-test",
|
||||
Type: "virtualbox-iso.ubuntu-1204",
|
||||
BuilderType: "virtualbox-iso",
|
||||
Prepared: true,
|
||||
Builder: emptyMockBuilder,
|
||||
Provisioners: []packer.CoreBuildProvisioner{
|
||||
{
|
||||
PName: "build-name-test",
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ func TestParse_datasource(t *testing.T) {
|
|||
[]packersdk.Build{
|
||||
&packer.CoreBuild{
|
||||
Type: "null.test",
|
||||
BuilderType: "null",
|
||||
Builder: &null.Builder{},
|
||||
Provisioners: []packer.CoreBuildProvisioner{},
|
||||
PostProcessors: [][]packer.CoreBuildPostProcessor{},
|
||||
|
|
@ -134,6 +135,7 @@ func TestParse_datasource(t *testing.T) {
|
|||
[]packersdk.Build{
|
||||
&packer.CoreBuild{
|
||||
Type: "null.test",
|
||||
BuilderType: "null",
|
||||
Builder: &null.Builder{},
|
||||
Provisioners: []packer.CoreBuildProvisioner{},
|
||||
PostProcessors: [][]packer.CoreBuildPostProcessor{},
|
||||
|
|
|
|||
|
|
@ -622,6 +622,7 @@ func (cfg *PackerConfig) GetBuilds(opts packer.GetBuildsOptions) ([]packersdk.Bu
|
|||
|
||||
decoded, _ := decodeHCL2Spec(srcUsage.Body, cfg.EvalContext(BuildContext, nil), builder)
|
||||
pcb.HCLConfig = decoded
|
||||
pcb.BuilderType = srcUsage.Type
|
||||
|
||||
// If the builder has provided a list of to-be-generated variables that
|
||||
// should be made accessible to provisioners, pass that list into
|
||||
|
|
|
|||
|
|
@ -208,8 +208,9 @@ func TestParser_complete(t *testing.T) {
|
|||
false, false,
|
||||
[]packersdk.Build{
|
||||
&packer.CoreBuild{
|
||||
Type: "virtualbox-iso.ubuntu-1204",
|
||||
Prepared: true,
|
||||
Type: "virtualbox-iso.ubuntu-1204",
|
||||
BuilderType: "virtualbox-iso",
|
||||
Prepared: true,
|
||||
Builder: &MockBuilder{
|
||||
Config: MockConfig{
|
||||
NestedMockConfig: NestedMockConfig{
|
||||
|
|
@ -319,8 +320,9 @@ func TestParser_complete(t *testing.T) {
|
|||
},
|
||||
},
|
||||
&packer.CoreBuild{
|
||||
Type: "amazon-ebs.ubuntu-1604",
|
||||
Prepared: true,
|
||||
Type: "amazon-ebs.ubuntu-1604",
|
||||
BuilderType: "amazon-ebs",
|
||||
Prepared: true,
|
||||
Builder: &MockBuilder{
|
||||
Config: MockConfig{
|
||||
NestedMockConfig: NestedMockConfig{
|
||||
|
|
|
|||
|
|
@ -55,6 +55,7 @@ func TestParse_source(t *testing.T) {
|
|||
[]packersdk.Build{
|
||||
&packer.CoreBuild{
|
||||
Type: "null.test",
|
||||
BuilderType: "null",
|
||||
Builder: &null.Builder{},
|
||||
Provisioners: []packer.CoreBuildProvisioner{},
|
||||
PostProcessors: [][]packer.CoreBuildPostProcessor{},
|
||||
|
|
|
|||
|
|
@ -129,6 +129,7 @@ func TestParse_variables(t *testing.T) {
|
|||
[]packersdk.Build{
|
||||
&packer.CoreBuild{
|
||||
Type: "null.test",
|
||||
BuilderType: "null",
|
||||
Builder: &null.Builder{},
|
||||
Provisioners: []packer.CoreBuildProvisioner{},
|
||||
PostProcessors: [][]packer.CoreBuildPostProcessor{},
|
||||
|
|
@ -293,6 +294,7 @@ func TestParse_variables(t *testing.T) {
|
|||
[]packersdk.Build{
|
||||
&packer.CoreBuild{
|
||||
Type: "null",
|
||||
BuilderType: "null",
|
||||
Builder: &null.Builder{},
|
||||
Provisioners: []packer.CoreBuildProvisioner{},
|
||||
PostProcessors: [][]packer.CoreBuildPostProcessor{},
|
||||
|
|
@ -379,6 +381,7 @@ func TestParse_variables(t *testing.T) {
|
|||
[]packersdk.Build{
|
||||
&packer.CoreBuild{
|
||||
Type: "null.test",
|
||||
BuilderType: "null",
|
||||
Builder: &null.Builder{},
|
||||
Provisioners: []packer.CoreBuildProvisioner{},
|
||||
PostProcessors: [][]packer.CoreBuildPostProcessor{},
|
||||
|
|
@ -442,6 +445,7 @@ func TestParse_variables(t *testing.T) {
|
|||
[]packersdk.Build{
|
||||
&packer.CoreBuild{
|
||||
Type: "null.test",
|
||||
BuilderType: "null",
|
||||
Builder: &null.Builder{},
|
||||
Provisioners: []packer.CoreBuildProvisioner{},
|
||||
PostProcessors: [][]packer.CoreBuildPostProcessor{},
|
||||
|
|
@ -483,6 +487,7 @@ func TestParse_variables(t *testing.T) {
|
|||
[]packersdk.Build{
|
||||
&packer.CoreBuild{
|
||||
Type: "null.test",
|
||||
BuilderType: "null",
|
||||
Builder: &null.Builder{},
|
||||
Provisioners: []packer.CoreBuildProvisioner{},
|
||||
PostProcessors: [][]packer.CoreBuildPostProcessor{},
|
||||
|
|
@ -538,9 +543,10 @@ func TestParse_variables(t *testing.T) {
|
|||
},
|
||||
false, false,
|
||||
[]packersdk.Build{&packer.CoreBuild{
|
||||
Type: "null.null-builder",
|
||||
Prepared: true,
|
||||
Builder: &null.Builder{},
|
||||
Type: "null.null-builder",
|
||||
BuilderType: "null",
|
||||
Prepared: true,
|
||||
Builder: &null.Builder{},
|
||||
Provisioners: []packer.CoreBuildProvisioner{
|
||||
{
|
||||
PType: "shell",
|
||||
|
|
@ -627,6 +633,7 @@ func TestParse_variables(t *testing.T) {
|
|||
[]packersdk.Build{
|
||||
&packer.CoreBuild{
|
||||
Type: "null.test",
|
||||
BuilderType: "null",
|
||||
Builder: &null.Builder{},
|
||||
Provisioners: []packer.CoreBuildProvisioner{},
|
||||
PostProcessors: [][]packer.CoreBuildPostProcessor{},
|
||||
|
|
|
|||
|
|
@ -85,6 +85,18 @@ func (h *HCLRegistry) CompleteBuild(
|
|||
if ok {
|
||||
name = cb.Type
|
||||
}
|
||||
|
||||
metadata := cb.GetMetadata()
|
||||
log.Printf(
|
||||
"[TRACE] HCL 'Packer Version' Metadata for build name %q: %q\n",
|
||||
name, metadata.PackerVersion,
|
||||
)
|
||||
for k, pluginDetails := range metadata.Plugins {
|
||||
log.Printf(
|
||||
"[TRACE] HCL 'Plugin' Metadata for build name %q: %q -- %q\n",
|
||||
name, k, pluginDetails.Description.Version,
|
||||
)
|
||||
}
|
||||
return h.bucket.completeBuild(ctx, name, artifacts, buildErr)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -93,7 +93,20 @@ func (h *JSONRegistry) CompleteBuild(
|
|||
artifacts []sdkpacker.Artifact,
|
||||
buildErr error,
|
||||
) ([]sdkpacker.Artifact, error) {
|
||||
return h.bucket.completeBuild(ctx, build.Name(), artifacts, buildErr)
|
||||
name := build.Name()
|
||||
|
||||
metadata := build.(*packer.CoreBuild).GetMetadata()
|
||||
log.Printf(
|
||||
"[TRACE] JSON 'Packer Version' Metadata for build name %q: %q\n",
|
||||
name, metadata.PackerVersion,
|
||||
)
|
||||
for k, pluginDetails := range metadata.Plugins {
|
||||
log.Printf(
|
||||
"[TRACE] JSON 'Plugin' Metadata for build name %q: %q -- %q\n",
|
||||
name, k, pluginDetails.Description.Version,
|
||||
)
|
||||
}
|
||||
return h.bucket.completeBuild(ctx, name, artifacts, buildErr)
|
||||
}
|
||||
|
||||
// VersionStatusSummary prints a status report in the UI if the version is not yet done
|
||||
|
|
|
|||
|
|
@ -52,6 +52,46 @@ type CoreBuild struct {
|
|||
prepareCalled bool
|
||||
}
|
||||
|
||||
type BuildMetadata struct {
|
||||
PackerVersion string
|
||||
Plugins map[string]PluginDetails
|
||||
}
|
||||
|
||||
func (b *CoreBuild) getPluginsMetadata() map[string]PluginDetails {
|
||||
resp := map[string]PluginDetails{}
|
||||
|
||||
builderPlugin, builderPluginOk := PluginsDetailsStorage[fmt.Sprintf("%q-%q", PluginComponentBuilder, b.BuilderType)]
|
||||
if builderPluginOk {
|
||||
resp[builderPlugin.Name] = builderPlugin
|
||||
}
|
||||
|
||||
for _, pp := range b.PostProcessors {
|
||||
for _, p := range pp {
|
||||
postprocessorsPlugin, postprocessorsPluginOk := PluginsDetailsStorage[fmt.Sprintf("%q-%q", PluginComponentPostProcessor, p.PType)]
|
||||
if postprocessorsPluginOk {
|
||||
resp[postprocessorsPlugin.Name] = postprocessorsPlugin
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, pv := range b.Provisioners {
|
||||
provisionerPlugin, provisionerPluginOk := PluginsDetailsStorage[fmt.Sprintf("%q-%q", PluginComponentProvisioner, pv.PType)]
|
||||
if provisionerPluginOk {
|
||||
resp[provisionerPlugin.Name] = provisionerPlugin
|
||||
}
|
||||
}
|
||||
|
||||
return resp
|
||||
}
|
||||
|
||||
func (b *CoreBuild) GetMetadata() BuildMetadata {
|
||||
metadata := BuildMetadata{
|
||||
PackerVersion: version.FormattedVersion(),
|
||||
Plugins: b.getPluginsMetadata(),
|
||||
}
|
||||
return metadata
|
||||
}
|
||||
|
||||
// CoreBuildPostProcessor Keeps track of the post-processor and the
|
||||
// configuration of the post-processor used within a build.
|
||||
type CoreBuildPostProcessor struct {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ package packer
|
|||
import (
|
||||
"crypto/sha256"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
|
@ -135,6 +136,11 @@ func (c *PluginConfig) DiscoverMultiPlugin(pluginName, pluginPath string) error
|
|||
}
|
||||
|
||||
pluginPrefix := pluginName + "-"
|
||||
pluginDetails := PluginDetails{
|
||||
Name: pluginName,
|
||||
Description: desc,
|
||||
PluginPath: pluginPath,
|
||||
}
|
||||
|
||||
for _, builderName := range desc.Builders {
|
||||
builderName := builderName // copy to avoid pointer overwrite issue
|
||||
|
|
@ -145,6 +151,8 @@ func (c *PluginConfig) DiscoverMultiPlugin(pluginName, pluginPath string) error
|
|||
c.Builders.Set(key, func() (packersdk.Builder, error) {
|
||||
return c.Client(pluginPath, "start", "builder", builderName).Builder()
|
||||
})
|
||||
PluginsDetailsStorage[fmt.Sprintf("%q-%q", PluginComponentBuilder, key)] = pluginDetails
|
||||
|
||||
}
|
||||
|
||||
if len(desc.Builders) > 0 {
|
||||
|
|
@ -160,6 +168,7 @@ func (c *PluginConfig) DiscoverMultiPlugin(pluginName, pluginPath string) error
|
|||
c.PostProcessors.Set(key, func() (packersdk.PostProcessor, error) {
|
||||
return c.Client(pluginPath, "start", "post-processor", postProcessorName).PostProcessor()
|
||||
})
|
||||
PluginsDetailsStorage[fmt.Sprintf("%q-%q", PluginComponentPostProcessor, key)] = pluginDetails
|
||||
}
|
||||
|
||||
if len(desc.PostProcessors) > 0 {
|
||||
|
|
@ -175,6 +184,8 @@ func (c *PluginConfig) DiscoverMultiPlugin(pluginName, pluginPath string) error
|
|||
c.Provisioners.Set(key, func() (packersdk.Provisioner, error) {
|
||||
return c.Client(pluginPath, "start", "provisioner", provisionerName).Provisioner()
|
||||
})
|
||||
PluginsDetailsStorage[fmt.Sprintf("%q-%q", PluginComponentProvisioner, key)] = pluginDetails
|
||||
|
||||
}
|
||||
if len(desc.Provisioners) > 0 {
|
||||
log.Printf("found external %v provisioner from %s plugin", desc.Provisioners, pluginName)
|
||||
|
|
@ -189,6 +200,7 @@ func (c *PluginConfig) DiscoverMultiPlugin(pluginName, pluginPath string) error
|
|||
c.DataSources.Set(key, func() (packersdk.Datasource, error) {
|
||||
return c.Client(pluginPath, "start", "datasource", datasourceName).Datasource()
|
||||
})
|
||||
PluginsDetailsStorage[fmt.Sprintf("%q-%q", PluginComponentDataSource, key)] = pluginDetails
|
||||
}
|
||||
if len(desc.Datasources) > 0 {
|
||||
log.Printf("found external %v datasource from %s plugin", desc.Datasources, pluginName)
|
||||
|
|
@ -240,3 +252,20 @@ func (c *PluginConfig) Client(path string, args ...string) *PluginClient {
|
|||
config.MaxPort = c.PluginMaxPort
|
||||
return NewClient(&config)
|
||||
}
|
||||
|
||||
type PluginComponentType string
|
||||
|
||||
const (
|
||||
PluginComponentBuilder PluginComponentType = "builder"
|
||||
PluginComponentPostProcessor PluginComponentType = "post-processor"
|
||||
PluginComponentProvisioner PluginComponentType = "provisioner"
|
||||
PluginComponentDataSource PluginComponentType = "data-source"
|
||||
)
|
||||
|
||||
type PluginDetails struct {
|
||||
Name string
|
||||
Description pluginsdk.SetDescription
|
||||
PluginPath string
|
||||
}
|
||||
|
||||
var PluginsDetailsStorage = map[string]PluginDetails{}
|
||||
|
|
|
|||
Loading…
Reference in a new issue