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

RUN contains undefined ARG or ENV variable for a very defined ARG variable #52

Open
leonsp opened this issue Apr 6, 2018 · 5 comments

Comments

@leonsp
Copy link

leonsp commented Apr 6, 2018

Issue details

This seems different from #47 and #49

Steps to reproduce/test case

This should not raise any issues:

ARG FOO

RUN [[ -n "$FOO" ]]

It raises:

ERROR: Arguments to RUN in exec form must not contain single quotes on line 26
ERROR: RUN contains undefined ARG or ENV variable on line 26

Affected version(s)

0.3.1 and 0.3.9 are affected.

@rnagy
Copy link
Contributor

rnagy commented Apr 6, 2018

@matrixik
Copy link

matrixik commented Jun 4, 2018

Similar example with ONBUILD

FROM scratch

# Get values from child images
ONBUILD ARG REPO_PATH

ONBUILD RUN \
            git clone $REPO_PATH .

Dockerlint 0.3.9

@morgan-zylotech
Copy link

I've just run into this issue myself. Wanted to post a solution here in case anyone else comes across this particular issue

ARG foo will Issue the error as described in the title above

however, if you do the following, the error goes away

ARG foo=${foo:-""}

The interpolated command is a bash parameter substitution construct that says: use $foo if it exists or default to empty. The dash before "" is needed.

https://tldp.org/LDP/abs/html/parameter-substitution.html explains what is going on in greater detail with examples

In any event, I believe the crux of the issue is to set a default value on the foo ARG to stop the error from showing up.

@boner-cmd
Copy link

As shown in the title, the problem is that the ARG is already defined, but that the error thinks it is not. My example is probably the most on-the-nose case:

ARG foo="some string"

Certainly a "very defined ARG variable," not that the linter thinks so.

I believe the crux of the issue is to set a default value on the foo ARG to stop the error from showing up.

I wish it were so simple. But since I also have the error, and I am explicitly defining the ARG... this cannot be the case. At the very least, the problem is more complex.

Not even going to touch "why does Bash parameter substitution fix a linter error in a Dockerfile that even presents in the IDE package."

I'm glad the solution worked for you, I'm just sad no one knows how to fix the underlying issue yet, or what it is.

@caleb15
Copy link

caleb15 commented Jun 13, 2022

Very simple reproduction case:

FROM python:3.9-slim

ARG sha
ENV CURRENT_COMMIT_SHA=$sha

@rnagy can this get a bug label please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants