GoogleContainerTools / kaniko

Build Container Images In Kubernetes
Apache License 2.0
14.88k stars 1.44k forks source link

Adding a --include-path flag to kaniko build #2884

Open Ga13Ou opened 11 months ago

Ga13Ou commented 11 months ago

Actual behavior Hello Kaniko Team,

I'm encountering a challenge with persistent volume usage in Kaniko. To manage ephemeral storage issues in Kaniko pods, I've set up a PVC/PV and mounted it at /opt/my-user/my-big-dependencies-and-relevant-files for building the image. With the build process utilizing the persistent volume effectively, thereby reducing the load on node ephemeral storage.

However, I encountered an issue where the contents of /opt/my-user/my-big-dependencies-and-relevant-files are not included in the final image that is pushed to the registry. This results in the final image missing installed packages that were expected to be part of it.

Upon investigating, I found that the internal logic of Kaniko, specifically in fs_util.go (fs_util.go#L455C6-L455C32), seems to skip directories listed in /proc/self/mountinfo during the snapshotting process. The logs indicate that /opt/my-user/my-big-dependencies-and-relevant-files is recognized as mounted but is later 'whiteouted' and skipped in the final image.

While Kaniko offers an --ignore-paths flag, it lacks an equivalent include-paths option.

Expected behavior Have the mounted paths be part of the image. Or have flag that can be used to explicitly include those paths

To Reproduce Steps to reproduce the behavior in kubernetes :

  1. Mount a pvc to the kaniko pod on a specific path
  2. Build the image
  3. Note that the specific mounted path is ignored during build and does not exist in the final image.

    Thank you in advance for your assistance and looking forward to a possible enhancement in Kaniko's functionality.

    Triage Notes for the Maintainers

    Description Yes/No
    Please check if this a new feature you are proposing
    • - [ ]
    Please check if the build works in docker but not in kaniko
    • - [ ]
    Please check if this error is seen when you use --cache flag
    • - [ ]
    Please check if your dockerfile is a multistage dockerfile
    • - [ ]
holmesb commented 1 month ago

A new --include-path flag would fix the issue reported by CloudBees. This prevents Kaniko builds working on Jenkins that touch the Jenkins home dir (/home/jenkins).