Skip to content

Commit 1cae7b3

Browse files
geroplcsweichel
authored andcommitted
add "docker-build-options" for passing options to "docker build"
1 parent 7ad80d7 commit 1cae7b3

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

cmd/build.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ func addBuildFlags(cmd *cobra.Command) {
171171
cmd.Flags().Bool("dont-retag", false, "Disable Docker image re-tagging (defaults to false)")
172172
cmd.Flags().UintP("max-concurrent-tasks", "j", uint(runtime.NumCPU()), "Limit the number of max concurrent build tasks - set to 0 to disable the limit")
173173
cmd.Flags().String("coverage-output-path", "", "Output path where test coverage file will be copied after running tests")
174+
cmd.Flags().StringToString("docker-build-options", nil, "Options passed to all 'docker build' commands")
174175
}
175176

176177
func getBuildOpts(cmd *cobra.Command) ([]leeway.BuildOption, *leeway.FilesystemCache) {
@@ -275,6 +276,12 @@ func getBuildOpts(cmd *cobra.Command) ([]leeway.BuildOption, *leeway.FilesystemC
275276
_ = os.MkdirAll(coverageOutputPath, 0644)
276277
}
277278

279+
var dockerBuildOptions leeway.DockerBuildOptions
280+
dockerBuildOptions, err = cmd.Flags().GetStringToString("docker-build-options")
281+
if err != nil {
282+
log.Fatal(err)
283+
}
284+
278285
return []leeway.BuildOption{
279286
leeway.WithLocalCache(localCache),
280287
leeway.WithRemoteCache(remoteCache),
@@ -286,6 +293,7 @@ func getBuildOpts(cmd *cobra.Command) ([]leeway.BuildOption, *leeway.FilesystemC
286293
leeway.WithMaxConcurrentTasks(int64(maxConcurrentTasks)),
287294
leeway.WithCoverageOutputPath(coverageOutputPath),
288295
leeway.WithDontRetag(dontRetag),
296+
leeway.WithDockerBuildOptions(&dockerBuildOptions),
289297
}, localCache
290298
}
291299

pkg/leeway/build.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,14 @@ type buildOptions struct {
213213
MaxConcurrentTasks int64
214214
CoverageOutputPath string
215215
DontRetag bool
216+
DockerBuildOptions *DockerBuildOptions
216217

217218
context *buildContext
218219
}
219220

221+
// DockerBuildOptions are options passed to "docker build"
222+
type DockerBuildOptions map[string]string
223+
220224
// BuildOption configures the build behaviour
221225
type BuildOption func(*buildOptions) error
222226

@@ -304,6 +308,14 @@ func WithDontRetag(dontRetag bool) BuildOption {
304308
}
305309
}
306310

311+
// WithDockerBuildOptions are passed to "docker build"
312+
func WithDockerBuildOptions(dockerBuildOpts *DockerBuildOptions) BuildOption {
313+
return func(opts *buildOptions) error {
314+
opts.DockerBuildOptions = dockerBuildOpts
315+
return nil
316+
}
317+
}
318+
307319
func withBuildContext(ctx *buildContext) BuildOption {
308320
return func(opts *buildOptions) error {
309321
opts.context = ctx
@@ -1019,6 +1031,11 @@ func (p *Package) buildDocker(buildctx *buildContext, wd, result string) (err er
10191031
if cfg.Squash {
10201032
buildcmd = append(buildcmd, "--squash")
10211033
}
1034+
if buildctx.DockerBuildOptions != nil {
1035+
for opt, v := range *buildctx.DockerBuildOptions {
1036+
buildcmd = append(buildcmd, fmt.Sprintf("--%s=%s", opt, v))
1037+
}
1038+
}
10221039
buildcmd = append(buildcmd, ".")
10231040
commands = append(commands, buildcmd)
10241041

0 commit comments

Comments
 (0)