Skip to content

Commit

Permalink
Merge pull request #114 from depot/feat/delete-load-lease
Browse files Browse the repository at this point in the history
feat(load): remove lease for exported image
  • Loading branch information
goller authored May 6, 2023
2 parents a88e3c4 + 7709973 commit 415dbb5
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 13 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/charmbracelet/lipgloss v0.6.0
github.com/cli/safeexec v1.0.0
github.com/containerd/console v1.0.3
github.com/containerd/containerd v1.6.18
github.com/containerd/containerd v1.6.20
github.com/docker/buildx v0.10.3
github.com/docker/cli v23.0.0+incompatible
github.com/docker/cli-docs-tool v0.5.1
Expand Down Expand Up @@ -69,7 +69,7 @@ require (
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/compose-spec/compose-go v1.6.0 // indirect
github.com/containerd/continuity v0.3.0 // indirect
github.com/containerd/ttrpc v1.1.1-0.20220420014843-944ef4a40df3 // indirect
github.com/containerd/ttrpc v1.1.1 // indirect
github.com/containerd/typeurl v1.0.3-0.20220422153119-7f6e6d160d67 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/distribution/distribution/v3 v3.0.0-20220725133111-4bf3547399eb // indirect
Expand Down Expand Up @@ -182,7 +182,7 @@ require (
)

replace (
github.com/moby/buildkit => github.com/depot/buildkit v0.11.5-depot.1
github.com/moby/buildkit => github.com/depot/buildkit v0.11.6-depot.2
k8s.io/api => k8s.io/api v0.22.4
k8s.io/apimachinery => k8s.io/apimachinery v0.22.4
k8s.io/client-go => k8s.io/client-go v0.22.4
Expand Down
17 changes: 9 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE=
github.com/Microsoft/hcsshim v0.9.6 h1:VwnDOgLeoi2du6dAznfmspNqTiwczvjv4K7NxuY9jsY=
github.com/Microsoft/hcsshim v0.9.8 h1:lf7xxK2+Ikbj9sVf2QZsouGjRjEp2STj1yDHgoVtU5k=
github.com/NYTimes/gziphandler v0.0.0-20170623195520-56545f4a5d46/go.mod h1:3wb06e3pkSAbeQ52E9H9iFoQsEEwGN64994WTCIhntQ=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/PuerkitoBio/purell v1.1.1/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbtSwDGJws/X0=
Expand Down Expand Up @@ -155,16 +155,16 @@ github.com/compose-spec/compose-go v1.6.0/go.mod h1:os+Ulh2jlZxY1XT1hbciERadjSUU
github.com/containerd/cgroups v1.0.4 h1:jN/mbWBEaz+T1pi5OFtnkQ+8qnmEbAr1Oo1FRm5B0dA=
github.com/containerd/console v1.0.3 h1:lIr7SlA5PxZyMV30bDW0MGbiOPXwc63yRuCP0ARubLw=
github.com/containerd/console v1.0.3/go.mod h1:7LqA/THxQ86k76b8c/EMSiaJ3h1eZkMkXar0TQ1gf3U=
github.com/containerd/containerd v1.6.18 h1:qZbsLvmyu+Vlty0/Ex5xc0z2YtKpIsb5n45mAMI+2Ns=
github.com/containerd/containerd v1.6.18/go.mod h1:1RdCUu95+gc2v9t3IL+zIlpClSmew7/0YS8O5eQZrOw=
github.com/containerd/containerd v1.6.20 h1:+itjwpdqXpzHB/QAiWc/BZCjjVfcNgw69w/oIeF4Oy0=
github.com/containerd/containerd v1.6.20/go.mod h1:apei1/i5Ux2FzrK6+DM/suEsGuK/MeVOfy8tR2q7Wnw=
github.com/containerd/continuity v0.3.0 h1:nisirsYROK15TAMVukJOUyGJjz4BNQJBVsNvAXZJ/eg=
github.com/containerd/continuity v0.3.0/go.mod h1:wJEAIwKOm/pBZuBd0JmeTvnLquTB1Ag8espWhkykbPM=
github.com/containerd/fifo v1.0.0 h1:6PirWBr9/L7GDamKr+XM0IeUFXu5mf3M/BPpH9gaLBU=
github.com/containerd/nydus-snapshotter v0.3.1 h1:b8WahTrPkt3XsabjG2o/leN4fw3HWZYr+qxo/Z8Mfzk=
github.com/containerd/stargz-snapshotter v0.13.0 h1:3zr1/IkW1aEo6cMYTQeZ4L2jSuCN+F4kgGfjnuowe4U=
github.com/containerd/stargz-snapshotter/estargz v0.13.0 h1:fD7AwuVV+B40p0d9qVkH/Au1qhp8hn/HWJHIYjpEcfw=
github.com/containerd/ttrpc v1.1.1-0.20220420014843-944ef4a40df3 h1:BhCp66ofL8oYcdelc3CBXc2/Pfvvgx+s+mrp9TvNgn8=
github.com/containerd/ttrpc v1.1.1-0.20220420014843-944ef4a40df3/go.mod h1:YYyNVhZrTMiaf51Vj6WhAJqJw+vl/nzABhj8pWrzle4=
github.com/containerd/ttrpc v1.1.1 h1:NoRHS/z8UiHhpY1w0xcOqoJDGf2DHyzXrF0H4l5AE8c=
github.com/containerd/ttrpc v1.1.1/go.mod h1:XX4ZTnoOId4HklF4edwc4DcqskFZuvXB1Evzy5KFQpQ=
github.com/containerd/typeurl v1.0.3-0.20220422153119-7f6e6d160d67 h1:rQvjv7gRi6Ki/NS/U9oLZFhqyk4dh/GH2M3o/4BRkMM=
github.com/containerd/typeurl v1.0.3-0.20220422153119-7f6e6d160d67/go.mod h1:HDkcKOXRnX6yKnXv3P0QrogFi0DoiauK/LpQi961f0A=
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
Expand All @@ -173,8 +173,8 @@ github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/depot/buildkit v0.11.5-depot.1 h1:0RnU+lcM1UapthHpen8Lc83tHCe/gKrmnGUIrwG6Ons=
github.com/depot/buildkit v0.11.5-depot.1/go.mod h1:P5Qi041LvCfhkfYBHry+Rwoo3Wi6H971J2ggE+PcIoo=
github.com/depot/buildkit v0.11.6-depot.2 h1:1qOr69CDATQKOVnkvlbZnynF4LqEGus2It+nEPpfXyY=
github.com/depot/buildkit v0.11.6-depot.2/go.mod h1:Fs+8NbPypNsVOo9DyVAETfMCA9OdfmgJXELJQAO0XKY=
github.com/distribution/distribution/v3 v3.0.0-20220725133111-4bf3547399eb h1:oCCuuU3kMO3sjZH/p7LamvQNW9SWoT4yQuMGcdSxGAE=
github.com/distribution/distribution/v3 v3.0.0-20220725133111-4bf3547399eb/go.mod h1:28YO/VJk9/64+sTGNuYaBjWxrXTPrj0C0XmgTIOjxX4=
github.com/docker/buildx v0.10.3 h1:9bPC/SZV85ZQDAa1rk5bjodsrK8HIBFThOUpWc052t0=
Expand Down Expand Up @@ -395,6 +395,7 @@ github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM=
github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
github.com/klauspost/pgzip v1.2.5 h1:qnWYvvKqedOF2ulHpMG72XQol4ILEJ8k2wwRl/Km8oE=
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/konsorten/go-windows-terminal-sequences v1.0.3/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
Expand Down Expand Up @@ -495,7 +496,7 @@ github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b h1:YWuSjZCQAPM8UUBLkYUk1e+rZcvWHJmFb6i6rM44Xs8=
github.com/opencontainers/image-spec v1.1.0-rc2.0.20221005185240-3a7f492d3f1b/go.mod h1:3OVijpioIKYWTqjiG0zfF6wvoJ4fAXGbjdZuI2NgsRQ=
github.com/opencontainers/runc v1.1.3 h1:vIXrkId+0/J2Ymu2m7VjGvbSlAId9XNRPhn2p4b+d8w=
github.com/opencontainers/runc v1.1.5 h1:L44KXEpKmfWDcS02aeGm8QNTFXTo2D+8MYGDIJ/GDEs=
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 h1:3snG66yBm59tKhhSPQrQ/0bCrv1LQbKt40LnUPiUxdc=
github.com/opencontainers/selinux v1.10.2 h1:NFy2xCsjn7+WspbfZkUd5zyVeisV7VFbPSP96+8/ha4=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
Expand Down
6 changes: 4 additions & 2 deletions pkg/buildx/commands/bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,10 @@ func RunBake(dockerCli command.Cli, targets []string, in BakeOptions) (err error
for i := range resp {
func(i int) {
eg.Go(func() error {
targetResponse := resp[i]
return load.DepotFastLoad(ctx2, dockerCli.Client(), []build.DepotBuildResponse{targetResponse}, pullOpts, printer)
depotResponses := []build.DepotBuildResponse{resp[i]}
err := load.DepotFastLoad(ctx2, dockerCli.Client(), depotResponses, pullOpts, printer)
load.DeleteExportLeases(ctx2, depotResponses)
return err
})
}(i)
}
Expand Down
1 change: 1 addition & 0 deletions pkg/buildx/commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,7 @@ func buildTargets(ctx context.Context, dockerCli command.Cli, nodes []builder.No
}
}
}
load.DeleteExportLeases(ctx, resp)

if err := printer.Wait(); err != nil {
return nil, nil, err
Expand Down
1 change: 1 addition & 0 deletions pkg/load/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ func WithDepotImagePull(buildOpts map[string]build.Options, loadOpts DepotLoadOp
}

export.Attrs["oci-mediatypes"] = "true"
export.Attrs["depot.export.lease"] = "true"
}
buildOpt.Exports[i] = export
}
Expand Down
49 changes: 49 additions & 0 deletions pkg/load/leases.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package load

