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

Cannot overwrite PATH environment variable properly #748

Closed
fspaniol opened this issue Aug 22, 2019 · 5 comments
Closed

Cannot overwrite PATH environment variable properly #748

fspaniol opened this issue Aug 22, 2019 · 5 comments
Labels
good first issue Good for newcomers kind/bug Something isn't working

Comments

@fspaniol
Copy link

Actual behavior
Whenever I try to add anything to the PATH, the previous value is gone.

Expected behavior
Mimic the normal Docker behavior

To Reproduce
Try to build this Dockerfile:

FROM opensuse/leap:15.0

RUN echo $PATH
ENV PATH="${PATH}:a"
RUN echo $PATH

When building it directly with Docker, the output is:

Sending build context to Docker daemon  2.048kB
Step 1/4 : FROM opensuse/leap:15.0
 ---> aaf6380c86fb
Step 2/4 : RUN echo $PATH
 ---> Running in 843a7bc797ae
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
Removing intermediate container 843a7bc797ae
 ---> e868ea5e93e7
Step 3/4 : ENV PATH="${PATH}:a"
 ---> Running in 5777e406e11f
Removing intermediate container 5777e406e11f
 ---> fc531f605651
Step 4/4 : RUN echo $PATH
 ---> Running in 529207d98d8d
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:a
Removing intermediate container 529207d98d8d
 ---> 6b0409e343cc
Successfully built 6b0409e343cc

Whereas when using Kaniko, the output is:

INFO[0001] Resolved base name opensuse/leap:15.0 to opensuse/leap:15.0 
INFO[0001] Resolved base name opensuse/leap:15.0 to opensuse/leap:15.0 
INFO[0001] Downloading base image opensuse/leap:15.0    
INFO[0004] Error while retrieving image from cache: getting file info: stat /cache/sha256:ad69820fac84924293242a2c5180810e99aac4361ad422172e147de3894ddd74: no such file or directory 
INFO[0004] Downloading base image opensuse/leap:15.0    
INFO[0005] Built cross stage deps: map[]                
INFO[0005] Downloading base image opensuse/leap:15.0    
INFO[0007] Error while retrieving image from cache: getting file info: stat /cache/sha256:ad69820fac84924293242a2c5180810e99aac4361ad422172e147de3894ddd74: no such file or directory 
INFO[0007] Downloading base image opensuse/leap:15.0    
INFO[0008] Unpacking rootfs as cmd RUN echo $PATH requires it. 
INFO[0027] Taking snapshot of full filesystem...        
INFO[0030] RUN echo $PATH                               
INFO[0030] cmd: /bin/sh                                 
INFO[0030] args: [-c echo $PATH]                        
/usr/local/bin:/usr/bin:/bin:.
INFO[0030] Taking snapshot of full filesystem...        
INFO[0031] No files were changed, appending empty layer to config. No layer added to image. 
INFO[0031] ENV PATH="${PATH}:a"                         
INFO[0031] RUN echo $PATH                               
INFO[0031] cmd: /bin/sh                                 
INFO[0031] args: [-c echo $PATH]                        
:a
INFO[0031] Taking snapshot of full filesystem...        
INFO[0031] No files were changed, appending empty layer to config. No layer added to image.

One interesting thing, is that the default PATH is not the PATH from the base image that I'm extending, but instead a fixed one. This has already been reported in #650. Maybe #691 has some relation to this as well?

Kaniko image used: gcr.io/kaniko-project/executor:debug-v0.10.0 (although I have tried with many different ones)

For now, the workaround I've been using is to manually set the PATH to the one contained in the base image I'm extending :)

Thanks for the help :)

@ffoebel
Copy link

ffoebel commented Aug 28, 2019

I've faced the same issue and while applying your workaround is sufficient when building your specific image, it doesn't help you when trying to offer a build pipeline for arbitrary images.

@tejal29 tejal29 added kind/bug Something isn't working good first issue Good for newcomers labels Aug 29, 2019
@tejal29
Copy link
Contributor

tejal29 commented Aug 29, 2019

Thanks, relates to #649.

@tejal29
Copy link
Contributor

tejal29 commented Aug 29, 2019

Currently, we only resolve environments which are set or passed via build-args. We can definitely add "$PATH" as a special case.

@prary
Copy link
Contributor

prary commented Sep 9, 2019

#762 kind of resolve the issue, here is the output

INFO[0007] Executing 0 build triggers
INFO[0007] Unpacking rootfs as cmd RUN echo $PATH requires it.
INFO[0014] Taking snapshot of full filesystem...
INFO[0017] RUN echo $PATH
INFO[0017] cmd: /bin/sh
INFO[0017] args: [-c echo $PATH]
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
INFO[0017] Taking snapshot of full filesystem...
INFO[0020] No files were changed, appending empty layer to config. No layer added to image.
INFO[0020] ENV PATH="${PATH}:a"
INFO[0020] RUN echo $PATH
INFO[0020] cmd: /bin/sh
INFO[0020] args: [-c echo $PATH]
INFO[0020] Taking snapshot of full filesystem...
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:a
INFO[0022] No files were changed, appending empty layer to config. No layer added to image.

@tejal29
Copy link
Contributor

tejal29 commented Sep 13, 2019

so, i added tests on @prary branch and checked it out myself.


INFO[0005] ENV PATH="${PATH}:a"                         
DEBU[0005] Replacing environment variable {PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin} with {PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:a} in config 
INFO[0005] RUN echo $PATH                               
INFO[0005] cmd: /bin/sh                                 
INFO[0005] args: [-c echo $PATH]                        
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:a
INFO[0005] No files were changed, appending empty layer to cfg. No layer added to image. 
INFO[0005] Skipping push to container registry due to --no-push flag 
tejaldesai@@kaniko (test)$ 

@tejal29 tejal29 closed this as completed Sep 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants