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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions devcontainer/devcontainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type Compiled struct {
BuildContext string
FeatureContexts map[string]string
BuildArgs []string
Target string

User string
ContainerEnv map[string]string
Expand Down Expand Up @@ -140,6 +141,7 @@ func (s Spec) HasDockerfile() bool {
func (s *Spec) Compile(fs billy.Filesystem, devcontainerDir, scratchDir string, fallbackDockerfile, workspaceFolder string, useBuildContexts bool, lookupEnv func(string) (string, bool)) (*Compiled, error) {
params := &Compiled{
User: s.ContainerUser,
Target: s.Build.Target,
ContainerEnv: s.ContainerEnv,
RemoteEnv: s.RemoteEnv,
}
Expand Down
1 change: 1 addition & 0 deletions docs/env-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
| `--ignore-paths` | `ENVBUILDER_IGNORE_PATHS` | | The comma separated list of paths to ignore when building the workspace. |
| `--build-secrets` | `ENVBUILDER_BUILD_SECRETS` | | The list of secret environment variables to use when building the image. |
| `--skip-rebuild` | `ENVBUILDER_SKIP_REBUILD` | | Skip building if the MagicFile exists. This is used to skip building when a container is restarting. e.g. docker stop -> docker start This value can always be set to true - even if the container is being started for the first time. |
| `--skip-unused-stages` | `ENVBUILDER_SKIP_UNUSED_STAGES` | | 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. |
| `--git-url` | `ENVBUILDER_GIT_URL` | | The URL of a Git repository containing a Devcontainer or Docker image to clone. This is optional. |
| `--git-clone-depth` | `ENVBUILDER_GIT_CLONE_DEPTH` | | The depth to use when cloning the Git repository. |
| `--git-clone-single-branch` | `ENVBUILDER_GIT_CLONE_SINGLE_BRANCH` | | Clone only a single branch of the Git repository. |
Expand Down
2 changes: 2 additions & 0 deletions envbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,8 @@ func run(ctx context.Context, opts options.Options, execArgs *execArgsInfo) erro
CustomPlatform: platforms.Format(platforms.Normalize(platforms.DefaultSpec())),
SnapshotMode: "redo",
RunV2: true,
SkipUnusedStages: opts.SkipUnusedStages,
Target: buildParams.Target,
RunStdout: stdoutWriter,
RunStderr: stderrWriter,
Destinations: destinations,
Expand Down
12 changes: 12 additions & 0 deletions options/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ type Options struct {
// This value can always be set to true - even if the container is being
// started for the first time.
SkipRebuild bool
// SkipUnusedStages builds only used stages if defined to true. Otherwise,
// it builds by default all stages, even the unnecessary ones until it
// reaches the target stage / end of Dockerfile
SkipUnusedStages bool
// GitURL is the URL of the Git repository to clone. This is optional.
GitURL string
// GitCloneDepth is the depth to use when cloning the Git repository.
Expand Down Expand Up @@ -357,6 +361,14 @@ func (o *Options) CLI() serpent.OptionSet {
"docker start This value can always be set to true - even if the " +
"container is being started for the first time.",
},
{
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.",
},
{
Flag: "git-url",
Env: WithEnvPrefix("GIT_URL"),
Expand Down
4 changes: 4 additions & 0 deletions options/testdata/options.golden
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ OPTIONS:
when a container is restarting. e.g. docker stop -> docker start This
value can always be set to true - even if the container is being
started for the first time.
--skip-unused-stages bool, $ENVBUILDER_SKIP_UNUSED_STAGES
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.

--ssl-cert-base64 string, $ENVBUILDER_SSL_CERT_BASE64
The content of an SSL cert file. This is useful for self-signed
Expand Down