Skip to content

Commit 497d803

Browse files
author
Hamish
committed
Added the ability to specify build targets for kaniko build and an option to skip building unused layers
1 parent 440ac5c commit 497d803

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

devcontainer/devcontainer.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type Compiled struct {
6969
BuildContext string
7070
FeatureContexts map[string]string
7171
BuildArgs []string
72+
Target string
7273

7374
User string
7475
ContainerEnv map[string]string
@@ -140,6 +141,7 @@ func (s Spec) HasDockerfile() bool {
140141
func (s *Spec) Compile(fs billy.Filesystem, devcontainerDir, scratchDir string, fallbackDockerfile, workspaceFolder string, useBuildContexts bool, lookupEnv func(string) (string, bool)) (*Compiled, error) {
141142
params := &Compiled{
142143
User: s.ContainerUser,
144+
Target: s.Build.Target,
143145
ContainerEnv: s.ContainerEnv,
144146
RemoteEnv: s.RemoteEnv,
145147
}

docs/env-variables.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
| `--ignore-paths` | `ENVBUILDER_IGNORE_PATHS` | | The comma separated list of paths to ignore when building the workspace. |
2525
| `--build-secrets` | `ENVBUILDER_BUILD_SECRETS` | | The list of secret environment variables to use when building the image. |
2626
| `--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. |
27+
| `--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. |
2728
| `--git-url` | `ENVBUILDER_GIT_URL` | | The URL of a Git repository containing a Devcontainer or Docker image to clone. This is optional. |
2829
| `--git-clone-depth` | `ENVBUILDER_GIT_CLONE_DEPTH` | | The depth to use when cloning the Git repository. |
2930
| `--git-clone-single-branch` | `ENVBUILDER_GIT_CLONE_SINGLE_BRANCH` | | Clone only a single branch of the Git repository. |

envbuilder.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -539,6 +539,8 @@ func run(ctx context.Context, opts options.Options, execArgs *execArgsInfo) erro
539539
CustomPlatform: platforms.Format(platforms.Normalize(platforms.DefaultSpec())),
540540
SnapshotMode: "redo",
541541
RunV2: true,
542+
SkipUnusedStages: opts.SkipUnusedStages,
543+
Target: buildParams.Target,
542544
RunStdout: stdoutWriter,
543545
RunStderr: stderrWriter,
544546
Destinations: destinations,

options/options.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ type Options struct {
100100
// This value can always be set to true - even if the container is being
101101
// started for the first time.
102102
SkipRebuild bool
103+
// SkipUnusedStages builds only used stages if defined to true. Otherwise,
104+
// it builds by default all stages, even the unnecessary ones until it
105+
// reaches the target stage / end of Dockerfile
106+
SkipUnusedStages bool
103107
// GitURL is the URL of the Git repository to clone. This is optional.
104108
GitURL string
105109
// GitCloneDepth is the depth to use when cloning the Git repository.
@@ -357,6 +361,14 @@ func (o *Options) CLI() serpent.OptionSet {
357361
"docker start This value can always be set to true - even if the " +
358362
"container is being started for the first time.",
359363
},
364+
{
365+
Flag: "skip-unused-stages",
366+
Env: WithEnvPrefix("SKIP_UNUSED_STAGES"),
367+
Value: serpent.BoolOf(&o.SkipUnusedStages),
368+
Description: "Skip building all unused docker stages. Otherwise it builds by " +
369+
"default all stages, even the unnecessary ones until it reaches the " +
370+
"target stage / end of Dockerfile.",
371+
},
360372
{
361373
Flag: "git-url",
362374
Env: WithEnvPrefix("GIT_URL"),

options/testdata/options.golden

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ OPTIONS:
173173
when a container is restarting. e.g. docker stop -> docker start This
174174
value can always be set to true - even if the container is being
175175
started for the first time.
176+
--skip-unused-stages bool, $ENVBUILDER_SKIP_UNUSED_STAGES
177+
Skip building all unused docker stages. Otherwise it builds by default
178+
all stages, even the unnecessary ones until it reaches the target
179+
stage / end of Dockerfile.
176180

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

0 commit comments

Comments
 (0)