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

UndefinedVar build check behaviour for PATH-like variables #2751

Open
Stikus opened this issue Oct 23, 2024 · 6 comments
Open

UndefinedVar build check behaviour for PATH-like variables #2751

Stikus opened this issue Oct 23, 2024 · 6 comments
Labels

Comments

@Stikus
Copy link

Stikus commented Oct 23, 2024

According to docs:

Before you reference an environment variable or a build argument in a RUN instruction, you should ensure that the variable is declared in the Dockerfile, using the ARG or ENV instructions.

This is not correct statement - you can append $PATH without any declaration in Dockerfile, as well as some other variables like $LD_LIBRARY_PATH. But not PYTHONPATH:

PYTHONPATH="$SOFT/Stranger-${STRANGER_VERSION}/local/lib/python3.10/dist-packages:$PYTHONPATH"

results warning: UndefinedVar: Usage of undefined variable '$PYTHONPATH' (line 72)

Are there any settings for predefined variables (not in Dockerfile) or how is should be fixed?

Stack Overflow question about this problem.

@crazy-max
Copy link
Member

you can append $PATH without any declaration in Dockerfile, as well as some other variables like $LD_LIBRARY_PATH

It depends if this ENV has already been declared in the base image.

results warning: UndefinedVar: Usage of undefined variable '$PYTHONPATH' (line 72)

This means PYTHONPATH has not been declared in your Dockerfile or the base image you're using.

@Stikus
Copy link
Author

Stikus commented Oct 23, 2024

Does this check actually checks base image? Documentation doesn't have any info about it.

Is there any way to ignore only current case of this check (not all check entirely)? Something like https://github.com/hadolint/hadolint?tab=readme-ov-file#inline-ignores or https://github.com/koalaman/shellcheck/wiki/Ignore#ignoring-one-specific-instance-in-a-file

@crazy-max
Copy link
Member

Does this check actually checks base image?

Yes it does

Documentation doesn't have any info about it.

Indeed we could add a callout about it (cc @dvdksn).

Is there any way to ignore only current case of this check (not all check entirely)? Something like https://github.com/hadolint/hadolint?tab=readme-ov-file#inline-ignores or https://github.com/koalaman/shellcheck/wiki/Ignore#ignoring-one-specific-instance-in-a-file

I recall this has been discussed internally but not sure what is the current state of it. @colinhemmings do we have this scoped to a milestone?

@crazy-max crazy-max added kind/question Further information is requested area/checks labels Oct 23, 2024
@colinhemmings
Copy link
Collaborator

@Stikus, yes, we have something similar to inline ignores on the roadmap, but we don't have a date for it just yet. I will make sure to keep you posted.

@Stikus
Copy link
Author

Stikus commented Oct 23, 2024

Thanks for fast answer, maybe there are any workarounds - like PATH1=${PATH1:-}:/new-path1 or PYTHONPATH="$SOFT/Stranger-${STRANGER_VERSION}/local/lib/python3.10/dist-packages:${PYTHONPATH:-''}"? To ensure that user is aware about empty variable?

@serge2016
Copy link

Hello! I am also interested in workarounds... Which one is better?

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

No branches or pull requests

5 participants