Skip to content

Commit

Permalink
Merge pull request #22529 from dcermak/substitute-home-in-runlabel
Browse files Browse the repository at this point in the history
Also substitute $HOME in runlabel with user's homedir
  • Loading branch information
openshift-merge-bot[bot] authored May 6, 2024
2 parents 07d8b32 + 46f247d commit f1b8439
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
7 changes: 7 additions & 0 deletions pkg/domain/infra/abi/containers_runlabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,13 @@ func generateRunlabelCommand(runlabel string, img *libimage.Image, inputName str
return ""
}
return d
case "HOME":
h, err := os.UserHomeDir()
if err != nil {
logrus.Warnf("Unable to determine user's home directory: %s", err)
return ""
}
return h
}
return ""
}
Expand Down
6 changes: 3 additions & 3 deletions test/system/037-runlabel.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ load helpers
rand3=$(random_string 30)
cat >$containerfile <<EOF
FROM $IMAGE
LABEL INSTALL podman run -t -i --rm \\\${OPT1} --privileged -v /:/host --net=host --ipc=host --pid=host -e HOST=/host -e NAME=\\\${NAME} -e IMAGE=\\\${IMAGE} -e CONFDIR=/etc/\\\${NAME} -e LOGDIR=/var/log/\\\${NAME} -e DATADIR=/var/lib/\\\${NAME} \\\${IMAGE} \\\${OPT2} /bin/install.sh \\\${OPT3}
LABEL INSTALL podman run -t -i --rm \\\${OPT1} --privileged -v /:/host --net=host --ipc=host --pid=host -e HOST=/host -e HOMEDIR=\\\$HOME -e NAME=\\\${NAME} -e IMAGE=\\\${IMAGE} -e CONFDIR=/etc/\\\${NAME} -e LOGDIR=/var/log/\\\${NAME} -e DATADIR=/var/lib/\\\${NAME} \\\${IMAGE} \\\${OPT2} /bin/install.sh \\\${OPT3}
EOF

run_podman build -t runlabel_image $tmpdir

run_podman container runlabel --opt1=${rand1} --opt2=${rand2} --opt3=${rand3} --name test1 --display install runlabel_image
is "$output" "command: ${PODMAN} run -t -i --rm ${rand1} --privileged -v /:/host --net=host --ipc=host --pid=host -e HOST=/host -e NAME=test1 -e IMAGE=localhost/runlabel_image:latest -e CONFDIR=/etc/test1 -e LOGDIR=/var/log/test1 -e DATADIR=/var/lib/test1 localhost/runlabel_image:latest ${rand2} /bin/install.sh ${rand3}" "generating runlabel install command"
is "$output" "command: ${PODMAN} run -t -i --rm ${rand1} --privileged -v /:/host --net=host --ipc=host --pid=host -e HOST=/host -e HOMEDIR=${HOME} -e NAME=test1 -e IMAGE=localhost/runlabel_image:latest -e CONFDIR=/etc/test1 -e LOGDIR=/var/log/test1 -e DATADIR=/var/lib/test1 localhost/runlabel_image:latest ${rand2} /bin/install.sh ${rand3}" "generating runlabel install command"

run_podman container runlabel --opt3=${rand3} --display install runlabel_image
is "$output" "command: ${PODMAN} run -t -i --rm --privileged -v /:/host --net=host --ipc=host --pid=host -e HOST=/host -e NAME=runlabel_image -e IMAGE=localhost/runlabel_image:latest -e CONFDIR=/etc/runlabel_image -e LOGDIR=/var/log/runlabel_image -e DATADIR=/var/lib/runlabel_image localhost/runlabel_image:latest /bin/install.sh ${rand3}" "generating runlabel without name and --opt1, --opt2"
is "$output" "command: ${PODMAN} run -t -i --rm --privileged -v /:/host --net=host --ipc=host --pid=host -e HOST=/host -e HOMEDIR=${HOME} -e NAME=runlabel_image -e IMAGE=localhost/runlabel_image:latest -e CONFDIR=/etc/runlabel_image -e LOGDIR=/var/log/runlabel_image -e DATADIR=/var/lib/runlabel_image localhost/runlabel_image:latest /bin/install.sh ${rand3}" "generating runlabel without name and --opt1, --opt2"

run_podman 125 container runlabel --opt1=${rand1} --opt2=${rand2} --opt3=${rand3} --name test1 --display run runlabel_image
is "$output" "Error: cannot find the value of label: run in image: runlabel_image" "generating runlabel run command"
Expand Down

1 comment on commit f1b8439

@packit-as-a-service
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podman-next COPR build failed. @containers/packit-build please check.

Please sign in to comment.