buildah icon indicating copy to clipboard operation
buildah copied to clipboard

Feature request - ${VAR_NAME:?} dockerfile syntax to error on unset variables

Open jwhitaker-swiftnav opened this issue 3 years ago • 1 comments

Description

Docker supports ${SOME_VAR:?} syntax, which will give an error at build if SOME_VAR is unset. I believe this is directly in the Dockerfile syntax, not via a shell. Buildah doesn't support this, so this feature request is to request support for this syntax.

Example:

Docker

FROM public.ecr.aws/docker/library/node:16-alpine as builder

ARG USERID

USER ${USERID:?}
docker build .
...
Step 3/3 : USER ${USERID:?}
failed to process "${USERID:?}": USERID: is not allowed to be unset
# exit 1

Buildah/Podman

Buildah/Podman don't support this syntax:

podman build .
...
Error: error resolving step {Value:user Next:0xc0002ae8c0 Children:[] Attributes:map[] Original:USER ${USERID:?} Flags:[] StartLine:5 EndLine:5}: Unsupported modifier (?) in substitution: ${USERID:?}

This is a genuinely useful feature, so my request goes beyond just for the sake of compatibility.

Extra Info

Output of podman version:

podman version 4.2.1
buildah version 1.27.1 (image-spec 1.0.2-dev, runtime-spec 1.0.2-dev)

Package info (e.g. output of rpm -q podman or apt list podman):

podman/unknown,now 4:4.2.1-0ubuntu22.04+obs57.1 amd64 [installed]
buildah/unknown,now 1.27.1-0ubuntu22.04+obs25.1 amd64 [installed]

Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide? (https://github.com/containers/podman/blob/main/troubleshooting.md)

Yes/No Latest version in the kubic repo, haven't tried building from master.

Additional environment details (AWS, VirtualBox, physical, etc.):

Docker version for comparison:

Docker version 20.10.18, build b40c2f6

jwhitaker-swiftnav avatar Sep 21 '22 04:09 jwhitaker-swiftnav

Hi @jwhitaker-swiftnav , Thanks for creating the issue.

I was unable to find any formal documentation on docker side for this, but I think we can implement this at imagebuilder. @nalind Any thoughts ? Since this is not a documented behavior on docker.

flouthoc avatar Sep 21 '22 07:09 flouthoc

A friendly reminder that this issue had no activity for 30 days.

github-actions[bot] avatar Oct 22 '22 00:10 github-actions[bot]

If this is a legitimate Dockerfile then we should support it. Whether it is documented or not. (Well maybe not if it is considered experimental)

@edsantiago Is this a special Bashism?

rhatdan avatar Oct 27 '22 13:10 rhatdan

It's a common bashism; I have no knowledge of docker's level of support for it.

Parameter Expansion

  ${parameter:?word}
     Display  Error if Null or Unset.  If parameter is null or unset, the
     expansion of word (or a message to that effect if word is not present) is
     written to the standard error and the shell, if it is not interactive, exits.
     Otherwise, the value of parameter is substituted.

edsantiago avatar Oct 27 '22 14:10 edsantiago

Seams reasonable.

rhatdan avatar Oct 27 '22 18:10 rhatdan

@rhatdan @edsantiago Importantly, this is not a Bashism, but standard/POSIX/SUS. It also works in practice in other shells, e.g., Ash.

sanmai-NL avatar Nov 24 '22 08:11 sanmai-NL

@flouthoc any time to work on it?

rhatdan avatar Nov 30 '22 20:11 rhatdan

A friendly reminder that this issue had no activity for 30 days.

github-actions[bot] avatar Dec 31 '22 00:12 github-actions[bot]

@flouthoc any time to work on it?

rhatdan avatar Jan 03 '23 16:01 rhatdan

I'll check this thanks.

flouthoc avatar Jan 03 '23 16:01 flouthoc

A friendly reminder that this issue had no activity for 30 days.

github-actions[bot] avatar Feb 03 '23 00:02 github-actions[bot]

@jwhitaker-swiftnav Thanks PR https://github.com/openshift/imagebuilder/pull/243 should close this.

flouthoc avatar Feb 03 '23 12:02 flouthoc