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

ARG and ENV instructions should be scoped to a build stage #163

Closed
rcjsuen opened this issue Aug 23, 2017 · 0 comments
Closed

ARG and ENV instructions should be scoped to a build stage #163

rcjsuen opened this issue Aug 23, 2017 · 0 comments
Assignees
Labels

Comments

@rcjsuen
Copy link
Owner

rcjsuen commented Aug 23, 2017

Variables defined by ARG and ENV should be scoped to a build stage. Currently, features related to Dockerfile variables such as textDocument/definition, textDocument/documentHighlight, textDocument/hover, and textDocument/rename are all getting spanned across multiple build stages.

Renaming a variable in one build stage will cause the similarly named ones in another other build stage to be renamed and highlighting a variable will highlight all the instances in the Dockerfile when the highlighting should only be scoped to the build stage that encompasses the instruction with that variable. Similarly, hovering over a variable will incorrectly display defined values from an earlier build stage when it should be empty if that variable has never been declared in the current build stage. Also, opening a variable's definition will jump to a declaration in an earlier build stage when the lookup should only be performed in the current build stage.

The docker build output below shows how variables should be scoped to its encompassing build stage. The second RUN echo $var statement prints nothing because the variable has not been defined in the second build stage.

FROM alpine
ARG var=value
RUN echo $var
FROM alpine
RUN echo $var
$ docker build .
Sending build context to Docker daemon  86.15MB
Step 1/5 : FROM alpine
latest: Pulling from library/alpine
88286f41530e: Pull complete
Digest: sha256:1072e499f3f655a032e88542330cf75b02e7bdf673278f701d7ba61629ee3ebe
Status: Downloaded newer image for alpine:latest
 ---> 7328f6f8b418
Step 2/5 : ARG var=value
 ---> Running in 2b3317a23f64
 ---> eb0507a9cd61
Removing intermediate container 2b3317a23f64
Step 3/5 : RUN echo $var
 ---> Running in a359d6d23c99
value
 ---> 80d30528cb2f
Removing intermediate container a359d6d23c99
Step 4/5 : FROM alpine
 ---> 7328f6f8b418
Step 5/5 : RUN echo $var
 ---> Running in a98c86de2859

 ---> e13e8e88531a
Removing intermediate container a98c86de2859
Successfully built e13e8e88531a
FROM alpine
ENV var=value
RUN echo $var
FROM alpine
RUN echo $var
$ docker build .
Sending build context to Docker daemon  61.28MB
Sending build context to Docker daemon  86.15MB
Step 1/5 : FROM alpine
latest: Pulling from library/alpine
88286f41530e: Pull complete
Digest: sha256:1072e499f3f655a032e88542330cf75b02e7bdf673278f701d7ba61629ee3ebe
Status: Downloaded newer image for alpine:latest
 ---> 7328f6f8b418
Step 2/5 : ENV var value
 ---> Running in c07c1aef8530
 ---> e49c9ab7b565
Removing intermediate container c07c1aef8530
Step 3/5 : RUN echo $var
 ---> Running in bb79cf1b0ac9
value
 ---> fadbe87bf1c6
Removing intermediate container bb79cf1b0ac9
Step 4/5 : FROM alpine
 ---> 7328f6f8b418
Step 5/5 : RUN echo $var
 ---> Running in ccf4603f3dae

 ---> 61a8fe637349
Removing intermediate container ccf4603f3dae
Successfully built 61a8fe637349
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

1 participant