Skip to content

Commit fb6a260

Browse files
Merge pull request #399 from depot/fix-bake-load
Fix `--load` attempting to pull extra targets
2 parents 59e0bf0 + 3b74df1 commit fb6a260

File tree

4 files changed

+28
-41
lines changed

4 files changed

+28
-41
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ bin/depot:
44

55
.PHONY: image
66
image:
7-
docker --context=default buildx build --builder default -t public.ecr.aws/depot/cli:0.0.0-dev --load .
7+
docker --context=desktop-linux buildx build --builder desktop-linux -t public.ecr.aws/depot/cli:0.0.0-dev --load .
88

99
.PHONY: npm
1010
npm:

pkg/buildx/commands/bake.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -202,24 +202,28 @@ func RunBake(dockerCli command.Cli, in BakeOptions, validator BakeValidator, pri
202202
// Three concurrent pulls at a time to avoid overwhelming the registry.
203203
eg.SetLimit(3)
204204
for i := range resp {
205-
func(i int, targetsToLoad []string) {
206-
eg.Go(func() error {
207-
depotResponses := []build.DepotBuildResponse{resp[i]}
208-
var err error
209-
// Only load images from requested targets to avoid pulling unnecessary images.
210-
if slices.Contains(targetsToLoad, resp[i].Name) {
211-
reportingPrinter := progresshelper.NewReporter(ctx2, printer, in.buildID, in.token)
212-
defer reportingPrinter.Close()
213-
if in.DepotOptions.loadUsingRegistry && in.DepotOptions.pullInfo != nil {
214-
err = load.DepotLoadFromRegistry(ctx, dockerCli.Client(), in.DepotOptions.pullInfo.Reference, true, pullOpts, reportingPrinter)
215-
} else {
216-
err = load.DepotFastLoad(ctx2, dockerCli.Client(), depotResponses, pullOpts, reportingPrinter)
205+
eg.Go(func() error {
206+
depotResponses := []build.DepotBuildResponse{resp[i]}
207+
var err error
208+
// Only load images from requested targets to avoid pulling unnecessary images.
209+
if slices.Contains(targetsToLoad, resp[i].Name) {
210+
reportingPrinter := progresshelper.NewReporter(ctx2, printer, in.buildID, in.token)
211+
defer reportingPrinter.Close()
212+
213+
if in.DepotOptions.loadUsingRegistry && in.DepotOptions.pullInfo != nil {
214+
target := resp[i].Name
215+
pullOpt, ok := pullOpts[target]
216+
if ok {
217+
pw := progress.WithPrefix(reportingPrinter, target, len(pullOpts) > 1)
218+
err = load.PullImages(ctx, dockerCli.Client(), fmt.Sprintf("%s-%s", in.DepotOptions.pullInfo.Reference, target), pullOpt, pw)
217219
}
220+
} else {
221+
err = load.DepotFastLoad(ctx2, dockerCli.Client(), depotResponses, pullOpts, reportingPrinter)
218222
}
219-
load.DeleteExportLeases(ctx2, depotResponses)
220-
return err
221-
})
222-
}(i, targetsToLoad)
223+
}
224+
load.DeleteExportLeases(ctx2, depotResponses)
225+
return err
226+
})
223227
}
224228

225229
err = eg.Wait()

pkg/buildx/commands/build.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,13 @@ func buildTargets(ctx context.Context, dockerCli command.Cli, nodes []builder.No
330330
reportingPrinter := progresshelper.NewReporter(ctx, printer, depotOpts.buildID, depotOpts.token)
331331

332332
if depotOpts.loadUsingRegistry && depotOpts.pullInfo != nil {
333-
err = load.DepotLoadFromRegistry(ctx, dockerCli.Client(), depotOpts.pullInfo.Reference, false, pullOpts, reportingPrinter)
333+
for target, pullOpt := range pullOpts {
334+
pw := progress.WithPrefix(reportingPrinter, target, len(pullOpts) > 1)
335+
err = load.PullImages(ctx, dockerCli.Client(), depotOpts.pullInfo.Reference, pullOpt, pw)
336+
if err != nil {
337+
break
338+
}
339+
}
334340
} else {
335341
err = load.DepotFastLoad(ctx, dockerCli.Client(), resp, pullOpts, reportingPrinter)
336342
}

pkg/load/load.go

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -75,29 +75,6 @@ func DepotFastLoad(ctx context.Context, dockerapi docker.APIClient, resp []depot
7575
return nil
7676
}
7777

78-
func DepotLoadFromRegistry(ctx context.Context, dockerapi docker.APIClient, reference string, isBake bool, pullOpts map[string]PullOptions, printer progress.Writer) error {
79-
if len(pullOpts) == 0 {
80-
return nil
81-
}
82-
83-
for target, pullOpt := range pullOpts {
84-
pw := progress.WithPrefix(printer, target, len(pullOpts) > 1)
85-
86-
imageName := reference
87-
88-
if isBake {
89-
imageName = fmt.Sprintf("%s-%s", reference, target)
90-
}
91-
92-
err := PullImages(ctx, dockerapi, imageName, pullOpt, pw)
93-
if err != nil {
94-
return fmt.Errorf("failed to pull image: %w", err)
95-
}
96-
}
97-
98-
return nil
99-
}
100-
10178
// For now if there is a multi-platform build we try to only download the
10279
// architecture of the depot CLI host. If there is not a node with the same
10380
// architecture as the depot CLI host, we take the first node in the list.

0 commit comments

Comments
 (0)