From 83ecebbf378adb55cda8e55ac8c3961347e49696 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Thu, 16 Jan 2020 13:02:31 -0800 Subject: [PATCH] add PACKER_PLUGIN_PATH for plugin discovery --- config.go | 20 +++++++++++++++++-- website/source/docs/extending/plugins.html.md | 9 +++++++++ .../docs/other/environment-variables.html.md | 8 ++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/config.go b/config.go index 33e88505f..715ce03f5 100644 --- a/config.go +++ b/config.go @@ -123,7 +123,23 @@ func (c *config) Discover() error { return nil } - // First, look in the same directory as the executable. + // First, check whether there is a custom Plugin directory defined. This gets + // absolute preference. + if packerPluginPath := os.Getenv("PACKER_PLUGIN_PATH"); packerPluginPath != "" { + sep := ":" + if runtime.GOOS == "windows" { + // on windows, PATH is semicolon-separated + sep = ";" + } + plugPaths := strings.Split(packerPluginPath, sep) + for _, plugPath := range plugPaths { + if err := c.discoverExternalComponents(plugPath); err != nil { + return err + } + } + } + + // Next, look in the same directory as the executable. exePath, err := osext.Executable() if err != nil { log.Printf("[ERR] Error loading exe directory: %s", err) @@ -133,7 +149,7 @@ func (c *config) Discover() error { } } - // Next, look in the plugins directory. + // Next, look in the default plugins directory inside the configdir/.packer.d/plugins. dir, err := packer.ConfigDir() if err != nil { log.Printf("[ERR] Error loading config directory: %s", err) diff --git a/website/source/docs/extending/plugins.html.md b/website/source/docs/extending/plugins.html.md index 24d337c43..995830b62 100644 --- a/website/source/docs/extending/plugins.html.md +++ b/website/source/docs/extending/plugins.html.md @@ -51,6 +51,7 @@ Once the plugin is named properly, Packer automatically discovers plugins in the following directories in the given order. If a conflicting plugin is found later, it will take precedence over one found earlier. + 1. The directory where `packer` is, or the executable directory. 2. The `$HOME/.packer.d/plugins` directory, if `$HOME` is defined (unix) @@ -62,6 +63,14 @@ later, it will take precedence over one found earlier. 5. The current working directory. +6. The directory defined in the env var `PACKER_PLUGIN_PATH`. There can be more +than one directory defined; for example, `~/custom-dir-1:~/custom-dir-2`. +Separate directories in the PATH string using a colon (`:`) on posix systems and +a semicolon (`;`) on windows systems. The above example path would be able to +find a provisioner named `packer-provisioner-foo` in either +`~/custom-dir-1/packer-provisioner-foo` or +`~/custom-dir-2/packer-provisioner-foo`. + The valid types for plugins are: - `builder` - Plugins responsible for building images for a specific diff --git a/website/source/docs/other/environment-variables.html.md b/website/source/docs/other/environment-variables.html.md index 257336482..eaebae6ec 100644 --- a/website/source/docs/other/environment-variables.html.md +++ b/website/source/docs/other/environment-variables.html.md @@ -39,6 +39,14 @@ each can be found below: connections on your local host. The default is 10,000. See the [core configuration page](/docs/other/core-configuration.html). +- `PACKER_PLUGIN_PATH` - a PATH variable for finding third-party packer +plugins. For example: `~/custom-dir-1:~/custom-dir-2`. +Separate directories in the PATH string using a colon (`:`) on posix systems and +a semicolon (`;`) on windows systems. The above example path would be able to +find a provisioner named `packer-provisioner-foo` in either +`~/custom-dir-1/packer-provisioner-foo` or +`~/custom-dir-2/packer-provisioner-foo`. + - `CHECKPOINT_DISABLE` - When Packer is invoked it sometimes calls out to [checkpoint.hashicorp.com](https://checkpoint.hashicorp.com/) to look for new versions of Packer. If you want to disable this for security or privacy