From b7222d1f56924b09b9e246a6ea5b34d634156beb Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Wed, 12 Dec 2018 15:45:00 +0100 Subject: [PATCH 1/4] Add tmp package that offers Dir & File funcs this regroups the calls of tmp func calls into one package. the tmp pkg allows to store tmp files under a common directory for easier managment Squashed commit of the following: commit 74b674c01560c6b547e9cab5e8afb486f0fe7d6c Merge: fc94b5714 66001525d Author: Matthew Patton Date: Fri Nov 2 02:02:38 2018 -0400 Merge branch 'remove_TMPDIR_docs' of github.com:tb3088/packer into remove_TMPDIR_docs commit fc94b571428447aaf2e5171967c95cdf9e5c73ff Author: Matthew Patton Date: Fri Nov 2 01:42:38 2018 -0400 update tests to honor configured temporary directory commit 5a562359f4937af506607dd96ed1c46426093f52 Author: Matthew Patton Date: Thu Nov 1 18:52:38 2018 -0400 sync straggler to refactor. implement tests at packer/configfile instead of buried in docker. commit 9d5a4a0935bfd049e2f8f50ad73e4455b42c9410 Author: Matthew Patton Date: Thu Nov 1 15:39:46 2018 -0400 insert URL to GoLang API for os.TempDir() commit fbae4c2e051898aecd8705e9d8a20353430ede23 Author: Matthew Patton Date: Thu Nov 1 07:41:29 2018 -0400 revise documentation to match code commit 3590fae8bd0afa92a161a49ed794ee32e357d583 Author: Matthew Patton Date: Thu Nov 1 07:21:59 2018 -0400 refacter config_file. replace all hard-coded os.TempDir with wrapper commit d5c5306a97b648ded06a8eb76ce728f07c9924f0 Author: Matthew Patton Date: Wed Oct 31 20:11:36 2018 -0400 close massive file overwrite hole with TempDir commit 0a72297da86089fbd07e4f7d9472a92fa4d1c733 Author: Matthew Patton Date: Wed Oct 31 01:06:00 2018 -0400 adjust var declaration scope commit 20f68228b6c372d984ea5b055cfc8bda9b110ac5 Author: Matthew Patton Date: Wed Oct 31 00:54:35 2018 -0400 use mktemp() equivalent to create temporary directory commit c73ebe3d8321664a2685a0baa8e441dd895b0db4 Author: Matthew Patton Date: Tue Oct 30 20:40:58 2018 -0400 remove extraneous variable declaration, fix FOR loop commit 63549b8bd745a0090b15ed0b0ebf644162db27db Author: Matthew Patton Date: Tue Oct 30 19:30:44 2018 -0400 match styistic convension with rest of docs commit 976101074942db36f10d3a686d6d29ddb7c01926 Author: Matthew Patton Date: Tue Oct 30 19:08:39 2018 -0400 revert dangling config file change commit 95159afbc05eac96ed11c3183af5fb0abe2f2d5c Author: Matthew Patton Date: Fri Dec 29 23:53:43 2017 -0500 replace invalid TMPDIR variable wth PACKER_TMP_DIR. update ConfigTmpDir() to try common temporary paths first and only write to configDir() as a last resort. commit 66001525d72de56a4cf9339b900c46f59bc6e91a Author: Matthew Patton Date: Fri Nov 2 01:42:38 2018 -0400 update tests to honor configured temporary directory commit e9b6adefeae8c65eb8aa47fef38cbf0aa424338c Author: Matthew Patton Date: Thu Nov 1 18:52:38 2018 -0400 sync straggler to refactor. implement tests at packer/configfile instead of buried in docker. commit 852113ed076e2d14e5dca6815ea680da1e2896bb Author: Matthew Patton Date: Thu Nov 1 15:39:46 2018 -0400 insert URL to GoLang API for os.TempDir() commit 54add38d1d1c6e283cd444b367ed8bd49a5f3699 Author: Matthew Patton Date: Thu Nov 1 07:41:29 2018 -0400 revise documentation to match code commit 6b5b8f6d4edad0e187ca13d64ac4118f34eee643 Author: Matthew Patton Date: Thu Nov 1 07:21:59 2018 -0400 refacter config_file. replace all hard-coded os.TempDir with wrapper commit c22092c601c33484327674f322c7379fa41506d7 Author: Matthew Patton Date: Wed Oct 31 20:11:36 2018 -0400 close massive file overwrite hole with TempDir commit 7a730450916bf8e5dbc2a741ec233a49466ab7cc Author: Matthew Patton Date: Wed Oct 31 01:06:00 2018 -0400 adjust var declaration scope commit 0f2933adb6f6922dfeab78a95371a444ec8918ab Author: Matthew Patton Date: Wed Oct 31 00:54:35 2018 -0400 use mktemp() equivalent to create temporary directory commit d74839ede05dacf712b55a7bb48aec19fe6b007f Author: Matthew Patton Date: Tue Oct 30 20:40:58 2018 -0400 remove extraneous variable declaration, fix FOR loop commit eb65416619437e4a3dec90277770803dd5b2281c Author: Matthew Patton Date: Tue Oct 30 19:30:44 2018 -0400 match styistic convension with rest of docs commit acaa2b31ed463219c4ef099f351eec72406e2989 Author: Matthew Patton Date: Tue Oct 30 19:08:39 2018 -0400 revert dangling config file change commit e573fde668dcb418561e61535c1d68b2888f5b0f Author: Matthew Patton Date: Fri Dec 29 23:53:43 2017 -0500 replace invalid TMPDIR variable wth PACKER_TMP_DIR. update ConfigTmpDir() to try common temporary paths first and only write to configDir() as a last resort. commit 39a9874afc9dea71b36753375fb7feb61ffecf69 Merge: 8a413cfe8 3315812c2 Author: Matthew Patton Date: Tue Oct 30 18:19:26 2018 -0400 Merge branch 'master' of https://github.com/hashicorp/packer into prestine commit 8a413cfe83b0a70dbd99c32d936334ca5788ca9b Merge: e07491de5 4e14710a6 Author: Matthew Patton Date: Mon Oct 1 20:18:10 2018 -0400 Merge remote-tracking branch 'upstream/master' into prestine commit e07491de59cead0b337a7f57f4a6c625e1f560ab Merge: 42610a35d a1fa35dff Author: Matthew Patton Date: Tue Aug 21 13:26:19 2018 -0400 Merge remote-tracking branch 'upstream/master' into prestine commit 42610a35d5ef65af8844a58ad70e2ec75262da6a Merge: 5298142da 0d63cf7bc Author: Matthew Patton Date: Tue Jun 19 22:45:05 2018 -0400 Merge remote-tracking branch 'upstream/master' into prestine commit 5298142da6da95354844f201deeeef3c599e48b2 Merge: 7bb110bc7 9d9736552 Author: Matthew Patton Date: Mon Jun 11 15:10:09 2018 -0400 Merge remote-tracking branch 'upstream/master' into prestine commit 7bb110bc744c9797fcaec25a265d9b85a22d6d6b Merge: a61c869ca 6189d66e7 Author: Matthew Patton Date: Wed May 9 23:41:22 2018 -0400 Merge remote-tracking branch 'upstream/master' into prestine commit a61c869ca7268acf0e3b1e1fa7a8ee7feea65984 Merge: 098101dd9 4be5f072c Author: Matthew Patton Date: Fri May 4 10:13:04 2018 -0400 Merge remote-tracking branch 'upstream/master' into prestine commit 098101dd99f08b0ca110d33eff6904537c6d21de Merge: fefaf0fa6 554b2b4a5 Author: Matthew Patton Date: Tue May 1 20:52:30 2018 -0400 Merge branch 'EOL-handling' into prestine Co-Authored-By: Matthew Patton --- builder/amazon/chroot/communicator.go | 4 +- builder/docker/step_temp_dir.go | 10 +--- builder/docker/step_temp_dir_test.go | 45 ----------------- .../hyperv/common/step_create_build_dir.go | 8 +-- .../common/step_create_build_dir_test.go | 4 +- .../hyperv/common/step_mount_floppydrive.go | 4 +- builder/hyperv/iso/builder_test.go | 3 +- builder/lxc/communicator.go | 3 +- builder/openstack/step_key_pair.go | 5 +- builder/parallels/common/driver_9.go | 3 +- .../virtualbox/common/step_attach_floppy.go | 4 +- .../common/step_download_guest_additions.go | 4 +- builder/vmware/iso/step_create_vmx.go | 3 +- builder/vmware/iso/step_create_vmx_test.go | 1 + builder/vmware/vmx/step_clone_vmx.go | 4 +- common/powershell/powershell.go | 5 +- common/shell-local/run.go | 4 +- common/step_create_floppy.go | 4 +- communicator/ssh/communicator.go | 3 +- helper/communicator/testing.go | 5 +- main.go | 3 +- packer/cache_test.go | 4 +- packer/config_file.go | 22 --------- packer/plugin/server.go | 4 +- packer/tmp/tmp.go | 49 +++++++++++++++++++ post-processor/vagrant/post-processor.go | 3 +- post-processor/vagrant/virtualbox_test.go | 7 +-- provisioner/ansible-local/provisioner.go | 4 +- provisioner/ansible/provisioner.go | 3 +- provisioner/ansible/scp.go | 6 +-- provisioner/powershell/provisioner.go | 4 +- provisioner/shell/provisioner.go | 6 +-- provisioner/windows-shell/provisioner.go | 5 +- template/parse.go | 4 +- website/source/docs/builders/docker.html.md | 6 +-- .../docs/other/environment-variables.html.md | 16 +++--- 36 files changed, 134 insertions(+), 138 deletions(-) create mode 100644 packer/tmp/tmp.go diff --git a/builder/amazon/chroot/communicator.go b/builder/amazon/chroot/communicator.go index 8b552d002..5dd3d0719 100644 --- a/builder/amazon/chroot/communicator.go +++ b/builder/amazon/chroot/communicator.go @@ -4,7 +4,6 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "log" "os" "os/exec" @@ -14,6 +13,7 @@ import ( "syscall" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" ) // Communicator is a special communicator that works by executing @@ -67,7 +67,7 @@ func (c *Communicator) Start(cmd *packer.RemoteCmd) error { func (c *Communicator) Upload(dst string, r io.Reader, fi *os.FileInfo) error { dst = filepath.Join(c.Chroot, dst) log.Printf("Uploading to chroot dir: %s", dst) - tf, err := ioutil.TempFile("", "packer-amazon-chroot") + tf, err := tmp.File("packer-amazon-chroot") if err != nil { return fmt.Errorf("Error preparing shell script: %s", err) } diff --git a/builder/docker/step_temp_dir.go b/builder/docker/step_temp_dir.go index a5b1d6ade..2db65bc3d 100644 --- a/builder/docker/step_temp_dir.go +++ b/builder/docker/step_temp_dir.go @@ -3,11 +3,11 @@ package docker import ( "context" "fmt" - "io/ioutil" "os" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" ) // StepTempDir creates a temporary directory that we use in order to @@ -21,13 +21,7 @@ func (s *StepTempDir) Run(_ context.Context, state multistep.StateBag) multistep ui.Say("Creating a temporary directory for sharing data...") - var err error - var tempdir string - - configTmpDir, err := packer.ConfigTmpDir() - if err == nil { - tempdir, err = ioutil.TempDir(configTmpDir, "packer-docker") - } + tempdir, err := tmp.Dir("packer-docker") if err != nil { err := fmt.Errorf("Error making temp dir: %s", err) state.Put("error", err) diff --git a/builder/docker/step_temp_dir_test.go b/builder/docker/step_temp_dir_test.go index e36d4fcff..a573726ec 100644 --- a/builder/docker/step_temp_dir_test.go +++ b/builder/docker/step_temp_dir_test.go @@ -3,11 +3,9 @@ package docker import ( "context" "os" - "path/filepath" "testing" "github.com/hashicorp/packer/helper/multistep" - "github.com/hashicorp/packer/packer" ) func TestStepTempDir_impl(t *testing.T) { @@ -52,46 +50,3 @@ func testStepTempDir_impl(t *testing.T) string { func TestStepTempDir(t *testing.T) { testStepTempDir_impl(t) } - -func TestStepTempDir_notmpdir(t *testing.T) { - tempenv := "PACKER_TMP_DIR" - - oldenv := os.Getenv(tempenv) - defer os.Setenv(tempenv, oldenv) - os.Setenv(tempenv, "") - - dir1 := testStepTempDir_impl(t) - - cd, err := packer.ConfigDir() - if err != nil { - t.Fatalf("bad ConfigDir") - } - td := filepath.Join(cd, "tmp") - os.Setenv(tempenv, td) - - dir2 := testStepTempDir_impl(t) - - if filepath.Dir(dir1) != filepath.Dir(dir2) { - t.Fatalf("temp base directories do not match: %s %s", filepath.Dir(dir1), filepath.Dir(dir2)) - } -} - -func TestStepTempDir_packertmpdir(t *testing.T) { - tempenv := "PACKER_TMP_DIR" - - oldenv := os.Getenv(tempenv) - defer os.Setenv(tempenv, oldenv) - os.Setenv(tempenv, ".") - - dir1 := testStepTempDir_impl(t) - - abspath, err := filepath.Abs(".") - if err != nil { - t.Fatalf("bad absolute path") - } - dir2 := filepath.Join(abspath, "tmp") - - if filepath.Dir(dir1) != filepath.Dir(dir2) { - t.Fatalf("temp base directories do not match: %s %s", filepath.Dir(dir1), filepath.Dir(dir2)) - } -} diff --git a/builder/hyperv/common/step_create_build_dir.go b/builder/hyperv/common/step_create_build_dir.go index 405a3407c..34148c41f 100644 --- a/builder/hyperv/common/step_create_build_dir.go +++ b/builder/hyperv/common/step_create_build_dir.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" ) type StepCreateBuildDir struct { @@ -29,12 +30,13 @@ func (s *StepCreateBuildDir) Run(_ context.Context, state multistep.StateBag) mu ui.Say("Creating build directory...") + var err error if s.TempPath == "" { - s.TempPath = os.TempDir() + s.buildDir, err = tmp.Dir("hyperv") + } else { + s.buildDir, err = ioutil.TempDir(s.TempPath, "hyperv") } - var err error - s.buildDir, err = ioutil.TempDir(s.TempPath, "packerhv") if err != nil { err = fmt.Errorf("Error creating build directory: %s", err) state.Put("error", err) diff --git a/builder/hyperv/common/step_create_build_dir_test.go b/builder/hyperv/common/step_create_build_dir_test.go index 3f0fe57cc..ab0c0c49a 100644 --- a/builder/hyperv/common/step_create_build_dir_test.go +++ b/builder/hyperv/common/step_create_build_dir_test.go @@ -38,7 +38,7 @@ func TestStepCreateBuildDir_Defaults(t *testing.T) { // This prevents the regexp interpreting backslashes as escape sequences stateBuildDir := filepath.ToSlash(v.(string)) expectedBuildDirRe := regexp.MustCompile( - filepath.ToSlash(filepath.Join(os.TempDir(), "packerhv") + `[[:digit:]]{9}$`)) + filepath.ToSlash(filepath.Join(os.TempDir(), "hyperv") + `[[:digit:]]{9}$`)) match := expectedBuildDirRe.MatchString(stateBuildDir) if !match { t.Fatalf("Got path that doesn't match expected format in 'build_dir': %s", stateBuildDir) @@ -79,7 +79,7 @@ func TestStepCreateBuildDir_UserDefinedTempPath(t *testing.T) { // This prevents the regexp interpreting backslashes as escape sequences stateBuildDir := filepath.ToSlash(v.(string)) expectedBuildDirRe := regexp.MustCompile( - filepath.ToSlash(filepath.Join(step.TempPath, "packerhv") + `[[:digit:]]{9}$`)) + filepath.ToSlash(filepath.Join(step.TempPath, "hyperv") + `[[:digit:]]{9}$`)) match := expectedBuildDirRe.MatchString(stateBuildDir) if !match { t.Fatalf("Got path that doesn't match expected format in 'build_dir': %s", stateBuildDir) diff --git a/builder/hyperv/common/step_mount_floppydrive.go b/builder/hyperv/common/step_mount_floppydrive.go index 1ae03d1db..31b4c794a 100644 --- a/builder/hyperv/common/step_mount_floppydrive.go +++ b/builder/hyperv/common/step_mount_floppydrive.go @@ -4,13 +4,13 @@ import ( "context" "fmt" "io" - "io/ioutil" "log" "os" "path/filepath" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" ) const ( @@ -93,7 +93,7 @@ func (s *StepMountFloppydrive) Cleanup(state multistep.StateBag) { } func (s *StepMountFloppydrive) copyFloppy(path string) (string, error) { - tempdir, err := ioutil.TempDir("", "packer") + tempdir, err := tmp.Dir("hyperv") if err != nil { return "", err } diff --git a/builder/hyperv/iso/builder_test.go b/builder/hyperv/iso/builder_test.go index 0369c0df7..124e1696c 100644 --- a/builder/hyperv/iso/builder_test.go +++ b/builder/hyperv/iso/builder_test.go @@ -5,12 +5,11 @@ package iso import ( "context" "fmt" + "os" "reflect" "strconv" "testing" - "os" - hypervcommon "github.com/hashicorp/packer/builder/hyperv/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" diff --git a/builder/lxc/communicator.go b/builder/lxc/communicator.go index c52c95d72..4968417b4 100644 --- a/builder/lxc/communicator.go +++ b/builder/lxc/communicator.go @@ -12,6 +12,7 @@ import ( "syscall" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" ) type LxcAttachCommunicator struct { @@ -60,7 +61,7 @@ func (c *LxcAttachCommunicator) Start(cmd *packer.RemoteCmd) error { func (c *LxcAttachCommunicator) Upload(dst string, r io.Reader, fi *os.FileInfo) error { log.Printf("Uploading to rootfs: %s", dst) - tf, err := ioutil.TempFile("", "packer-lxc-attach") + tf, err := tmp.File("packer-lxc-attach") if err != nil { return fmt.Errorf("Error uploading file to rootfs: %s", err) } diff --git a/builder/openstack/step_key_pair.go b/builder/openstack/step_key_pair.go index a850b8056..33fc7e769 100644 --- a/builder/openstack/step_key_pair.go +++ b/builder/openstack/step_key_pair.go @@ -13,6 +13,7 @@ import ( "github.com/hashicorp/packer/helper/communicator" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" "golang.org/x/crypto/ssh" ) @@ -137,13 +138,13 @@ func berToDer(ber []byte, ui packer.Ui) []byte { return ber } - berKey, err := ioutil.TempFile("", "packer-ber-privatekey-") + berKey, err := tmp.File("packer-ber-privatekey-") defer os.Remove(berKey.Name()) if err != nil { return ber } ioutil.WriteFile(berKey.Name(), ber, os.ModeAppend) - derKey, err := ioutil.TempFile("", "packer-der-privatekey-") + derKey, err := tmp.File("packer-der-privatekey-") defer os.Remove(derKey.Name()) if err != nil { return ber diff --git a/builder/parallels/common/driver_9.go b/builder/parallels/common/driver_9.go index 67600523a..77fa3ed5b 100644 --- a/builder/parallels/common/driver_9.go +++ b/builder/parallels/common/driver_9.go @@ -15,6 +15,7 @@ import ( "github.com/ChrisTrenkamp/goxpath" "github.com/ChrisTrenkamp/goxpath/tree/xmltree" + "github.com/hashicorp/packer/packer/tmp" ) // Parallels9Driver is a base type for Parallels builders. @@ -288,7 +289,7 @@ func (d *Parallels9Driver) SendKeyScanCodes(vmName string, codes ...string) erro return nil } - f, err := ioutil.TempFile("", "prltype") + f, err := tmp.File("prltype") if err != nil { return err } diff --git a/builder/virtualbox/common/step_attach_floppy.go b/builder/virtualbox/common/step_attach_floppy.go index 6c73aa4b4..6dac10349 100644 --- a/builder/virtualbox/common/step_attach_floppy.go +++ b/builder/virtualbox/common/step_attach_floppy.go @@ -4,13 +4,13 @@ import ( "context" "fmt" "io" - "io/ioutil" "log" "os" "path/filepath" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" ) // This step attaches the ISO to the virtual machine. @@ -106,7 +106,7 @@ func (s *StepAttachFloppy) Cleanup(state multistep.StateBag) { } func (s *StepAttachFloppy) copyFloppy(path string) (string, error) { - tempdir, err := ioutil.TempDir("", "packer") + tempdir, err := tmp.Dir("virtualbox") if err != nil { return "", err } diff --git a/builder/virtualbox/common/step_download_guest_additions.go b/builder/virtualbox/common/step_download_guest_additions.go index da413e994..bf324ae7a 100644 --- a/builder/virtualbox/common/step_download_guest_additions.go +++ b/builder/virtualbox/common/step_download_guest_additions.go @@ -5,7 +5,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "log" "os" "strings" @@ -13,6 +12,7 @@ import ( "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" "github.com/hashicorp/packer/template/interpolate" ) @@ -153,7 +153,7 @@ func (s *StepDownloadGuestAdditions) downloadAdditionsSHA256(ctx context.Context "https://download.virtualbox.org/virtualbox/%s/SHA256SUMS", additionsVersion) - checksumsFile, err := ioutil.TempFile("", "packer") + checksumsFile, err := tmp.File("packer") if err != nil { state.Put("error", fmt.Errorf( "Failed creating temporary file to store guest addition checksums: %s", diff --git a/builder/vmware/iso/step_create_vmx.go b/builder/vmware/iso/step_create_vmx.go index 5a46c14ef..6c056e17a 100644 --- a/builder/vmware/iso/step_create_vmx.go +++ b/builder/vmware/iso/step_create_vmx.go @@ -12,6 +12,7 @@ import ( vmwcommon "github.com/hashicorp/packer/builder/vmware/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" "github.com/hashicorp/packer/template/interpolate" ) @@ -417,7 +418,7 @@ func (s *stepCreateVMX) Run(_ context.Context, state multistep.StateBag) multist if config.RemoteType != "" { // For remote builds, we just put the VMX in a temporary // directory since it just gets uploaded anyways. - vmxDir, err = ioutil.TempDir("", "packer-vmx") + vmxDir, err = tmp.Dir("vmw-iso") if err != nil { err := fmt.Errorf("Error preparing VMX template: %s", err) state.Put("error", err) diff --git a/builder/vmware/iso/step_create_vmx_test.go b/builder/vmware/iso/step_create_vmx_test.go index 26605a1f5..6c621eae2 100644 --- a/builder/vmware/iso/step_create_vmx_test.go +++ b/builder/vmware/iso/step_create_vmx_test.go @@ -47,6 +47,7 @@ func tmpnam(prefix string) string { dir := os.TempDir() max := int(math.Pow(2, float64(length))) + // FIXME use ioutil.TempFile() or at least mimic implementation, this could loop forever n, err := rand.Intn(max), nil for path = filepath.Join(dir, prefix+strconv.Itoa(n)); err == nil; _, err = os.Stat(path) { n = rand.Intn(max) diff --git a/builder/vmware/vmx/step_clone_vmx.go b/builder/vmware/vmx/step_clone_vmx.go index c1fa5f65e..d48afdc8f 100644 --- a/builder/vmware/vmx/step_clone_vmx.go +++ b/builder/vmware/vmx/step_clone_vmx.go @@ -3,7 +3,6 @@ package vmx import ( "context" "fmt" - "io/ioutil" "log" "os" "path/filepath" @@ -12,6 +11,7 @@ import ( vmwcommon "github.com/hashicorp/packer/builder/vmware/common" "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" ) // StepCloneVMX takes a VMX file and clones the VM into the output directory. @@ -50,7 +50,7 @@ func (s *StepCloneVMX) Run(_ context.Context, state multistep.StateBag) multiste // * The disk compaction step needs the paths to all attached disks if remoteDriver, ok := driver.(vmwcommon.RemoteDriver); ok { remoteVmxPath := vmxPath - tempDir, err := ioutil.TempDir("", "packer-vmx") + tempDir, err := tmp.Dir("packer-vmx") if err != nil { return halt(err) } diff --git a/common/powershell/powershell.go b/common/powershell/powershell.go index 4c3dd80d1..a4b7f9b55 100644 --- a/common/powershell/powershell.go +++ b/common/powershell/powershell.go @@ -4,12 +4,13 @@ import ( "bytes" "fmt" "io" - "io/ioutil" "log" "os" "os/exec" "strconv" "strings" + + "github.com/hashicorp/packer/packer/tmp" ) const ( @@ -121,7 +122,7 @@ func (ps *PowerShellCmd) getPowerShellPath() (string, error) { } func saveScript(fileContents string) (string, error) { - file, err := ioutil.TempFile(os.TempDir(), "ps") + file, err := tmp.File("powershell") if err != nil { return "", err } diff --git a/common/shell-local/run.go b/common/shell-local/run.go index 6d3ecbb76..e1706f86d 100644 --- a/common/shell-local/run.go +++ b/common/shell-local/run.go @@ -3,7 +3,6 @@ package shell_local import ( "bufio" "fmt" - "io/ioutil" "log" "os" "runtime" @@ -13,6 +12,7 @@ import ( "github.com/hashicorp/packer/common" commonhelper "github.com/hashicorp/packer/helper/common" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" "github.com/hashicorp/packer/template/interpolate" ) @@ -107,7 +107,7 @@ func Run(ui packer.Ui, config *Config) (bool, error) { } func createInlineScriptFile(config *Config) (string, error) { - tf, err := ioutil.TempFile("", "packer-shell") + tf, err := tmp.File("packer-shell") if err != nil { return "", fmt.Errorf("Error preparing shell script: %s", err) } diff --git a/common/step_create_floppy.go b/common/step_create_floppy.go index dd4ead840..a2fa48885 100644 --- a/common/step_create_floppy.go +++ b/common/step_create_floppy.go @@ -4,7 +4,6 @@ import ( "context" "fmt" "io" - "io/ioutil" "log" "os" "path" @@ -13,6 +12,7 @@ import ( "github.com/hashicorp/packer/helper/multistep" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" "github.com/mitchellh/go-fs" "github.com/mitchellh/go-fs/fat" ) @@ -39,7 +39,7 @@ func (s *StepCreateFloppy) Run(_ context.Context, state multistep.StateBag) mult ui.Say("Creating floppy disk...") // Create a temporary file to be our floppy drive - floppyF, err := ioutil.TempFile("", "packer") + floppyF, err := tmp.File("packer") if err != nil { state.Put("error", fmt.Errorf("Error creating temporary file for floppy: %s", err)) diff --git a/communicator/ssh/communicator.go b/communicator/ssh/communicator.go index b08eec587..c5a582f82 100644 --- a/communicator/ssh/communicator.go +++ b/communicator/ssh/communicator.go @@ -16,6 +16,7 @@ import ( "time" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" "github.com/pkg/sftp" "golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh/agent" @@ -793,7 +794,7 @@ func scpUploadFile(dst string, src io.Reader, w io.Writer, r *bufio.Reader, fi * } else { // Create a temporary file where we can copy the contents of the src // so that we can determine the length, since SCP is length-prefixed. - tf, err := ioutil.TempFile("", "packer-upload") + tf, err := tmp.File("packer-upload") if err != nil { return fmt.Errorf("Error creating temporary file for upload: %s", err) } diff --git a/helper/communicator/testing.go b/helper/communicator/testing.go index 1c89f15e3..4f4894b6a 100644 --- a/helper/communicator/testing.go +++ b/helper/communicator/testing.go @@ -1,12 +1,13 @@ package communicator import ( - "io/ioutil" "testing" + + "github.com/hashicorp/packer/packer/tmp" ) func TestPEM(t *testing.T) string { - tf, err := ioutil.TempFile("", "packer") + tf, err := tmp.File("packer") if err != nil { t.Fatalf("err: %s", err) } diff --git a/main.go b/main.go index 16ec61b41..e7f750e2d 100644 --- a/main.go +++ b/main.go @@ -21,6 +21,7 @@ import ( "github.com/hashicorp/packer/command" "github.com/hashicorp/packer/packer" "github.com/hashicorp/packer/packer/plugin" + "github.com/hashicorp/packer/packer/tmp" "github.com/hashicorp/packer/version" "github.com/mitchellh/cli" "github.com/mitchellh/panicwrap" @@ -69,7 +70,7 @@ func realMain() int { // We always send logs to a temporary file that we use in case // there is a panic. Otherwise, we delete it. - logTempFile, err := ioutil.TempFile("", "packer-log") + logTempFile, err := tmp.File("packer-log") if err != nil { fmt.Fprintf(os.Stderr, "Couldn't setup logging tempfile: %s", err) return 1 diff --git a/packer/cache_test.go b/packer/cache_test.go index e4463e61d..8e0b0e761 100644 --- a/packer/cache_test.go +++ b/packer/cache_test.go @@ -5,6 +5,8 @@ import ( "os" "strings" "testing" + + "github.com/hashicorp/packer/packer/tmp" ) type TestCache struct{} @@ -30,7 +32,7 @@ func TestFileCache_Implements(t *testing.T) { } func TestFileCache(t *testing.T) { - cacheDir, err := ioutil.TempDir("", "packer") + cacheDir, err := tmp.Dir("packer") if err != nil { t.Fatalf("error creating temporary dir: %s", err) } diff --git a/packer/config_file.go b/packer/config_file.go index f95914230..1dbc69d54 100644 --- a/packer/config_file.go +++ b/packer/config_file.go @@ -21,29 +21,7 @@ func ConfigDir() (string, error) { return configDir() } -// ConfigTmpDir returns the configuration tmp directory for Packer -func ConfigTmpDir() (string, error) { - if tmpdir := os.Getenv("PACKER_TMP_DIR"); tmpdir != "" { - return filepath.Abs(tmpdir) - } - configdir, err := configDir() - if err != nil { - return "", err - } - td := filepath.Join(configdir, "tmp") - _, err = os.Stat(td) - if os.IsNotExist(err) { - if err = os.MkdirAll(td, 0755); err != nil { - return "", err - } - } else if err != nil { - return "", err - } - return td, nil -} - func homeDir() (string, error) { - // First prefer the HOME environmental variable if home := os.Getenv("HOME"); home != "" { log.Printf("Detected home directory from env var: %s", home) diff --git a/packer/plugin/server.go b/packer/plugin/server.go index 470daf950..22e74847e 100644 --- a/packer/plugin/server.go +++ b/packer/plugin/server.go @@ -10,7 +10,6 @@ package plugin import ( "errors" "fmt" - "io/ioutil" "log" "math/rand" "net" @@ -23,6 +22,7 @@ import ( "time" packrpc "github.com/hashicorp/packer/packer/rpc" + "github.com/hashicorp/packer/packer/tmp" ) // This is a count of the number of interrupts the process has received. @@ -125,7 +125,7 @@ func serverListener_tcp(minPort, maxPort int64) (net.Listener, error) { } func serverListener_unix() (net.Listener, error) { - tf, err := ioutil.TempFile("", "packer-plugin") + tf, err := tmp.File("packer-plugin") if err != nil { return nil, err } diff --git a/packer/tmp/tmp.go b/packer/tmp/tmp.go new file mode 100644 index 000000000..9ffb94ff0 --- /dev/null +++ b/packer/tmp/tmp.go @@ -0,0 +1,49 @@ +// Package tmp provides temporary directory helpers. +// +// tmp stores temporary items in the system's +// temporary directory ( see os.TempDir ). +// +// When the $TMPDIR_SUFFIX environment variable +// is set, tmp will return paths under $TMPDIR_SUFFIX +// inside the system temporary directory. +// +package tmp + +import ( + "io/ioutil" + "os" + "path/filepath" +) + +var tmpDir = os.TempDir() + +func init() { + if d := os.Getenv("TMPDIR_SUFFIX"); d != "" { + tmpDir = filepath.Join(tmpDir, d) + } +} + +// Dir creates a new temporary directory in the system temporary +// directory with a name beginning with prefix and returns the path +// of the new directory. +// Multiple programs calling Dir simultaneously +// will not choose the same directory. +// It is the caller's responsibility +// to remove the file when no longer needed. +func Dir(prefix string) (string, error) { + return ioutil.TempDir(tmpDir, prefix) +} + +// File creates a new temporary file in the system temporary +// directory, opens the file for reading and writing, and +// returns the resulting *os.File. +// The filename is generated by taking pattern and adding a random +// string to the end. If pattern includes a "*", the random string +// replaces the last "*". +// Multiple programs calling File simultaneously +// will not choose the same file. The caller can use f.Name() +// to find the pathname of the file. It is the caller's responsibility +// to remove the file when no longer needed. +func File(pattern string) (*os.File, error) { + return ioutil.TempFile(tmpDir, pattern) +} diff --git a/post-processor/vagrant/post-processor.go b/post-processor/vagrant/post-processor.go index 5ea07f3a3..72c2ab440 100644 --- a/post-processor/vagrant/post-processor.go +++ b/post-processor/vagrant/post-processor.go @@ -14,6 +14,7 @@ import ( "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" "github.com/hashicorp/packer/template/interpolate" "github.com/mitchellh/mapstructure" ) @@ -95,7 +96,7 @@ func (p *PostProcessor) PostProcessProvider(name string, provider Provider, ui p } // Create a temporary directory for us to build the contents of the box in - dir, err := ioutil.TempDir("", "packer") + dir, err := tmp.Dir("packer") if err != nil { return nil, false, err } diff --git a/post-processor/vagrant/virtualbox_test.go b/post-processor/vagrant/virtualbox_test.go index 5082c9388..3e46f59fe 100644 --- a/post-processor/vagrant/virtualbox_test.go +++ b/post-processor/vagrant/virtualbox_test.go @@ -1,11 +1,11 @@ package vagrant import ( - "io/ioutil" "os" "path/filepath" "testing" + "github.com/hashicorp/packer/packer/tmp" "github.com/stretchr/testify/assert" ) @@ -14,8 +14,10 @@ func TestVBoxProvider_impl(t *testing.T) { } func TestDecomressOVA(t *testing.T) { - td, err := ioutil.TempDir("", "pp-vagrant-virtualbox") + td, err := tmp.Dir("pp-vagrant-virtualbox") assert.NoError(t, err) + defer os.RemoveAll(td) + fixture := "../../common/test-fixtures/decompress-tar/outside_parent.tar" err = DecompressOva(td, fixture) assert.NoError(t, err) @@ -23,5 +25,4 @@ func TestDecomressOVA(t *testing.T) { assert.Error(t, err) _, err = os.Stat(filepath.Join(td, "demo.poc")) assert.NoError(t, err) - os.RemoveAll(td) } diff --git a/provisioner/ansible-local/provisioner.go b/provisioner/ansible-local/provisioner.go index bd4559388..c5219a5c4 100644 --- a/provisioner/ansible-local/provisioner.go +++ b/provisioner/ansible-local/provisioner.go @@ -2,7 +2,6 @@ package ansiblelocal import ( "fmt" - "io/ioutil" "os" "path/filepath" "strings" @@ -11,6 +10,7 @@ import ( "github.com/hashicorp/packer/common/uuid" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" "github.com/hashicorp/packer/template/interpolate" ) @@ -212,7 +212,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { } if len(p.config.InventoryFile) == 0 { - tf, err := ioutil.TempFile("", "packer-provisioner-ansible-local") + tf, err := tmp.File("packer-provisioner-ansible-local") if err != nil { return fmt.Errorf("Error preparing inventory file: %s", err) } diff --git a/provisioner/ansible/provisioner.go b/provisioner/ansible/provisioner.go index ee92b1161..e23322a6b 100644 --- a/provisioner/ansible/provisioner.go +++ b/provisioner/ansible/provisioner.go @@ -29,6 +29,7 @@ import ( commonhelper "github.com/hashicorp/packer/helper/common" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" "github.com/hashicorp/packer/template/interpolate" ) @@ -499,7 +500,7 @@ func newUserKey(pubKeyFile string) (*userKey, error) { Headers: nil, Bytes: privateKeyDer, } - tf, err := ioutil.TempFile("", "ansible-key") + tf, err := tmp.File("ansible-key") if err != nil { return nil, errors.New("failed to create temp file for generated key") } diff --git a/provisioner/ansible/scp.go b/provisioner/ansible/scp.go index 0d951c728..ca029605d 100644 --- a/provisioner/ansible/scp.go +++ b/provisioner/ansible/scp.go @@ -6,7 +6,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "os" "path/filepath" @@ -14,6 +13,7 @@ import ( "time" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" ) const ( @@ -43,7 +43,7 @@ func scpUploadSession(opts []byte, rest string, in io.Reader, out io.Writer, com return errors.New("no scp target specified") } - d, err := ioutil.TempDir("", "packer-ansible-upload") + d, err := tmp.Dir("ansible-upload") if err != nil { fmt.Fprintf(out, scpEmptyError) return err @@ -68,7 +68,7 @@ func scpDownloadSession(opts []byte, rest string, in io.Reader, out io.Writer, c return errors.New("no scp source specified") } - d, err := ioutil.TempDir("", "packer-ansible-download") + d, err := tmp.Dir("ansible-download") if err != nil { fmt.Fprintf(out, scpEmptyError) return err diff --git a/provisioner/powershell/provisioner.go b/provisioner/powershell/provisioner.go index 3888b3d26..89b1fe4c8 100644 --- a/provisioner/powershell/provisioner.go +++ b/provisioner/powershell/provisioner.go @@ -8,7 +8,6 @@ import ( "encoding/xml" "errors" "fmt" - "io/ioutil" "log" "os" "sort" @@ -20,6 +19,7 @@ import ( commonhelper "github.com/hashicorp/packer/helper/common" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" "github.com/hashicorp/packer/template/interpolate" ) @@ -233,7 +233,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { // Takes the inline scripts, concatenates them into a temporary file and // returns a string containing the location of said file. func extractScript(p *Provisioner) (string, error) { - temp, err := ioutil.TempFile(os.TempDir(), "packer-powershell-provisioner") + temp, err := tmp.File("powershell-provisioner") if err != nil { return "", err } diff --git a/provisioner/shell/provisioner.go b/provisioner/shell/provisioner.go index 9c401ae8e..f0eb325a4 100644 --- a/provisioner/shell/provisioner.go +++ b/provisioner/shell/provisioner.go @@ -7,7 +7,6 @@ import ( "errors" "fmt" "io" - "io/ioutil" "log" "math/rand" "os" @@ -18,6 +17,7 @@ import ( "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" "github.com/hashicorp/packer/template/interpolate" ) @@ -216,7 +216,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { // If we have an inline script, then turn that into a temporary // shell script and use that. if p.config.Inline != nil { - tf, err := ioutil.TempFile("", "packer-shell") + tf, err := tmp.File("packer-shell") if err != nil { return fmt.Errorf("Error preparing shell script: %s", err) } @@ -242,7 +242,7 @@ func (p *Provisioner) Provision(ui packer.Ui, comm packer.Communicator) error { } if p.config.UseEnvVarFile == true { - tf, err := ioutil.TempFile("", "packer-shell-vars") + tf, err := tmp.File("packer-shell-vars") if err != nil { return fmt.Errorf("Error preparing shell script: %s", err) } diff --git a/provisioner/windows-shell/provisioner.go b/provisioner/windows-shell/provisioner.go index 98b3b17e9..71fcc71d6 100644 --- a/provisioner/windows-shell/provisioner.go +++ b/provisioner/windows-shell/provisioner.go @@ -6,7 +6,6 @@ import ( "bufio" "errors" "fmt" - "io/ioutil" "log" "os" "sort" @@ -16,9 +15,11 @@ import ( "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/helper/config" "github.com/hashicorp/packer/packer" + "github.com/hashicorp/packer/packer/tmp" "github.com/hashicorp/packer/template/interpolate" ) +//FIXME query remote host or use %SYSTEMROOT%, %TEMP% and more creative filename const DefaultRemotePath = "c:/Windows/Temp/script.bat" var retryableSleep = 2 * time.Second @@ -157,7 +158,7 @@ func (p *Provisioner) Prepare(raws ...interface{}) error { // into a temporary file and returns a string containing the location // of said file. func extractScript(p *Provisioner) (string, error) { - temp, err := ioutil.TempFile(os.TempDir(), "packer-windows-shell-provisioner") + temp, err := tmp.File("windows-shell-provisioner") if err != nil { log.Printf("Unable to create temporary file for inline scripts: %s", err) return "", err diff --git a/template/parse.go b/template/parse.go index e0d06a2b4..a2d337300 100644 --- a/template/parse.go +++ b/template/parse.go @@ -6,13 +6,13 @@ import ( "encoding/json" "fmt" "io" - "io/ioutil" "os" "path/filepath" "sort" "strings" "github.com/hashicorp/go-multierror" + "github.com/hashicorp/packer/packer/tmp" "github.com/mitchellh/mapstructure" ) @@ -328,7 +328,7 @@ func ParseFile(path string) (*Template, error) { var err error if path == "-" { // Create a temp file for stdin in case of errors - f, err = ioutil.TempFile(os.TempDir(), "packer") + f, err = tmp.File("parse") if err != nil { return nil, err } diff --git a/website/source/docs/builders/docker.html.md b/website/source/docs/builders/docker.html.md index 2193aa7e0..a6179c639 100644 --- a/website/source/docs/builders/docker.html.md +++ b/website/source/docs/builders/docker.html.md @@ -380,8 +380,8 @@ portable provisioning scripts. ## Overriding the host directory -By default, Packer creates a temporary folder under your home directory, and -uses that to stage files for uploading into the container. If you would like to -change the path to this temporary folder, you can set the `PACKER_TMP_DIR` +By default, Packer creates a temporary folder under your system temporary directory, +and uses that to stage files for uploading into the container. If you would like to +change the path to this temporary folder, you can set the `TMP_DIR` environment variable. This can be useful, for example, if you have your home directory permissions set up to disallow access from the docker daemon. diff --git a/website/source/docs/other/environment-variables.html.md b/website/source/docs/other/environment-variables.html.md index cd36ef1ad..bd883804b 100644 --- a/website/source/docs/other/environment-variables.html.md +++ b/website/source/docs/other/environment-variables.html.md @@ -42,9 +42,13 @@ each can be found below: new versions of Packer. If you want to disable this for security or privacy reasons, you can set this environment variable to `1`. -- `TMPDIR` (Unix) / `TMP` (Windows) - The location of the directory used for - temporary files (defaults to `/tmp` on Linux/Unix and - `%USERPROFILE%\AppData\Local\Temp` on Windows Vista and above). It might be - necessary to customize it when working with large files since `/tmp` is a - memory-backed filesystem in some Linux distributions in which case - `/var/tmp` might be preferred. +- `TMPDIR` (Unix) / `TMP` `TEMP` `USERPROFILE` (Windows) - The location of + the directory used for temporary files (defaults to `/tmp` on Linux/Unix + and `%USERPROFILE%\AppData\Local\Temp` on Windows Vista and above). It + might be necessary to customize it when working with large files since + `/tmp` is a memory-backed filesystem in some Linux distributions in which + case `/var/tmp` might be preferred. + +- `TMPDIR_SUFFIX` - When set, packer will put temporary files under system + temporary directory + `TMPDIR_SUFFIX`. This allows to create & to give + specific rights to a directory ie: `chmod 777 $TMPDIR/$TMPDIR_SUFFIX/` From cecf352aa71229d62d106e65d8881ff34253f048 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Wed, 12 Dec 2018 18:52:25 +0100 Subject: [PATCH 2/4] remove any reference to TMPDIR_SUFFIX. Using system tempdir is enough --- packer/tmp/tmp.go | 19 ++++++++----------- .../docs/other/environment-variables.html.md | 4 ---- 2 files changed, 8 insertions(+), 15 deletions(-) diff --git a/packer/tmp/tmp.go b/packer/tmp/tmp.go index 9ffb94ff0..753c7c668 100644 --- a/packer/tmp/tmp.go +++ b/packer/tmp/tmp.go @@ -1,28 +1,25 @@ // Package tmp provides temporary directory helpers. // // tmp stores temporary items in the system's -// temporary directory ( see os.TempDir ). +// temporary directory ( see os.TempDir ) unless +// a corresponding environment variable is set.git // -// When the $TMPDIR_SUFFIX environment variable -// is set, tmp will return paths under $TMPDIR_SUFFIX -// inside the system temporary directory. +// On Unix systems, it uses $TMPDIR if non-empty, else /tmp. +// On Windows, it uses GetTempPath, returning the first non-empty +// value from %TMP%, %TEMP%, %USERPROFILE%, or the Windows directory. +// On Plan 9, it returns /tmp. // +// The directory is neither guaranteed to exist nor have accessible +// permissions. package tmp import ( "io/ioutil" "os" - "path/filepath" ) var tmpDir = os.TempDir() -func init() { - if d := os.Getenv("TMPDIR_SUFFIX"); d != "" { - tmpDir = filepath.Join(tmpDir, d) - } -} - // Dir creates a new temporary directory in the system temporary // directory with a name beginning with prefix and returns the path // of the new directory. diff --git a/website/source/docs/other/environment-variables.html.md b/website/source/docs/other/environment-variables.html.md index bd883804b..a9becdcf1 100644 --- a/website/source/docs/other/environment-variables.html.md +++ b/website/source/docs/other/environment-variables.html.md @@ -48,7 +48,3 @@ each can be found below: might be necessary to customize it when working with large files since `/tmp` is a memory-backed filesystem in some Linux distributions in which case `/var/tmp` might be preferred. - -- `TMPDIR_SUFFIX` - When set, packer will put temporary files under system - temporary directory + `TMPDIR_SUFFIX`. This allows to create & to give - specific rights to a directory ie: `chmod 777 $TMPDIR/$TMPDIR_SUFFIX/` From 323db6350d932c6c4ecd514881c791536665bbe5 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Wed, 12 Dec 2018 19:17:39 +0100 Subject: [PATCH 3/4] be clearer in docker docs on TMP dirs --- website/source/docs/builders/docker.html.md | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/website/source/docs/builders/docker.html.md b/website/source/docs/builders/docker.html.md index a6179c639..07cf6bf62 100644 --- a/website/source/docs/builders/docker.html.md +++ b/website/source/docs/builders/docker.html.md @@ -185,8 +185,8 @@ You must specify (only) one of `commit`, `discard`, or `export_path`. information see the [section on ECR](#amazon-ec2-container-registry). - `exec_user` (string) - Username or UID (format: - <name\|uid>\[:<group\|gid>\]) to run remote commands with. You - may need this if you get permission errors trying to run the `shell` or + <name\\\|uid>\[:<group\\\|gid>\]) to run remote commands with. + You may need this if you get permission errors trying to run the `shell` or other provisioners. - `login` (boolean) - Defaults to false. If true, the builder will login in @@ -380,8 +380,9 @@ portable provisioning scripts. ## Overriding the host directory -By default, Packer creates a temporary folder under your system temporary directory, -and uses that to stage files for uploading into the container. If you would like to -change the path to this temporary folder, you can set the `TMP_DIR` -environment variable. This can be useful, for example, if you have your home -directory permissions set up to disallow access from the docker daemon. +By default, Packer creates a temporary folder under your system temporary +directory, and uses that to stage files for uploading into the container. If +you would like to change the path to this temporary folder, you can set +environment variable `TMPDIR` (Unix) / `TMP` `TEMP` `USERPROFILE` (Windows) . +This can be useful, for example, if you have your home directory permissions +set up to disallow access from the docker daemon. From 848d4e981ba3bd4950807750e7334e45ee09db8e Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Wed, 9 Jan 2019 16:30:43 +0100 Subject: [PATCH 4/4] clarify comments --- packer/tmp/tmp.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packer/tmp/tmp.go b/packer/tmp/tmp.go index 753c7c668..147673b9f 100644 --- a/packer/tmp/tmp.go +++ b/packer/tmp/tmp.go @@ -1,8 +1,8 @@ // Package tmp provides temporary directory helpers. // // tmp stores temporary items in the system's -// temporary directory ( see os.TempDir ) unless -// a corresponding environment variable is set.git +// temporary directory unless a corresponding +// environment variable is set ( see os.TempDir ). // // On Unix systems, it uses $TMPDIR if non-empty, else /tmp. // On Windows, it uses GetTempPath, returning the first non-empty