Skip to content

Commit

Permalink
Merge pull request #23810 from ygalblum/quadlet-build-multi-tag
Browse files Browse the repository at this point in the history
Quadlet - Support multiple image tags in .build files
  • Loading branch information
openshift-merge-bot[bot] authored Aug 30, 2024
2 parents ece759a + 2b14db2 commit f48f999
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 3 deletions.
2 changes: 2 additions & 0 deletions docs/source/markdown/podman-systemd.unit.5.md
Original file line number Diff line number Diff line change
Expand Up @@ -1621,6 +1621,8 @@ successfully.

This is equivalent to the `--tag` option of `podman build`.

This key can be listed multiple times. The first instance will be used as the name of the created artifact when the `.build` file is referenced by another Quadlet unit.

### `Label=`

Add an image *label* (e.g. label=*value*) to the image metadata. Can be used multiple times.
Expand Down
10 changes: 7 additions & 3 deletions pkg/systemd/quadlet/quadlet.go
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,10 @@ func ConvertBuild(build *parser.UnitFile, unitsInfoMap map[string]*UnitInfo) (*p
labels := build.LookupAllKeyVal(BuildGroup, KeyLabel)
podman.addLabels(labels)

podman.addf("--tag=%s", unitInfo.ResourceName)
imageTags := build.LookupAll(BuildGroup, KeyImageTag)
for _, imageTag := range imageTags {
podman.addf("--tag=%s", imageTag)
}

if err := addNetworks(build, BuildGroup, service, unitsInfoMap, podman); err != nil {
return nil, err
Expand Down Expand Up @@ -1555,8 +1558,9 @@ func ConvertBuild(build *parser.UnitFile, unitsInfoMap map[string]*UnitInfo) (*p
}

func GetBuiltImageName(buildUnit *parser.UnitFile) string {
if builtImageName, ok := buildUnit.Lookup(BuildGroup, KeyImageTag); ok {
return builtImageName
imageTags := buildUnit.LookupAll(BuildGroup, KeyImageTag)
if len(imageTags) > 0 {
return imageTags[0]
}
return ""
}
Expand Down
4 changes: 4 additions & 0 deletions test/e2e/quadlet/build.multiple-tags.container
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## assert-podman-final-args localhost/imagename:v1

[Container]
Image=multiple-tags.build
7 changes: 7 additions & 0 deletions test/e2e/quadlet/multiple-tags.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## assert-podman-args --tag=localhost/imagename:v1
## assert-podman-args --tag=localhost/imagename:latest

[Build]
ImageTag=localhost/imagename:v1
ImageTag=localhost/imagename:latest
SetWorkingDirectory=unit
2 changes: 2 additions & 0 deletions test/e2e/quadlet_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -984,6 +984,7 @@ BOGUS=foo
Entry("Build - GroupAdd Key", "group-add.build"),
Entry("Build - Containers Conf Modules", "containersconfmodule.build"),
Entry("Build - Label Key", "label.build"),
Entry("Build - Multiple Tags", "multiple-tags.build"),
Entry("Build - Network Key host", "network.build"),
Entry("Build - PodmanArgs", "podmanargs.build"),
Entry("Build - Pull Key", "pull.build"),
Expand Down Expand Up @@ -1075,6 +1076,7 @@ BOGUS=foo
Entry("Container - Mount overriding service name", "mount.servicename.container", []string{"service-name.volume"}),
Entry("Container - Quadlet Network overriding service name", "network.quadlet.servicename.container", []string{"service-name.network"}),
Entry("Container - Quadlet Volume overriding service name", "volume.servicename.container", []string{"service-name.volume"}),
Entry("Container - Quadlet build with multiple tags", "build.multiple-tags.container", []string{"multiple-tags.build"}),

Entry("Volume - Quadlet image (.build)", "build.quadlet.volume", []string{"basic.build"}),
Entry("Volume - Quadlet image (.image)", "image.quadlet.volume", []string{"basic.image"}),
Expand Down

0 comments on commit f48f999

Please sign in to comment.