diff --git a/docs/source/markdown/podman-systemd.unit.5.md b/docs/source/markdown/podman-systemd.unit.5.md index 480f08eb22..f20cb52aa0 100644 --- a/docs/source/markdown/podman-systemd.unit.5.md +++ b/docs/source/markdown/podman-systemd.unit.5.md @@ -1708,6 +1708,7 @@ Valid options for `[Build]` are listed below: | Annotation=annotation=value | --annotation=annotation=value | | Arch=aarch64 | --arch=aarch64 | | AuthFile=/etc/registry/auth\.json | --authfile=/etc/registry/auth\.json | +| BuildArg=foo=bar | --build-arg foo=bar | | ContainersConfModule=/etc/nvd\.conf | --module=/etc/nvd\.conf | | DNS=192.168.55.1 | --dns=192.168.55.1 | | DNSOption=ndots:1 | --dns-option=ndots:1 | @@ -1750,6 +1751,14 @@ Path of the authentication file. This is equivalent to the `--authfile` option of `podman build`. +### `BuildArg=` + +Specifies a build argument and its value in the same way environment variables are +(e.g., env=*value*), but it is not added to the environment variable list in the +resulting image's configuration. Can be listed multiple times. + +This is equivalent to the `--build-arg` option of `podman build`. + ### `ContainersConfModule=` Load the specified containers.conf(5) module. Equivalent to the Podman `--module` option. @@ -2157,7 +2166,7 @@ Yaml=/opt/k8s/deployment.yml WantedBy=multi-user.target default.target ``` -Example for locally built image to be used in a container: +Example for locally built image to be used in a container with build-specific arguments: `test.build` ``` @@ -2169,6 +2178,9 @@ ImageTag=localhost/imagename # expecting to find a Containerfile/Dockerfile # + other files needed to build the image SetWorkingDirectory=unit +# Set build arguments VERSION and DEBUG +BuildArg=VERSION=1.0 \ + DEBUG=false ``` `test.container` diff --git a/pkg/systemd/quadlet/quadlet.go b/pkg/systemd/quadlet/quadlet.go index c077043f9d..bc5f899c0d 100644 --- a/pkg/systemd/quadlet/quadlet.go +++ b/pkg/systemd/quadlet/quadlet.go @@ -63,6 +63,7 @@ const ( KeyArch = "Arch" KeyAuthFile = "AuthFile" KeyAutoUpdate = "AutoUpdate" + KeyBuildArg = "BuildArg" KeyCertDir = "CertDir" KeyCgroupsMode = "CgroupsMode" KeyConfigMap = "ConfigMap" @@ -433,6 +434,7 @@ var ( KeyAnnotation: true, KeyArch: true, KeyAuthFile: true, + KeyBuildArg: true, KeyContainersConfModule: true, KeyDNS: true, KeyDNSOption: true, @@ -1391,6 +1393,7 @@ func ConvertBuild(build *parser.UnitFile, unitsInfoMap map[string]*UnitInfo, isU lookupAndAddAllStrings(build, BuildGroup, allStringKeys, podman) keyValKeys := map[string]string{ + KeyBuildArg: "--build-arg", KeyEnvironment: "--env", KeyLabel: "--label", KeyAnnotation: "--annotation", diff --git a/test/e2e/quadlet/buildarg.build b/test/e2e/quadlet/buildarg.build new file mode 100644 index 0000000000..a76db5cd2e --- /dev/null +++ b/test/e2e/quadlet/buildarg.build @@ -0,0 +1,13 @@ +## assert-podman-args "--build-arg" "FOO=BAR" +## assert-podman-args "--build-arg" "BIZ=BAZ" +## assert-podman-args "--build-arg" "MULTIPLE=ARGUMENTS" +## assert-podman-args "--build-arg" "WORKS=FINE" + + +[Build] +ImageTag=image:latest +SetWorkingDirectory=unit +BuildArg=FOO=BAR +BuildArg=BIZ=BAZ +BuildArg=MULTIPLE=ARGUMENTS \ + WORKS=FINE diff --git a/test/e2e/quadlet_test.go b/test/e2e/quadlet_test.go index 44dad370d5..cc526046fe 100644 --- a/test/e2e/quadlet_test.go +++ b/test/e2e/quadlet_test.go @@ -1059,6 +1059,7 @@ BOGUS=foo Entry("Build - Multiple Tags", "multiple-tags.build"), Entry("Build - Network Key host", "network.build"), Entry("Build - PodmanArgs", "podmanargs.build"), + Entry("Build - BuildArg Key", "buildarg.build"), Entry("Build - Pull Key", "pull.build"), Entry("Build - Secrets", "secrets.build"), Entry("Build - SetWorkingDirectory is absolute path", "setworkingdirectory-is-abs.build"),