From 9b8e01efd6aae8bdc9b11192d6a623333bf91f1f Mon Sep 17 00:00:00 2001 From: Ygal Blum Date: Mon, 16 Oct 2023 13:02:16 +0300 Subject: [PATCH] Quadlet - support ImageName for .image files Allow overriding the image name resolved from the .image file Add test and doc Signed-off-by: Ygal Blum --- docs/source/markdown/podman-systemd.unit.5.md | 44 ++++++---- pkg/systemd/quadlet/quadlet.go | 6 ++ test/system/252-quadlet.bats | 87 +++++++++++++++++++ 3 files changed, 122 insertions(+), 15 deletions(-) diff --git a/docs/source/markdown/podman-systemd.unit.5.md b/docs/source/markdown/podman-systemd.unit.5.md index 0067c361d6..0132ffb97f 100644 --- a/docs/source/markdown/podman-systemd.unit.5.md +++ b/docs/source/markdown/podman-systemd.unit.5.md @@ -1070,21 +1070,22 @@ particularly interesting when using special options to control image pulls. Valid options for `[Image]` are listed below: -| **[Image] options** | **podman image pull equivalent** | -|-------------------------------------|-------------------------------------------------| -| AllTags=true | --all-tags | -| Arch=aarch64 | --arch=aarch64 | -| AuthFile=/etc/registry/auth\.json | --authfile=/etc/registry/auth\.json | -| CertDir=/etc/registry/certs | --cert-dir=/etc/registry/certs | -| ContainersConfModule=/etc/nvd\.conf | --module=/etc/nvd\.conf | -| Creds=myname\:mypassword | --creds=myname\:mypassword | -| DecryptionKey=/etc/registry\.key | --decryption-key=/etc/registry\.key | -| GlobalArgs=--log-level=debug | --log-level=debug | -| Image=quay.io/centos/centos\:latest | podman image pull quay.io/centos/centos\:latest | -| OS=windows | --os=windows | -| PodmanArgs=--os=linux | --os=linux | -| TLSVerify=false | --tls-verify=false | -| Variant=arm/v7 | --variant=arm/v7 | +| **[Image] options** | **podman image pull equivalent** | +|----------------------------------------|--------------------------------------------------| +| AllTags=true | --all-tags | +| Arch=aarch64 | --arch=aarch64 | +| AuthFile=/etc/registry/auth\.json | --authfile=/etc/registry/auth\.json | +| CertDir=/etc/registry/certs | --cert-dir=/etc/registry/certs | +| ContainersConfModule=/etc/nvd\.conf | --module=/etc/nvd\.conf | +| Creds=myname\:mypassword | --creds=myname\:mypassword | +| DecryptionKey=/etc/registry\.key | --decryption-key=/etc/registry\.key | +| GlobalArgs=--log-level=debug | --log-level=debug | +| Image=quay\.io/centos/centos:latest | podman image pull quay.io/centos/centos\:latest | +| ImageTag=quay\.io/centos/centos:latest | Use this name when resolving `.image` references | +| OS=windows | --os=windows | +| PodmanArgs=--os=linux | --os=linux | +| TLSVerify=false | --tls-verify=false | +| Variant=arm/v7 | --variant=arm/v7 | ### `AllTags=` @@ -1150,6 +1151,19 @@ performance and robustness reasons. The format of the name is the same as when passed to `podman pull`. So, it supports using `:tag` or digests to guarantee the specific image version. +### `ImageTag=` + +Actual FQIN of the referenced `Image`. +Only meaningful when source is a file or directory archive. + +For example, an image saved into a `docker-archive` with the following Podman command: + +`podman image save --format docker-archive --output /tmp/archive-file.tar quay.io/podman/stable:latest` + +requires setting +- `Image=docker-archive:/tmp/archive-file.tar` +- `ImageTag=quay.io/podman/stable:latest` + ### `OS=` Override the OS, defaults to hosts, of the image to be pulled. diff --git a/pkg/systemd/quadlet/quadlet.go b/pkg/systemd/quadlet/quadlet.go index d90de98f8e..094166d7a2 100644 --- a/pkg/systemd/quadlet/quadlet.go +++ b/pkg/systemd/quadlet/quadlet.go @@ -90,6 +90,7 @@ const ( KeyIP = "IP" KeyIP6 = "IP6" KeyImage = "Image" + KeyImageTag = "ImageTag" KeyKubeDownForce = "KubeDownForce" KeyLabel = "Label" KeyLogDriver = "LogDriver" @@ -290,6 +291,7 @@ var ( KeyDecryptionKey: true, KeyGlobalArgs: true, KeyImage: true, + KeyImageTag: true, KeyOS: true, KeyPodmanArgs: true, KeyTLSVerify: true, @@ -1222,6 +1224,10 @@ func ConvertImage(image *parser.UnitFile) (*parser.UnitFile, string, error) { // The default syslog identifier is the exec basename (podman) which isn't very useful here "SyslogIdentifier", "%N") + if name, ok := image.Lookup(ImageGroup, KeyImageTag); ok && len(name) > 0 { + imageName = name + } + return service, imageName, nil } diff --git a/test/system/252-quadlet.bats b/test/system/252-quadlet.bats index fe49a3e15a..2b57e58edd 100644 --- a/test/system/252-quadlet.bats +++ b/test/system/252-quadlet.bats @@ -1325,4 +1325,91 @@ EOF run_podman rmi --ignore $(pause_image) } +@test "quadlet - image tag" { + local quadlet_tmpdir=$PODMAN_TMPDIR/quadlets + local archive_file=$PODMAN_TMPDIR/archive-file.tar + local image_for_test=localhost/quadlet_image_test:$(random_string) + + local quadlet_image_unit=image_test_$(random_string).image + local quadlet_image_file=$PODMAN_TMPDIR/$quadlet_image_unit + cat > $quadlet_image_file < $quadlet_volume_file < $quadlet_container_file <