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

feat: allow specifying Kaniko targets for multi-stage dockerfiles #436

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hamishc
Copy link

@hamishc hamishc commented Dec 16, 2024

I've encountered issues with large multi-stage dockerfiles when targeting one particular stage. For example, if we have a devcontainer.json like

{
    "name": "envbuilder",
    "build": {
		"dockerfile": "Dockerfile",
		"args": {
		},
        "target": "devenv"
	},
}

and a Dockerfile as the following

FROM alpine AS runtime-deps

FROM runtime-deps AS devenv

FROM runtime-deps AS long-build-stage
COPY some-build-artifact/ /

then running docker run -it -v /my/repo:/workspaces/empty coder/envbuilder:latest will result in the following error

Failed to build: do build: error building stage: failed to get files used from context: failed to get fileinfo for /workspaces/empty/.devcontainer/some-build-artifact: lstat /workspaces/empty/.devcontainer/some-build-artifact: no such file or directory
Falling back to the default image...
error: do build: error building stage: failed to get files used from context: failed to get fileinfo for /workspaces/empty/.devcontainer/some-build-artifact: lstat /workspaces/empty/.devcontainer/some-build-artifact: no such file or directory: no fallback image has been specified
error: running command "envbuilder": do build: error building stage: failed to get files used from context: failed to get fileinfo for /workspaces/empty/.devcontainer/some-build-artifact: lstat /workspaces/empty/.devcontainer/some-build-artifact: no such file or directory:
    github.com/coder/envbuilder.run.func4
        /home/hamish/code/envbuilder/envbuilder.go:271
  - no fallback image has been specified

This is because we don't specify the build target in KanikoOptions. Specifying this option can also substantially decrease build times, especially when combined with the SkipUnusedStages option - which can allow for large unused build stages to be avoided entirely.

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

Successfully merging this pull request may close these issues.

1 participant