packer: remove single-component plugins

Single-component plugins are a relic from the past that has been
deprecated from version 1.7.0 and onwards.

Since we're revisiting how plugins are installed/loaded, and the changes
will be incompatible with those, we remove them in preparation of this
work.
update/migrate_scaleway_and_mondoo_integration
Lucas Bajolet 2 years ago committed by Lucas Bajolet
parent beb5fcf470
commit 6c99f387a0

@ -10,7 +10,6 @@ import (
"fmt"
"log"
"os"
"path/filepath"
"runtime"
"sort"
"strings"
@ -203,100 +202,6 @@ func TestInitCommand_Run(t *testing.T) {
"h1:47DEQpj8HBSa+/TImW+5JCeuQeRkm5NMpJWZG3hSuFU=",
nil,
},
{
"manually-installed-single-component-plugin-works",
[]func(t *testing.T, tc testCaseInit){
skipInitTestUnlessEnVar(acctest.TestEnvVar).fn,
initTestGoGetPlugin{
Src: "https://github.com/azr/packer-provisioner-comment/releases/download/v1.0.0/" +
"packer-provisioner-comment_v1.0.0_" + runtime.GOOS + "_" + runtime.GOARCH + ".zip",
Dst: filepath.Join(cfg.dir("4_pkr_config"), defaultConfigDir, "plugins"),
}.fn,
},
TestMetaFile(t),
nil,
map[string]string{
"darwin": "h1:nVebbXToeehPUASRbvV9M4qaA9+UgoR5AMp7LjTrSBk=",
"linux": "h1:/U5vdeMtOpRKNu0ld8+qf4t6WC+BsfCQ6JRo9Dh/khI=",
"windows": "h1:0nkdNCjtTHTgBNkzVKG++/VYmWAvq/o236GGTxrIf/Q=",
}[runtime.GOOS],
map[string]string{
`source.pkr.hcl`: `
source "null" "test" {
communicator = "none"
}
`,
`build.pkr.hcl`: `
build {
sources = ["source.null.test"]
provisioner "comment" {
comment = "Begin ¡"
ui = true
bubble_text = true
}
}
`,
},
cfg.dir("4_pkr_config"),
cfg.dir("4_pkr_user_folder"),
0,
nil,
map[string]string{
"darwin": "h1:nVebbXToeehPUASRbvV9M4qaA9+UgoR5AMp7LjTrSBk=",
"linux": "h1:/U5vdeMtOpRKNu0ld8+qf4t6WC+BsfCQ6JRo9Dh/khI=",
"windows": "h1:0nkdNCjtTHTgBNkzVKG++/VYmWAvq/o236GGTxrIf/Q=",
}[runtime.GOOS],
[]func(*testing.T, testCaseInit){
testBuild{want: 0}.fn,
},
},
{
"manually-installed-single-component-plugin-old-api-fails",
[]func(t *testing.T, tc testCaseInit){
skipInitTestUnlessEnVar(acctest.TestEnvVar).fn,
initTestGoGetPlugin{
Src: "https://github.com/azr/packer-provisioner-comment/releases/download/v0.0.0/" +
"packer-provisioner-comment_v0.0.0_" + runtime.GOOS + "_" + runtime.GOARCH + ".zip",
Dst: filepath.Join(cfg.dir("5_pkr_config"), defaultConfigDir, "plugins"),
}.fn,
},
TestMetaFile(t),
nil,
map[string]string{
"darwin": "h1:gW4gzpDXeu3cDrXgHJj9iWAN7Pyak626Gq8Bu2LG1kY=",
"linux": "h1:wQ2H5+J7VXwQzqR9DgpWtjhw9OVEFbcKQL6dgm/+zwo=",
"windows": "h1:BqRdW3c5H1PZ2Q4DOaKWja21v3nDlY5Nn8kqahhHGSw=",
}[runtime.GOOS],
map[string]string{
`source.pkr.hcl`: `
source "null" "test" {
communicator = "none"
}
`,
`build.pkr.hcl`: `
build {
sources = ["source.null.test"]
provisioner "comment" {
comment = "Begin ¡"
ui = true
bubble_text = true
}
}
`,
},
cfg.dir("5_pkr_config"),
cfg.dir("5_pkr_user_folder"),
0,
nil,
map[string]string{
"darwin": "h1:gW4gzpDXeu3cDrXgHJj9iWAN7Pyak626Gq8Bu2LG1kY=",
"linux": "h1:wQ2H5+J7VXwQzqR9DgpWtjhw9OVEFbcKQL6dgm/+zwo=",
"windows": "h1:BqRdW3c5H1PZ2Q4DOaKWja21v3nDlY5Nn8kqahhHGSw=",
}[runtime.GOOS],
[]func(*testing.T, testCaseInit){
testBuild{want: 1}.fn,
},
},
{
"unsupported-non-github-source-address",
[]func(t *testing.T, tc testCaseInit){

@ -72,13 +72,6 @@ func (c *PluginConfig) Discover() error {
c.KnownPluginFolders = PluginFolders(".")
}
// TODO after JSON is deprecated remove support for legacy component plugins.
for _, knownFolder := range c.KnownPluginFolders {
if err := c.discoverLegacyMonoComponents(knownFolder); err != nil {
return err
}
}
// Pick last folder as it's the one with the highest priority
// This is the same logic used when installing plugins via Packer's plugin installation commands.
pluginInstallationPath := c.KnownPluginFolders[len(c.KnownPluginFolders)-1]
@ -107,88 +100,6 @@ func (c *PluginConfig) Discover() error {
return nil
}
func (c *PluginConfig) discoverLegacyMonoComponents(path string) error {
var err error
log.Printf("[TRACE] discovering plugins in %s", path)
if !filepath.IsAbs(path) {
path, err = filepath.Abs(path)
if err != nil {
return err
}
}
var externallyUsed []string
pluginPaths, err := c.discoverSingle(filepath.Join(path, "packer-builder-*"))
if err != nil {
return err
}
for pluginName, pluginPath := range pluginPaths {
newPath := pluginPath // this needs to be stored in a new variable for the func below
c.Builders.Set(pluginName, func() (packersdk.Builder, error) {
return c.Client(newPath).Builder()
})
externallyUsed = append(externallyUsed, pluginName)
}
if len(externallyUsed) > 0 {
sort.Strings(externallyUsed)
log.Printf("[INFO] using external builders: %v", externallyUsed)
externallyUsed = nil
}
pluginPaths, err = c.discoverSingle(filepath.Join(path, "packer-post-processor-*"))
if err != nil {
return err
}
for pluginName, pluginPath := range pluginPaths {
newPath := pluginPath // this needs to be stored in a new variable for the func below
c.PostProcessors.Set(pluginName, func() (packersdk.PostProcessor, error) {
return c.Client(newPath).PostProcessor()
})
externallyUsed = append(externallyUsed, pluginName)
}
if len(externallyUsed) > 0 {
sort.Strings(externallyUsed)
log.Printf("using external post-processors %v", externallyUsed)
externallyUsed = nil
}
pluginPaths, err = c.discoverSingle(filepath.Join(path, "packer-provisioner-*"))
if err != nil {
return err
}
for pluginName, pluginPath := range pluginPaths {
newPath := pluginPath // this needs to be stored in a new variable for the func below
c.Provisioners.Set(pluginName, func() (packersdk.Provisioner, error) {
return c.Client(newPath).Provisioner()
})
externallyUsed = append(externallyUsed, pluginName)
}
if len(externallyUsed) > 0 {
sort.Strings(externallyUsed)
log.Printf("using external provisioners %v", externallyUsed)
externallyUsed = nil
}
pluginPaths, err = c.discoverSingle(filepath.Join(path, "packer-datasource-*"))
if err != nil {
return err
}
for pluginName, pluginPath := range pluginPaths {
newPath := pluginPath // this needs to be stored in a new variable for the func below
c.DataSources.Set(pluginName, func() (packersdk.Datasource, error) {
return c.Client(newPath).Datasource()
})
externallyUsed = append(externallyUsed, pluginName)
}
if len(externallyUsed) > 0 {
sort.Strings(externallyUsed)
log.Printf("using external datasource %v", externallyUsed)
}
return nil
}
func (c *PluginConfig) discoverSingle(glob string) (map[string]string, error) {
matches, err := filepath.Glob(glob)
if err != nil {

@ -42,118 +42,6 @@ func TestDiscoverReturnsIfMagicCookieSet(t *testing.T) {
}
}
func TestEnvVarPackerPluginPath(t *testing.T) {
// Create a temporary directory to store plugins in
dir, _, cleanUpFunc, err := generateFakePlugins("custom_plugin_dir",
[]string{"packer-provisioner-partyparrot"})
if err != nil {
t.Fatalf("Error creating fake custom plugins: %s", err)
}
defer cleanUpFunc()
// Add temp dir to path.
t.Setenv("PACKER_PLUGIN_PATH", dir)
config := newPluginConfig()
err = config.Discover()
if err != nil {
t.Fatalf("Should not have errored: %s", err)
}
if len(config.Provisioners.List()) == 0 {
t.Fatalf("Should have found partyparrot provisioner")
}
if !config.Provisioners.Has("partyparrot") {
t.Fatalf("Should have found partyparrot provisioner.")
}
}
func TestEnvVarPackerPluginPath_MultiplePaths(t *testing.T) {
// Create a temporary directory to store plugins in
dir, _, cleanUpFunc, err := generateFakePlugins("custom_plugin_dir",
[]string{"packer-provisioner-partyparrot"})
if err != nil {
t.Fatalf("Error creating fake custom plugins: %s", err)
}
defer cleanUpFunc()
pathsep := ":"
if runtime.GOOS == "windows" {
pathsep = ";"
}
// Create a second dir to look in that will be empty
decoyDir, err := os.MkdirTemp("", "decoy")
if err != nil {
t.Fatalf("Failed to create a temporary test dir.")
}
defer os.Remove(decoyDir)
pluginPath := dir + pathsep + decoyDir
// Add temp dir to path.
t.Setenv("PACKER_PLUGIN_PATH", pluginPath)
config := newPluginConfig()
err = config.Discover()
if err != nil {
t.Fatalf("Should not have errored: %s", err)
}
if len(config.Provisioners.List()) == 0 {
t.Fatalf("Should have found partyparrot provisioner")
}
if !config.Provisioners.Has("partyparrot") {
t.Fatalf("Should have found partyparrot provisioner.")
}
}
func TestDiscoverDatasource(t *testing.T) {
// Create a temporary directory to store plugins in
dir, _, cleanUpFunc, err := generateFakePlugins("custom_plugin_dir",
[]string{"packer-datasource-partyparrot"})
if err != nil {
t.Fatalf("Error creating fake custom plugins: %s", err)
}
defer cleanUpFunc()
pathsep := ":"
if runtime.GOOS == "windows" {
pathsep = ";"
}
// Create a second dir to look in that will be empty
decoyDir, err := os.MkdirTemp("", "decoy")
if err != nil {
t.Fatalf("Failed to create a temporary test dir.")
}
defer os.Remove(decoyDir)
pluginPath := dir + pathsep + decoyDir
// Add temp dir to path.
t.Setenv("PACKER_PLUGIN_PATH", pluginPath)
config := newPluginConfig()
err = config.Discover()
if err != nil {
t.Fatalf("Should not have errored: %s", err)
}
if len(config.DataSources.List()) == 0 {
t.Fatalf("Should have found partyparrot datasource")
}
if !config.DataSources.Has("partyparrot") {
t.Fatalf("Should have found partyparrot datasource.")
}
}
func TestMultiPlugin_describe(t *testing.T) {
createMockPlugins(t, mockPlugins)
pluginDir := os.Getenv("PACKER_PLUGIN_PATH")

Loading…
Cancel
Save