Skip to content

Commit

Permalink
Use TMPDIR when commiting images
Browse files Browse the repository at this point in the history
Fixes: containers#9825

Currently we are using TMPDIR for storaing temporary files
when building images, but not when you directly commit the images.

This change simply uses the TMPDIR environment variable if set
to store temporary files.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
  • Loading branch information
rhatdan authored and jmguzik committed Apr 26, 2021
1 parent 49e824b commit 26c79da
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions libpod/image/docker_registry_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func GetSystemContext(signaturePolicyPath, authFilePath string, forceCompress bo
sc.AuthFilePath = authFilePath
sc.DirForceCompress = forceCompress
sc.DockerRegistryUserAgent = fmt.Sprintf("libpod/%s", podmanVersion.Version)
sc.BigFilesTemporaryDir = parse.GetTempDir()

return sc
}
23 changes: 23 additions & 0 deletions libpod/image/image_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/containers/podman/v3/libpod/events"
"github.com/containers/podman/v3/pkg/util"
podmanVersion "github.com/containers/podman/v3/version"
"github.com/containers/storage"
"github.com/containers/storage/pkg/reexec"
"github.com/opencontainers/go-digest"
Expand Down Expand Up @@ -293,3 +294,25 @@ func TestNormalizedTag(t *testing.T) {
}
}
}

func TestGetSystemContext(t *testing.T) {
sc := GetSystemContext("", "", false)
assert.Equal(t, sc.SignaturePolicyPath, "")
assert.Equal(t, sc.AuthFilePath, "")
assert.Equal(t, sc.DirForceCompress, false)
assert.Equal(t, sc.DockerRegistryUserAgent, fmt.Sprintf("libpod/%s", podmanVersion.Version))
assert.Equal(t, sc.BigFilesTemporaryDir, "/var/tmp")

oldtmpdir := os.Getenv("TMPDIR")
os.Setenv("TMPDIR", "/mnt")
sc = GetSystemContext("/tmp/foo", "/tmp/bar", true)
assert.Equal(t, sc.SignaturePolicyPath, "/tmp/foo")
assert.Equal(t, sc.AuthFilePath, "/tmp/bar")
assert.Equal(t, sc.DirForceCompress, true)
assert.Equal(t, sc.BigFilesTemporaryDir, "/mnt")
if oldtmpdir != "" {
os.Setenv("TMPDIR", oldtmpdir)
} else {
os.Unsetenv("TMPDIR")
}
}

0 comments on commit 26c79da

Please sign in to comment.