Skip to content

Commit 056514d

Browse files
committed
introduce build --check
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent bf6b447 commit 056514d

3 files changed

Lines changed: 14 additions & 3 deletions

File tree

cmd/compose/build.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ type buildOptions struct {
4646
builder string
4747
deps bool
4848
print bool
49+
check bool
4950
}
5051

5152
func (opts buildOptions) toAPIBuildOptions(services []string) (api.BuildOptions, error) {
@@ -80,6 +81,7 @@ func (opts buildOptions) toAPIBuildOptions(services []string) (api.BuildOptions,
8081
Deps: opts.deps,
8182
Memory: int64(opts.memory),
8283
Print: opts.print,
84+
Check: opts.check,
8385
SSHs: SSHKeys,
8486
Builder: builderName,
8587
}, nil
@@ -136,6 +138,7 @@ func buildCommand(p *ProjectOptions, dockerCli command.Cli, backend api.Service)
136138
flags.StringVar(&p.Progress, "progress", string(buildkit.AutoMode), fmt.Sprintf(`Set type of ui output (%s)`, strings.Join(printerModes, ", ")))
137139
flags.MarkHidden("progress") //nolint:errcheck
138140
flags.BoolVar(&opts.print, "print", false, "Print equivalent bake file")
141+
flags.BoolVar(&opts.check, "check", false, "Check build configuration")
139142

140143
return cmd
141144
}

pkg/api/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,8 @@ type BuildOptions struct {
157157
Builder string
158158
// Print don't actually run builder but print equivalent build config
159159
Print bool
160+
// Check let builder validate build configuration
161+
Check bool
160162
}
161163

162164
// Apply mutates project according to build options

pkg/compose/build_bake.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,14 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
172172
}
173173

174174
var output string
175+
call := "build"
175176
push := options.Push && service.Image != ""
176-
if len(service.Build.Platforms) > 1 {
177+
switch {
178+
case options.Check:
179+
call = "lint"
180+
case len(service.Build.Platforms) > 1:
177181
output = fmt.Sprintf("type=image,push=%t", push)
178-
} else {
182+
default:
179183
output = fmt.Sprintf("type=docker,load=true,push=%t", push)
180184
}
181185

@@ -207,7 +211,9 @@ func (s *composeService) doBuildBake(ctx context.Context, project *types.Project
207211
ShmSize: build.ShmSize,
208212
Ulimits: toBakeUlimits(build.Ulimits),
209213
Entitlements: entitlements,
210-
Outputs: []string{output},
214+
215+
Outputs: []string{output},
216+
Call: call,
211217
}
212218
group.Targets = append(group.Targets, serviceName)
213219
}

0 commit comments

Comments
 (0)