Skip to contentSkip to conversation

podman: support bash completions for podman/docker

PATCH In review [email protected] 2 participants 6 messages Jan 8, 2024 – Jan 10, 2024

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 podman: support bash completions for podman/docker

From: Ming Liu <[email protected]>

Generate podman bash completion script with qemu wrapper.

When docker pkgconfig is enabled, also generate bash completion script for docker.

---
 recipes-containers/podman/podman_git.bb | 29 +++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
recipes-containers/podman/podman_git.bb +29 -0
index 33d437a3..1c64272a 100644
@@ -68,6 +68,18 @@ EXTRA_OEMAKE = " \
 # packageconfig, the podman package will rconfict with docker.
 PACKAGECONFIG ?= "docker"
 
+# podman builds bash completion with the help of podman binary, only the machines
+# that support qemu usermode can enable this pkgconfig.
+PACKAGECONFIG:append = " ${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'completion', '', d)}"
+DEPENDS:append = " ${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'qemu-native', '', d)}"
+
+inherit qemu bash-completion
+
+# To avoid breaking the recipes without 'completion' enabled.
+ALLOW_EMPTY:${PN}-bash-completion = "1"
+
+QEMU_OPTIONS = ""
+
 do_compile() {
 	cd ${S}/src
 	rm -rf .gopath
@@ -116,6 +128,23 @@ do_install() {
 		install -d "${D}${sysconfdir}/sysctl.d"
 		install -m 0644 "${WORKDIR}/50-podman-rootless.conf" "${D}${sysconfdir}/sysctl.d"
 	fi
+
+	if ${@bb.utils.contains('PACKAGECONFIG', 'completion', 'true', 'false', d)}; then
+		qemu_binary="${@qemu_wrapper_cmdline(d, '${STAGING_DIR_TARGET}', ['${B}', '${STAGING_DIR_TARGET}/${base_libdir}'])}"
+		cat > ${WORKDIR}/podman-qemuwrapper << EOF
+#!/bin/sh
+
+$qemu_binary "\$@"
+EOF
+		chmod +x ${WORKDIR}/podman-qemuwrapper
+		${WORKDIR}/podman-qemuwrapper ./bin/podman completion bash > ${B}/podman-bash-completion
+		install -d ${D}${datadir}/bash-completion/completions
+		install -m 0644 ${B}/podman-bash-completion ${D}${datadir}/bash-completion/completions/podman
+		if ${@bb.utils.contains('PACKAGECONFIG', 'docker', 'true', 'false', d)}; then
+			sed "s/podman/docker/g" ${B}/podman-bash-completion > ${B}/docker-bash-completion
+			install -m 0644 ${B}/docker-bash-completion ${D}${datadir}/bash-completion/completions/docker
+		fi
+	fi
 }
 
 do_install_ptest () {
Signature · 1 line
2.34.1
#1 lore raw
Quoted 7 lines · Ming Liu

From: Ming Liu <[email protected]>

Generate podman bash completion script with qemu wrapper.

When docker pkgconfig is enabled, also generate bash completion script for docker.

Just to get bash-completions, this is too complicated and brittle.

In this situation, we need to figure out what it is generating, do it once, and capture
the output (or otherwise simulate it).

Bruce

Quoted 65 lines
---
 recipes-containers/podman/podman_git.bb | 29 +++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
recipes-containers/podman/podman_git.bb +29 -1
index 33d437a3..1c64272a 100644
@@ -68,6 +68,18 @@ EXTRA_OEMAKE = " \
 # packageconfig, the podman package will rconfict with docker.
 PACKAGECONFIG ?= "docker"
 
+# podman builds bash completion with the help of podman binary, only the machines
+# that support qemu usermode can enable this pkgconfig.
+PACKAGECONFIG:append = " ${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'completion', '', d)}"
+DEPENDS:append = " ${@bb.utils.contains('MACHINE_FEATURES', 'qemu-usermode', 'qemu-native', '', d)}"
+
+inherit qemu bash-completion
+
+# To avoid breaking the recipes without 'completion' enabled.
+ALLOW_EMPTY:${PN}-bash-completion = "1"
+
+QEMU_OPTIONS = ""
+
 do_compile() {
        cd ${S}/src
        rm -rf .gopath
@@ -116,6 +128,23 @@ do_install() {
                install -d "${D}${sysconfdir}/sysctl.d"
                install -m 0644 "${WORKDIR}/50-podman-rootless.conf" "${D}${sysconfdir}/sysctl.d"
        fi
+
+       if ${@bb.utils.contains('PACKAGECONFIG', 'completion', 'true', 'false', d)}; then
+               qemu_binary="${@qemu_wrapper_cmdline(d, '${STAGING_DIR_TARGET}', ['${B}', '${STAGING_DIR_TARGET}/${base_libdir}'])}"
+               cat > ${WORKDIR}/podman-qemuwrapper << EOF
+#!/bin/sh
+
+$qemu_binary "\$@"
+EOF
+               chmod +x ${WORKDIR}/podman-qemuwrapper
+               ${WORKDIR}/podman-qemuwrapper ./bin/podman completion bash > ${B}/podman-bash-completion
+               install -d ${D}${datadir}/bash-completion/completions
+               install -m 0644 ${B}/podman-bash-completion ${D}${datadir}/bash-completion/completions/podman
+               if ${@bb.utils.contains('PACKAGECONFIG', 'docker', 'true', 'false', d)}; then
+                       sed "s/podman/docker/g" ${B}/podman-bash-completion > ${B}/docker-bash-completion
+                       install -m 0644 ${B}/docker-bash-completion ${D}${datadir}/bash-completion/completions/docker
+               fi
+       fi
 }
 
 do_install_ptest () {
--

2.34.1

-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#8531): https://lists.yoctoproject.org/g/meta-virtualization/message/8531
Mute This Topic: https://lists.yoctoproject.org/mt/103603296/1050810
Group Owner: [email protected]
Unsubscribe: https://lists.yoctoproject.org/g/meta-virtualization/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-

Signature · 3 lines
- Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end
- "Use the force Harry" - Gandalf, Star Trek II
author
#2 lore raw

Hi, Bruce:

Seems podman manage its shell completions inside the code (see this line:
https://github.com/containers/podman/pull/21095/commits/6c4892c8029fd992b4494adb62c535d0f5c5d62d#diff-cf5cc76e70a369c5221f08f29ec0452710af1f4ecd423c162d5b669688416caeR484
)

then it uses "podman completion SHELL-NAME" to get the completion for a particular shell, so it's not safe to pre-generate a completion outside of podman source? For instance, if we add a CVE fix or some common bug fixes to SRC_URI, the completion might be changed and the developers have to be aware of that and also update completion file.

And this qemu wrapper way is being used in OE in several recipes, like python, the qemu-native would be built in most cases if you build a OE image, so would be no much cost on it? Just my personal options.

the best,
thank you

#3 lore raw
Quoted 7 lines · Ming Liu

Hi, Bruce:

Seems podman manage its shell completions inside the code (see this line: https://github.com/containers/podman/pull/21095/commits/6c4892c8029fd992b4494adb62c535d0f5c5d62d#diff-cf5cc76e70a369c5221f08f29ec0452710af1f4ecd423c162d5b669688416caeR484)

then it uses "podman completion SHELL-NAME" to get the completion for a particular shell, so it's not safe to pre-generate a completion outside of podman source? For instance, if we add a CVE fix or some common bug fixes to SRC_URI, the completion might be changed and the developers have to be aware of that and also update completion file.

That CVE example is quite unlikely .. and I'd suggest we created the issue by packaging the completions in the first case.

Quoted 2 lines

And this qemu wrapper way is being used in OE in several recipes, like python, the qemu-native would be built in most cases if you build a OE image, so would be no much cost on it? Just my personal options.

I'm quite aware of how and where the wrappers are used. It is still too complex for something as trivial
as bash completion generation.

I'd suggest you can carry the generation and packaging in a bbappend, and that I can look into alternate
ways to generate the completions in the future.

Even generating them on-target, in a first boot scenario is preferable (from a maintenance point of view).

I also have a podman-native extension locally that could be useful, but doing an emulated arch-specific
execution of target podman to generate bash completion outputs (that should NOT be arch specfic, and
if they are, we want no part of them) is far too heavy.

Bruce

Quoted 2 lines

the best,
thank you

Signature · 3 lines
- Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end
- "Use the force Harry" - Gandalf, Star Trek II
author
#4 lore raw

Hi, Bruce:

Got that, in that case, I will use a bbappend in our meta layers for now, thanks for the explanation.

About the podman-native recipe you mentioned, do you plan to push it to meta-virtualization layer? We found it's very useful in some cases, I am also considering adding native/natiesdk for buildah, it could be used to provide a fakerooted build env.

the best,
thank you

Bruce Ashfield <[email protected]> 於 2024年1月9日 週二 下午2:23寫道:

Quoted 53 lines · Ming Liu
Quoted 4 lines

Hi, Bruce:

Seems podman manage its shell completions inside the code (see this

line:
https://github.com/containers/podman/pull/21095/commits/6c4892c8029fd992b4494adb62c535d0f5c5d62d#diff-cf5cc76e70a369c5221f08f29ec0452710af1f4ecd423c162d5b669688416caeR484
)

Quoted 2 lines

then it uses "podman completion SHELL-NAME" to get the completion for a

particular shell, so it's not safe to pre-generate a completion outside of podman source? For instance, if we add a CVE fix or some common bug fixes to SRC_URI, the completion might be changed and the developers have to be aware of that and also update completion file.

Quoted 1 line

That CVE example is quite unlikely .. and I'd suggest we created the issue by packaging the completions in the first case.

Quoted 1 line

And this qemu wrapper way is being used in OE in several recipes, like

python, the qemu-native would be built in most cases if you build a OE image, so would be no much cost on it? Just my personal options.

Quoted 1 line

I'm quite aware of how and where the wrappers are used. It is still too complex for something as trivial
as bash completion generation.

I'd suggest you can carry the generation and packaging in a bbappend, and that I can look into alternate
ways to generate the completions in the future.

Even generating them on-target, in a first boot scenario is preferable (from a maintenance point of view).

I also have a podman-native extension locally that could be useful, but doing an emulated arch-specific
execution of target podman to generate bash completion outputs (that should NOT be arch specfic, and
if they are, we want no part of them) is far too heavy.

Bruce

Quoted 2 lines

the best,
thank you

--
- Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end
- "Use the force Harry" - Gandalf, Star Trek II

#5 lore raw
Quoted 7 lines · Ming Liu

Hi, Bruce:

Got that, in that case, I will use a bbappend in our meta layers for now, thanks for the explanation.

About the podman-native recipe you mentioned, do you plan to push it to meta-virtualization layer? We found it's very useful in some cases, I am also considering adding native/natiesdk for buildah, it could be used to provide a fakerooted build env.

I will push both of the changes eventually, I'm currently still working through some pseudo and
namespace / cgroups problems.

I also have buildah as native in that scenario, since it is slightly coupled to podman. But I won't
use it as a image construction method as it duplicates far too much code from other tools and
had it's own set of assumptions and coupling.

Bruce

Quoted 48 lines

the best,
thank you

Bruce Ashfield <[email protected]> 於 2024年1月9日 週二 下午2:23寫道:

Quoted 44 lines · Ming Liu
Quoted 7 lines

Hi, Bruce:

Seems podman manage its shell completions inside the code (see this line: https://github.com/containers/podman/pull/21095/commits/6c4892c8029fd992b4494adb62c535d0f5c5d62d#diff-cf5cc76e70a369c5221f08f29ec0452710af1f4ecd423c162d5b669688416caeR484)

then it uses "podman completion SHELL-NAME" to get the completion for a particular shell, so it's not safe to pre-generate a completion outside of podman source? For instance, if we add a CVE fix or some common bug fixes to SRC_URI, the completion might be changed and the developers have to be aware of that and also update completion file.

That CVE example is quite unlikely .. and I'd suggest we created the issue by packaging the completions in the first case.

Quoted 2 lines

And this qemu wrapper way is being used in OE in several recipes, like python, the qemu-native would be built in most cases if you build a OE image, so would be no much cost on it? Just my personal options.

I'm quite aware of how and where the wrappers are used. It is still too complex for something as trivial
as bash completion generation.

I'd suggest you can carry the generation and packaging in a bbappend, and that I can look into alternate
ways to generate the completions in the future.

Even generating them on-target, in a first boot scenario is preferable (from a maintenance point of view).

I also have a podman-native extension locally that could be useful, but doing an emulated arch-specific
execution of target podman to generate bash completion outputs (that should NOT be arch specfic, and
if they are, we want no part of them) is far too heavy.

Bruce

Quoted 2 lines

the best,
thank you

--
- Thou shalt not follow the NULL pointer, for chaos and madness await thee at its end
- "Use the force Harry" - Gandalf, Star Trek II

Signature · 3 lines
- Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end
- "Use the force Harry" - Gandalf, Star Trek II