Docker needs a temporary dir that is inside the $HOME dir
This commit is contained in:
parent
4fef738363
commit
f57953d4ff
|
@ -4,10 +4,10 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
|
||||||
"github.com/hashicorp/packer/helper/multistep"
|
"github.com/hashicorp/packer/helper/multistep"
|
||||||
"github.com/hashicorp/packer/packer"
|
"github.com/hashicorp/packer/packer"
|
||||||
"github.com/hashicorp/packer/packer/tmp"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// StepTempDir creates a temporary directory that we use in order to
|
// StepTempDir creates a temporary directory that we use in order to
|
||||||
|
@ -16,12 +16,33 @@ type StepTempDir struct {
|
||||||
tempDir string
|
tempDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ConfigTmpDir returns the configuration tmp directory for Docker
|
||||||
|
func ConfigTmpDir() (string, error) {
|
||||||
|
if tmpdir := os.Getenv("PACKER_TMP_DIR"); tmpdir != "" {
|
||||||
|
return filepath.Abs(tmpdir)
|
||||||
|
}
|
||||||
|
configdir, err := packer.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 (s *StepTempDir) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
func (s *StepTempDir) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
|
||||||
ui := state.Get("ui").(packer.Ui)
|
ui := state.Get("ui").(packer.Ui)
|
||||||
|
|
||||||
ui.Say("Creating a temporary directory for sharing data...")
|
ui.Say("Creating a temporary directory for sharing data...")
|
||||||
|
|
||||||
tempdir, err := tmp.Dir("packer-docker")
|
tempdir, err := ConfigTmpDir()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
err := fmt.Errorf("Error making temp dir: %s", err)
|
err := fmt.Errorf("Error making temp dir: %s", err)
|
||||||
state.Put("error", err)
|
state.Put("error", err)
|
||||||
|
|
|
@ -380,9 +380,8 @@ portable provisioning scripts.
|
||||||
|
|
||||||
## Overriding the host directory
|
## Overriding the host directory
|
||||||
|
|
||||||
By default, Packer creates a temporary folder under your system temporary
|
By default, Packer creates a temporary folder under your home directory, and
|
||||||
directory, and uses that to stage files for uploading into the container. If
|
uses that to stage files for uploading into the container. If you would like to
|
||||||
you would like to change the path to this temporary folder, you can set
|
change the path to this temporary folder, you can set the `PACKER_TMP_DIR`.
|
||||||
environment variable `TMPDIR` (Unix) / `TMP` `TEMP` `USERPROFILE` (Windows) .
|
|
||||||
This can be useful, for example, if you have your home directory permissions
|
This can be useful, for example, if you have your home directory permissions
|
||||||
set up to disallow access from the docker daemon.
|
set up to disallow access from the docker daemon.
|
||||||
|
|
Loading…
Reference in New Issue