Skip to content

Commit

Permalink
Set default storage from containers.conf for temporary images
Browse files Browse the repository at this point in the history
Fixes: containers#11107

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
  • Loading branch information
rhatdan committed Sep 15, 2021
1 parent 81f41ca commit 3e77f96
Show file tree
Hide file tree
Showing 13 changed files with 162 additions and 72 deletions.
6 changes: 5 additions & 1 deletion cmd/podman/root.go
Expand Up @@ -174,7 +174,11 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error {
}
// Hard code TMPDIR functions to use /var/tmp, if user did not override
if _, ok := os.LookupEnv("TMPDIR"); !ok {
os.Setenv("TMPDIR", "/var/tmp")
if tmpdir, err := cfg.ImageCopyTmpDir(); err != nil {
logrus.Warnf("failed to retrieve default tmp dir: %s", err.Error())
} else {
os.Setenv("TMPDIR", tmpdir)
}
}

context := cmd.Root().LocalFlags().Lookup("context")
Expand Down
1 change: 1 addition & 0 deletions contrib/tmpfile/podman.conf
Expand Up @@ -3,5 +3,6 @@
x /tmp/podman-run-*
x /tmp/containers-user-*
x /tmp/run-*/libpod
D! /var/lib/containers/storage/tmp 0700 root root
D! /run/podman 0700 root root
D! /var/lib/cni/networks
112 changes: 51 additions & 61 deletions docs/source/markdown/podman-info.1.md
Expand Up @@ -31,7 +31,7 @@ Run podman info with plain text response:
$ podman info
host:
arch: amd64
buildahVersion: 1.22.3
buildahVersion: 1.23.0
cgroupControllers: []
cgroupManager: systemd
cgroupVersion: v2
Expand Down Expand Up @@ -64,7 +64,7 @@ host:
kernel: 5.13.13-200.fc34.x86_64
linkmode: dynamic
logDriver: journald
memFree: 1351262208
memFree: 1833385984
memTotal: 16401895424
ociRuntime:
name: crun
Expand Down Expand Up @@ -95,9 +95,9 @@ host:
libslirp: 4.4.0
SLIRP_CONFIG_VERSION_MAX: 3
libseccomp: 2.5.0
swapFree: 16818888704
swapFree: 15687475200
swapTotal: 16886259712
uptime: 33h 57m 32.85s (Approximately 1.38 days)
uptime: 47h 15m 9.91s (Approximately 1.96 days)
plugins:
log:
- k8s-file
Expand All @@ -109,24 +109,18 @@ plugins:
volume:
- local
registries:
localhost:5000:
Blocked: false
Insecure: true
Location: localhost:5000
MirrorByDigestOnly: false
Mirrors: null
Prefix: localhost:5000
search:
- registry.fedoraproject.org
- registry.access.redhat.com
- docker.io
- quay.io
store:
configFile: /home/dwalsh/.config/containers/storage.conf
containerStore:
number: 2
number: 9
paused: 0
running: 1
stopped: 1
stopped: 8
graphDriverName: overlay
graphOptions: {}
graphRoot: /home/dwalsh/.local/share/containers/storage
Expand All @@ -135,26 +129,27 @@ store:
Native Overlay Diff: "true"
Supports d_type: "true"
Using metacopy: "false"
imageCopyTmpDir: /home/dwalsh/.local/share/containers/storage/tmp
imageStore:
number: 37
number: 5
runRoot: /run/user/3267/containers
volumePath: /home/dwalsh/.local/share/containers/storage/volumes
version:
APIVersion: 3.3.1
Built: 1631137208
BuiltTime: Wed Sep 8 17:40:08 2021
GitCommit: ab272d1e9bf4daac224fb230e0c9b5c56c4cab4d-dirty
APIVersion: 4.0.0
Built: 1631648722
BuiltTime: Tue Sep 14 15:45:22 2021
GitCommit: 23677f92dd83e96d2bc8f0acb611865fb8b1a56d
GoVersion: go1.16.6
OsArch: linux/amd64
Version: 3.3.1
Version: 4.0.0
```
Run podman info with JSON formatted response:
```
$ ./bin/podman info --format json
$ podman info --format json
{
"host": {
"arch": "amd64",
"buildahVersion": "1.22.3",
"buildahVersion": "1.23.0",
"cgroupManager": "systemd",
"cgroupVersion": "v2",
"cgroupControllers": [],
Expand All @@ -172,33 +167,33 @@ $ ./bin/podman info --format json
"hostname": "localhost.localdomain",
"idMappings": {
"gidmap": [
{
"container_id": 0,
"host_id": 3267,
"size": 1
},
{
"container_id": 1,
"host_id": 100000,
"size": 65536
}
{
"container_id": 0,
"host_id": 3267,
"size": 1
},
{
"container_id": 1,
"host_id": 100000,
"size": 65536
}
],
"uidmap": [
{
"container_id": 0,
"host_id": 3267,
"size": 1
},
{
"container_id": 1,
"host_id": 100000,
"size": 65536
}
{
"container_id": 0,
"host_id": 3267,
"size": 1
},
{
"container_id": 1,
"host_id": 100000,
"size": 65536
}
]
},
"kernel": "5.13.13-200.fc34.x86_64",
"logDriver": "journald",
"memFree": 1274040320,
"memFree": 1785753600,
"memTotal": 16401895424,
"ociRuntime": {
"name": "crun",
Expand All @@ -224,21 +219,22 @@ $ ./bin/podman info --format json
"package": "slirp4netns-1.1.12-2.fc34.x86_64",
"version": "slirp4netns version 1.1.12\ncommit: 7a104a101aa3278a2152351a082a6df71f57c9a3\nlibslirp: 4.4.0\nSLIRP_CONFIG_VERSION_MAX: 3\nlibseccomp: 2.5.0"
},
"swapFree": 16818888704,
"swapFree": 15687475200,
"swapTotal": 16886259712,
"uptime": "33h 59m 25.69s (Approximately 1.38 days)",
"uptime": "47h 17m 29.75s (Approximately 1.96 days)",
"linkmode": "dynamic"
},
"store": {
"configFile": "/home/dwalsh/.config/containers/storage.conf",
"containerStore": {
"number": 2,
"number": 9,
"paused": 0,
"running": 1,
"stopped": 1
"stopped": 8
},
"graphDriverName": "overlay",
"graphOptions": {
},
"graphRoot": "/home/dwalsh/.local/share/containers/storage",
"graphStatus": {
Expand All @@ -247,25 +243,19 @@ $ ./bin/podman info --format json
"Supports d_type": "true",
"Using metacopy": "false"
},
"imageCopyTmpDir": "/home/dwalsh/.local/share/containers/storage/tmp",
"imageStore": {
"number": 37
"number": 5
},
"runRoot": "/run/user/3267/containers",
"volumePath": "/home/dwalsh/.local/share/containers/storage/volumes"
},
"registries": {
"localhost:5000": {
"Prefix": "localhost:5000",
"Location": "localhost:5000",
"Insecure": true,
"Mirrors": null,
"Blocked": false,
"MirrorByDigestOnly": false
},
"search": [
"registry.fedoraproject.org",
"registry.access.redhat.com",
"docker.io"
"docker.io",
"quay.io"
]
},
"plugins": {
Expand All @@ -283,12 +273,12 @@ $ ./bin/podman info --format json
]
},
"version": {
"APIVersion": "3.3.1",
"Version": "3.3.1",
"APIVersion": "4.0.0",
"Version": "4.0.0",
"GoVersion": "go1.16.6",
"GitCommit": "",
"BuiltTime": "Mon Aug 30 16:46:36 2021",
"Built": 1630356396,
"GitCommit": "23677f92dd83e96d2bc8f0acb611865fb8b1a56d",
"BuiltTime": "Tue Sep 14 15:45:22 2021",
"Built": 1631648722,
"OsArch": "linux/amd64"
}
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Expand Up @@ -12,7 +12,7 @@ require (
github.com/containernetworking/cni v0.8.1
github.com/containernetworking/plugins v0.9.1
github.com/containers/buildah v1.23.0
github.com/containers/common v0.44.0
github.com/containers/common v0.44.1-0.20210914173811-fcaa2e0de285
github.com/containers/conmon v2.0.20+incompatible
github.com/containers/image/v5 v5.16.0
github.com/containers/ocicrypt v1.1.2
Expand Down
3 changes: 2 additions & 1 deletion go.sum
Expand Up @@ -246,8 +246,9 @@ github.com/containernetworking/plugins v0.9.1 h1:FD1tADPls2EEi3flPc2OegIY1M9pUa9
github.com/containernetworking/plugins v0.9.1/go.mod h1:xP/idU2ldlzN6m4p5LmGiwRDjeJr6FLK6vuiUwoH7P8=
github.com/containers/buildah v1.23.0 h1:qGIeSNOczUHzvnaaOS29HSMiYAjw6JgIXYksAyvqnLs=
github.com/containers/buildah v1.23.0/go.mod h1:K0iMKgy/MffkkgELBXhSXwTy2HTT6hM0X8qruDR1FwU=
github.com/containers/common v0.44.0 h1:YpjfOxmWrnVyxugYgiWV1Vo/Xg8JUfe32QZz3SAMfUk=
github.com/containers/common v0.44.0/go.mod h1:7sdP4vmI5Bm6FPFxb3lvAh1Iktb6tiO1MzjUzhxdoGo=
github.com/containers/common v0.44.1-0.20210914173811-fcaa2e0de285 h1:sXBzh8CcqR5cGGY9cM/AUIk58CJKHbyljVtFh8HYyLY=
github.com/containers/common v0.44.1-0.20210914173811-fcaa2e0de285/go.mod h1:7sdP4vmI5Bm6FPFxb3lvAh1Iktb6tiO1MzjUzhxdoGo=
github.com/containers/conmon v2.0.20+incompatible h1:YbCVSFSCqFjjVwHTPINGdMX1F6JXHGTUje2ZYobNrkg=
github.com/containers/conmon v2.0.20+incompatible/go.mod h1:hgwZ2mtuDrppv78a/cOBNiCm6O0UMWGx1mu7P00nu5I=
github.com/containers/image/v5 v5.16.0 h1:WQcNSzb7+ngS2cfynx0vUwhk+scpgiKlldVcsF8GPbI=
Expand Down
1 change: 1 addition & 0 deletions libpod/define/info.go
Expand Up @@ -108,6 +108,7 @@ type StoreInfo struct {
GraphOptions map[string]interface{} `json:"graphOptions"`
GraphRoot string `json:"graphRoot"`
GraphStatus map[string]string `json:"graphStatus"`
ImageCopyTmpDir string `json:"imageCopyTmpDir"`
ImageStore ImageStore `json:"imageStore"`
RunRoot string `json:"runRoot"`
VolumePath string `json:"volumePath"`
Expand Down
1 change: 1 addition & 0 deletions libpod/info.go
Expand Up @@ -288,6 +288,7 @@ func (r *Runtime) storeInfo() (*define.StoreInfo, error) {

info := define.StoreInfo{
ImageStore: imageInfo,
ImageCopyTmpDir: os.Getenv("TMPDIR"),
ContainerStore: conInfo,
GraphRoot: r.store.GraphRoot(),
RunRoot: r.store.RunRoot(),
Expand Down
47 changes: 47 additions & 0 deletions test/e2e/containers_conf_test.go
Expand Up @@ -397,4 +397,51 @@ var _ = Describe("Podman run", func() {
Expect(session).Should(Exit(0))
Expect(session.OutputToString()).To(Equal(profile))
})

It("podman info image_copy_tmp_dir", func() {
session := podmanTest.Podman([]string{"info", "--format", "{{.Store.ImageCopyTmpDir}}"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(session.OutputToString()).To(Equal("/var/tmp"))

configPath := filepath.Join(podmanTest.TempDir, "containers.conf")
os.Setenv("CONTAINERS_CONF", configPath)

containersConf := []byte(fmt.Sprintf("[engine]\nimage_copy_tmp_dir=\"/foobar\""))
err = ioutil.WriteFile(configPath, containersConf, os.ModePerm)
Expect(err).To(BeNil())

if IsRemote() {
podmanTest.RestartRemoteService()
}

session = podmanTest.Podman([]string{"info", "--format", "{{.Store.ImageCopyTmpDir}}"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(session.OutputToString()).To(Equal("/foobar"))

containersConf = []byte(fmt.Sprintf("[engine]\nimage_copy_tmp_dir=\"storage\""))
err = ioutil.WriteFile(configPath, containersConf, os.ModePerm)
Expect(err).To(BeNil())
if IsRemote() {
podmanTest.RestartRemoteService()
}

session = podmanTest.Podman([]string{"info", "--format", "{{.Store.ImageCopyTmpDir}}"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(session.LineInOutputContains("containers/storage/tmp")).To(BeTrue())

containersConf = []byte(fmt.Sprintf("[engine]\nimage_copy_tmp_dir=\"storage1\""))
err = ioutil.WriteFile(configPath, containersConf, os.ModePerm)
Expect(err).To(BeNil())
if IsRemote() {
podmanTest.RestartRemoteService()
}

session = podmanTest.Podman([]string{"info", "--format", "{{.Store.ImageCopyTmpDir}}"})
session.WaitWithDefaultTimeout()
Expect(session).Should(Exit(0))
Expect(session.ErrorToString()).To(ContainSubstring("invalid image_copy_tmp_dir"))
})
})
28 changes: 28 additions & 0 deletions vendor/github.com/containers/common/pkg/config/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3e77f96

Please sign in to comment.