Skip to content

Commit

Permalink
Add support for image_copy_tmp_dir
Browse files Browse the repository at this point in the history
Allow users to set the default location for the temporary files used
during image pulls and pushes.

Defaults to /var/tmp;

Overridden via "TMPDIR" environment variable.

Allow special flag "storage" to indicate the the storage should use
the tmp directory in containers/storage/tmp.

Needed to fix: containers/podman#11107

Signed-off-by: Daniel J Walsh <[email protected]>
  • Loading branch information
rhatdan committed Sep 9, 2021
1 parent f907b47 commit 7030dc0
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/containers.conf.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,12 @@ The list of OCI runtimes that support running containers with KVM separation.

The list of OCI runtimes that support running containers without CGroups.

**image_copy_tmp_dir**="/var/tmp"

Default location for storing temporary container image content. Can be
overridden with the TMPDIR environment variable. If you specify "storage", then
the location of the container/storage tmp directory will be used.

**static_dir**="/var/lib/containers/storage/libpod"

Directory for persistent libpod files (database, etc).
Expand Down
8 changes: 8 additions & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,8 @@ type EngineConfig struct {
// EventsLogger determines where events should be logged.
EventsLogger string `toml:"events_logger,omitempty"`

// graphRoot internal stores the location of the graphroot
graphRoot string
// configuration files. When the same filename is present in in
// multiple directories, the file in the directory listed last in
// this slice takes precedence.
Expand Down Expand Up @@ -380,6 +382,12 @@ type EngineConfig struct {
// before sending kill signal.
StopTimeout uint `toml:"stop_timeout,omitempty"`

// ImageCopyTmpDir is the default location for storing temporary
// container image content, Can be overridden with the TMPDIR
// environment variable. If you specify "storage", then the
// location of the container/storage tmp directory will be used.
ImageCopyTmpDir string `toml:"image_copy_tmp_dir,omitempty"`

// TmpDir is the path to a temporary directory to store per-boot container
// files. Must be stored in a tmpfs.
TmpDir string `toml:"tmp_dir,omitempty"`
Expand Down
27 changes: 27 additions & 0 deletions pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var _ = Describe("Config", func() {
gomega.Expect(err).To(gomega.BeNil())
gomega.Expect(defaultConfig.Containers.ApparmorProfile).To(gomega.Equal(apparmor.Profile))
gomega.Expect(defaultConfig.Containers.PidsLimit).To(gomega.BeEquivalentTo(2048))
gomega.Expect(defaultConfig.ImageCopyTmpDir()).To(gomega.BeEquivalentTo("/var/tmp"))
})

It("should succeed with devices", func() {
Expand Down Expand Up @@ -107,6 +108,31 @@ var _ = Describe("Config", func() {
})
})

Describe("readStorageTmp", func() {
It("test image_copy_tmp_dir='storage'", func() {
// Reload from new configuration file
testFile := "testdata/temp.conf"
content := `[engine]
image_copy_tmp_dir="storage"`
err := ioutil.WriteFile(testFile, []byte(content), os.ModePerm)
// Then
gomega.Expect(err).To(gomega.BeNil())
defer os.Remove(testFile)

config, _ := NewConfig(testFile)
gomega.Expect(config.ImageCopyTmpDir()).To(gomega.ContainSubstring("containers/storage/tmp"))
// Given we do
oldTMPDIR, set := os.LookupEnv("TMPDIR")
os.Setenv("TMPDIR", "/var/tmp/foobar")
gomega.Expect(config.ImageCopyTmpDir()).To(gomega.BeEquivalentTo("/var/tmp/foobar"))
if set {
os.Setenv("TMPDIR", oldTMPDIR)
} else {
os.Unsetenv("TMPDIR")
}
})
})

Describe("readConfigFromFile", func() {
It("should succeed with default config", func() {
// Given
Expand Down Expand Up @@ -327,6 +353,7 @@ var _ = Describe("Config", func() {
gomega.Expect(config.Containers.LogSizeMax).To(gomega.Equal(int64(100000)))
gomega.Expect(config.Engine.ImageParallelCopies).To(gomega.Equal(uint(10)))
gomega.Expect(config.Engine.ImageDefaultFormat).To(gomega.Equal("v2s2"))
gomega.Expect(config.ImageCopyTmpDir()).To(gomega.BeEquivalentTo("/tmp/foobar"))
})

It("should fail with invalid value", func() {
Expand Down
5 changes: 5 additions & 0 deletions pkg/config/containers.conf
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,11 @@ default_sysctls = [
#
#runtime_supports_nocgroups = ["crun"]

# Default location for storing temporary container image content, Can be overridden with the TMPDIR environment
# variable. If you specify "storage", then the location of the
# container/storage tmp directory will be used.
# image_copy_tmp_dir="/var/tmp"

# Directory for persistent engine files (database, etc)
# By default, this will be configured relative to where the containers/storage
# stores containers
Expand Down
13 changes: 13 additions & 0 deletions pkg/config/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,8 @@ func defaultConfigFromMemory() (*EngineConfig, error) {
logrus.Warnf("Storage configuration is unset - using hardcoded default graph root %q", _defaultGraphRoot)
storeOpts.GraphRoot = _defaultGraphRoot
}
c.graphRoot = storeOpts.GraphRoot
c.ImageCopyTmpDir = "/var/tmp"
c.StaticDir = filepath.Join(storeOpts.GraphRoot, "libpod")
c.VolumePath = filepath.Join(storeOpts.GraphRoot, "volumes")

Expand Down Expand Up @@ -562,3 +564,14 @@ func (c *Config) RootlessNetworking() string {
func (c *Config) MachineImage() string {
return c.Engine.MachineImage
}

// ImageCopyTmpDir default storage tmpdir
func (c *Config) ImageCopyTmpDir() string {
if path, found := os.LookupEnv("TMPDIR"); found {
return path
}
if c.Engine.ImageCopyTmpDir == "storage" {
return filepath.Join(c.Engine.graphRoot, "tmp")
}
return c.Engine.ImageCopyTmpDir
}
3 changes: 3 additions & 0 deletions pkg/config/testdata/containers_default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ conmon_env_vars = [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
]

image_copy_tmp_dir="storage"


# Paths to look for the Conmon container manager binary
conmon_path = [
"/usr/libexec/podman/conmon",
Expand Down
1 change: 1 addition & 0 deletions pkg/config/testdata/containers_override.conf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ log_size_max = 100000
[engine]
image_parallel_copies=10
image_default_format="v2s2"
image_copy_tmp_dir="/tmp/foobar"

[secrets]
driver = "pass"
Expand Down

0 comments on commit 7030dc0

Please sign in to comment.