Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
jwhitaker-swiftnav opened this issue Sep 21, 2022 · 12 comments · Fixed by openshift/imagebuilder#243

Comments

@jwhitaker-swiftnav
Copy link

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
@flouthoc
Copy link
Collaborator

flouthoc commented Sep 21, 2022

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.

@github-actions
Copy link

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

@rhatdan
Copy link
Member

rhatdan commented Oct 27, 2022

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?

@edsantiago
Copy link
Collaborator

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.

@rhatdan
Copy link
Member

rhatdan commented Oct 27, 2022

Seams reasonable.

@sanmai-NL
Copy link

sanmai-NL commented Nov 24, 2022

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

@rhatdan
Copy link
Member

rhatdan commented Nov 30, 2022

@flouthoc any time to work on it?

@github-actions
Copy link

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

@rhatdan
Copy link
Member

rhatdan commented Jan 3, 2023

@flouthoc any time to work on it?

@flouthoc
Copy link
Collaborator

flouthoc commented Jan 3, 2023

I'll check this thanks.

@flouthoc flouthoc self-assigned this Jan 3, 2023
@github-actions
Copy link

github-actions bot commented Feb 3, 2023

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

flouthoc added a commit to flouthoc/imagebuilder that referenced this issue Feb 3, 2023
Docker supports ${SOME_VAR:?} syntax, which will give an error at build if SOME_VAR is unset.

```dockerfile
FROM alpine

ARG USERID

USER ${USERID:?}
```

```console
Failed to process `${USERID:?}`: USERID is not allowed to be
unset
```

Closes: containers/buildah#4284

Ref: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02

Signed-off-by: Aditya R <arajan@redhat.com>
@flouthoc
Copy link
Collaborator

flouthoc commented Feb 3, 2023

@jwhitaker-swiftnav Thanks PR openshift/imagebuilder#243 should close this.

flouthoc added a commit to flouthoc/imagebuilder that referenced this issue Feb 13, 2023
Docker supports ${SOME_VAR:?} syntax, which will give an error at build if SOME_VAR is unset.

```dockerfile
FROM alpine

ARG USERID

USER ${USERID:?}
```

```console
Failed to process `${USERID:?}`: USERID is not allowed to be
unset
```

Closes: containers/buildah#4284

Ref: https://pubs.opengroup.org/onlinepubs/9699919799/utilities/V3_chap02.html#tag_18_06_02

Signed-off-by: Aditya R <arajan@redhat.com>
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants