From 5d4d5a21bfce02dd8563df006e50145f1acc09c8 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Thu, 25 Jul 2019 13:06:41 -0700 Subject: [PATCH 1/3] check env for a PACKER_CONFIG_DIR before defaulting to homedir for config --- packer/config_file.go | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/packer/config_file.go b/packer/config_file.go index 04275f457..173766afa 100644 --- a/packer/config_file.go +++ b/packer/config_file.go @@ -52,18 +52,31 @@ func homeDir() (string, error) { } func configFile() (string, error) { - dir, err := homeDir() - if err != nil { - return "", err + var dir string + if cd := os.Getenv("PACKER_CONFIG_DIR"); cd != "" { + log.Printf("Detected config directory from env var: %s", cd) + dir = cd + } else { + homedir, err := homeDir() + if err != nil { + return "", err + } + dir = homedir } - return filepath.Join(dir, defaultConfigFile), nil } func configDir() (string, error) { - dir, err := homeDir() - if err != nil { - return "", err + var dir string + if cd := os.Getenv("PACKER_CONFIG_DIR"); cd != "" { + log.Printf("Detected config directory from env var: %s", cd) + dir = cd + } else { + homedir, err := homeDir() + if err != nil { + return "", err + } + dir = homedir } return filepath.Join(dir, defaultConfigDir), nil From 2e3d4bebe7523c426770bdfed3ddcd990ca4dd30 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Thu, 25 Jul 2019 13:13:40 -0700 Subject: [PATCH 2/3] docs --- website/source/docs/other/environment-variables.html.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/website/source/docs/other/environment-variables.html.md b/website/source/docs/other/environment-variables.html.md index a9becdcf1..386fc6983 100644 --- a/website/source/docs/other/environment-variables.html.md +++ b/website/source/docs/other/environment-variables.html.md @@ -16,6 +16,8 @@ each can be found below: of the configuration file is basic JSON. See the [core configuration page](/docs/other/core-configuration.html). +- `PACKER_CONFIG_DIR` - The location to place the `.packer.d` config directory + - `PACKER_LOG` - Setting this to any value other than "" (empty string) or "0" will enable the logger. See the [debugging page](/docs/other/debugging.html). From 7e2ea77634b6df0c4271ea340237af89e83bc6c6 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Thu, 25 Jul 2019 13:16:08 -0700 Subject: [PATCH 3/3] docs --- website/source/docs/other/environment-variables.html.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/source/docs/other/environment-variables.html.md b/website/source/docs/other/environment-variables.html.md index 386fc6983..257336482 100644 --- a/website/source/docs/other/environment-variables.html.md +++ b/website/source/docs/other/environment-variables.html.md @@ -16,7 +16,7 @@ each can be found below: of the configuration file is basic JSON. See the [core configuration page](/docs/other/core-configuration.html). -- `PACKER_CONFIG_DIR` - The location to place the `.packer.d` config directory +- `PACKER_CONFIG_DIR` - The location of the `.packer.d` config directory - `PACKER_LOG` - Setting this to any value other than "" (empty string) or "0" will enable the logger. See the [debugging