import (
"context"
"fmt"

leasesapi "github.com/containerd/containerd/api/services/leases/v1"
depotbuild "github.com/depot/cli/pkg/buildx/build"
"github.com/moby/buildkit/depot"
)

// DeleteExportLeases removes the long-lived leases we use to inhibit garbage collection of exported images.
func DeleteExportLeases(ctx context.Context, responses []depotbuild.DepotBuildResponse) {
for _, res := range responses {
for _, nodeRes := range res.NodeResponses {
if nodeRes.SolveResponse == nil {
continue
}
leaseID := nodeRes.SolveResponse.ExporterResponse[depot.ExportLeaseLabel]
if leaseID == "" {
continue
}

leasesClient, err := leasesClient(ctx, nodeRes)
if err != nil {
// Older versions of buildkitd may not have the leases API exposed.
continue
}
_, _ = leasesClient.Delete(ctx, &leasesapi.DeleteRequest{ID: leaseID})
}
}
}

func leasesClient(ctx context.Context, nodeResponse depotbuild.DepotNodeResponse) (leasesapi.LeasesClient, error) {
if nodeResponse.Node.Driver == nil {
return nil, fmt.Errorf("node %s does not have a driver", nodeResponse.Node.Name)
}

client, err := nodeResponse.Node.Driver.Client(ctx)
if err != nil {
return nil, err
}

if client == nil {
return nil, fmt.Errorf("node %s does not have a client", nodeResponse.Node.Name)
}

return client.LeasesClient(), nil
}
1 change: 1 addition & 0 deletions pkg/load/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func DepotFastLoad(ctx context.Context, dockerapi docker.APIClient, resp []depot
if err != nil {
return err
}

pullOpt := pullOpts[buildRes.Name]
proxyOpts := &ProxyOpts{
RawManifest: manifest,
Expand Down

0 comments on commit 415dbb5

Please sign in to comment.