Uh oh!
There was an error while loading. Please reload this page.
feat: allow specifying Kaniko targets for multi-stage dockerfiles - #436
feat: allow specifying Kaniko targets for multi-stage dockerfiles#436hamishc wants to merge 6 commits into
Conversation
…tion to skip building unused layers
hamishc
commented
Mar 14, 2025
Any chance getting this reviewed sometime soon? This is blocking the adoption of coder for our org, as we rely on multi-stage dockerfiles and devcontainers for most of our repositories. |
bedaberner
commented
May 27, 2025
I would also love to get this. |
johnstcn
left a comment
There was a problem hiding this comment.
Thanks for adding this! Could you add some tests for when this is set?
| require.NoError(t, err) | ||
| file, err := fs.OpenFile(filepath.Join(dcDir, "Dockerfile"), os.O_CREATE|os.O_WRONLY, 0o644) | ||
| require.NoError(t, err) | ||
| _, err = io.WriteString(file, "FROM scratch AS my-target\nUSER testuser") |
There was a problem hiding this comment.
Do we want to also add a second target and then assert that we only go up as far as my-target?
e.g.
FROM scratch AS my-target
USER testuser
FROM my-target AS not-my-target
USER nottestuser
and then assert params.User or similar?
Similarly, what is the expected behaviour for --skip-unused-stages?
| { | ||
| Flag: "skip-unused-stages", | ||
| Env: WithEnvPrefix("SKIP_UNUSED_STAGES"), | ||
| Value: serpent.BoolOf(&o.SkipUnusedStages), | ||
| Description: "Skip building all unused docker stages. Otherwise it builds by " + | ||
| "default all stages, even the unnecessary ones until it reaches the " + | ||
| "target stage / end of Dockerfile.", | ||
| }, |
I've encountered issues with large multi-stage dockerfiles when targeting one particular stage. For example, if we have a devcontainer.json like
and a Dockerfile as the following
then running
docker run -it -v /my/repo:/workspaces/empty coder/envbuilder:latestwill result in the following errorThis is because we don't specify the build target in
KanikoOptions. Specifying this option can also substantially decrease build times, especially when combined with theSkipUnusedStagesoption - which can allow for large unused build stages to be avoided entirely.