qudlet: Respect $PODMAN env var for podman binary

This changes the podman binary name embedded in the generated files.
This is primarily needed for testing podman.

This also adds a -X config for BINDIR so that we pick up the right
install target. This required tweaking some tests to handle the default
bindir not being /usr/bin.

Signed-off-by: Alexander Larsson <alexl@redhat.com>
This commit is contained in:
Alexander Larsson 2022-12-13 14:10:07 +01:00
parent a4a647c0b9
commit 461726a3fa
5 changed files with 20 additions and 4 deletions

View File

@ -110,6 +110,7 @@ LDFLAGS_PODMAN ?= \
$(if $(BUILD_INFO),-X $(LIBPOD)/define.buildInfo=$(BUILD_INFO),) \
-X $(LIBPOD)/config._installPrefix=$(PREFIX) \
-X $(LIBPOD)/config._etcDir=$(ETCDIR) \
-X $(PROJECT)/v4/pkg/systemd/quadlet._binDir=$(BINDIR) \
-X github.com/containers/common/pkg/config.additionalHelperBinariesDir=$(HELPER_BINARIES_DIR)\
$(EXTRA_LDFLAGS)
LDFLAGS_PODMAN_STATIC ?= \

View File

@ -2,9 +2,24 @@ package quadlet
import (
"fmt"
"os"
"path"
"sort"
)
// Overwritten at build time
var (
_binDir string
)
func podmanBinary() string {
podman := os.Getenv("PODMAN")
if len(podman) > 0 {
return podman
}
return path.Join(_binDir, "podman")
}
/* This is a helper for constructing podman commandlines */
type PodmanCmdline struct {
Args []string
@ -47,7 +62,7 @@ func NewPodmanCmdline(args ...string) *PodmanCmdline {
Args: make([]string, 0),
}
c.add("/usr/bin/podman")
c.add(podmanBinary())
c.add(args...)
return c
}

View File

@ -229,7 +229,7 @@ func ConvertContainer(container *parser.UnitFile, isUser bool) (*parser.UnitFile
// If the conman exited uncleanly it may not have removed the container, so force it,
// -i makes it ignore non-existing files.
service.Add(ServiceGroup, "ExecStopPost", "-/usr/bin/podman rm -f -i --cidfile=%t/%N.cid")
service.Add(ServiceGroup, "ExecStopPost", "-"+podmanBinary()+" rm -f -i --cidfile=%t/%N.cid")
// Remove the cid file, to avoid confusion as the container is no longer running.
service.Add(ServiceGroup, "ExecStopPost", "-rm -f %t/%N.cid")

View File

@ -14,7 +14,7 @@
## assert-key-is "Service" "Type" "notify"
## assert-key-is "Service" "NotifyAccess" "all"
## assert-key-is "Service" "SyslogIdentifier" "%N"
## assert-key-is "Service" "ExecStopPost" "-/usr/bin/podman rm -f -i --cidfile=%t/%N.cid" "-rm -f %t/%N.cid"
## assert-key-is-regex "Service" "ExecStopPost" "-.*/podman rm -f -i --cidfile=%t/%N.cid" "-rm -f %t/%N.cid"
## assert-key-is "Service" "Environment" "PODMAN_SYSTEMD_UNIT=%n"
[Container]

View File

@ -1,7 +1,7 @@
## assert-key-is Unit RequiresMountsFor "%t/containers"
## assert-key-is Service Type oneshot
## assert-key-is Service RemainAfterExit yes
## assert-key-is Service ExecStart "/usr/bin/podman volume create --ignore systemd-basic"
## assert-key-is-regex Service ExecStart ".*/podman volume create --ignore systemd-basic"
## assert-key-is Service SyslogIdentifier "%N"
[Volume]