Skip to content

Commit

Permalink
Merge pull request #255 from depot/imagetools
Browse files Browse the repository at this point in the history
Upgrade buildx imagetools
  • Loading branch information
jacobwgillespie authored Mar 6, 2024
2 parents d7d892c + 3ce6bbb commit acff7e9
Show file tree
Hide file tree
Showing 16 changed files with 1,327 additions and 22 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.20.5"
go-version: "1.21"
check-latest: true
cache: true

Expand Down Expand Up @@ -53,7 +53,7 @@ jobs:
- uses: golangci/golangci-lint-action@v4
with:
version: v1.53.3
version: v1.56.2
only-new-issues: false
skip-cache: false
skip-build-cache: true
Expand All @@ -74,7 +74,7 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.20.5"
go-version: "1.21"
check-latest: true
cache: true

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- uses: actions/setup-go@v5
with:
go-version: "1.20.5"
go-version: "1.21"
check-latest: true
cache: true

Expand Down
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
run:
go: "1.20"
go: "1.21"
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM --platform=$BUILDPLATFORM golang:1.20.11 AS build
FROM --platform=$BUILDPLATFORM golang:1.21 AS build
WORKDIR /src
ARG LDFLAGS
ARG TARGETARCH
Expand Down
2 changes: 1 addition & 1 deletion examples/go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/depot/cli/examples

go 1.20
go 1.21

require (
github.com/depot/cli v1.8.3
Expand Down
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/depot/cli

go 1.20
go 1.21

require (
buf.build/gen/go/depot/api/connectrpc/go v1.15.0-20240221184445-e8316610338f.1
Expand All @@ -15,6 +15,7 @@ require (
github.com/compose-spec/compose-go v1.6.0
github.com/containerd/console v1.0.4-0.20230313162750-1ae8d489ac81
github.com/containerd/containerd v1.6.20
github.com/containerd/log v0.1.0
github.com/distribution/reference v0.5.0
github.com/docker/buildx v0.10.3
github.com/docker/cli v24.0.7+incompatible
Expand All @@ -37,7 +38,7 @@ require (
github.com/pkg/errors v0.9.1
github.com/pyroscope-io/client v0.7.2
github.com/savioxavier/termlink v1.2.1
github.com/sirupsen/logrus v1.9.0
github.com/sirupsen/logrus v1.9.3
github.com/spf13/cobra v1.6.1
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.14.0
Expand Down Expand Up @@ -189,6 +190,7 @@ require (
)

replace (
github.com/docker/docker => github.com/docker/docker v24.0.9+incompatible
github.com/moby/buildkit => github.com/depot/buildkit v0.11.6-depot.34
k8s.io/api => k8s.io/api v0.22.4
k8s.io/apimachinery => k8s.io/apimachinery v0.22.4
Expand Down
55 changes: 51 additions & 4 deletions go.sum

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions pkg/buildx/build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import (
"github.com/containerd/containerd/images"
"github.com/containerd/containerd/platforms"
depotbuild "github.com/depot/cli/pkg/build"
"github.com/depot/cli/pkg/buildx/imagetools"
"github.com/distribution/reference"
"github.com/docker/buildx/builder"
"github.com/docker/buildx/driver"
"github.com/docker/buildx/util/dockerutil"
"github.com/docker/buildx/util/imagetools"
"github.com/docker/buildx/util/progress"
"github.com/docker/buildx/util/resolver"
"github.com/docker/buildx/util/waitmap"
Expand Down Expand Up @@ -1167,7 +1167,11 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
var driverIndex int

for _, dp := range dps {
imageopt = nodes[dp.driverIndex].ImageOpt
opt := nodes[dp.driverIndex].ImageOpt
imageopt = imagetools.Opt{
Auth: opt.Auth,
RegistryConfig: opt.RegistryConfig,
}
driverIndex = dp.driverIndex
break
}
Expand Down Expand Up @@ -1206,7 +1210,7 @@ func BuildWithResultHandler(ctx context.Context, nodes []builder.Node, opt map[s
}
}

dt, desc, err := itpull.Combine(ctx, srcs)
dt, desc, err := itpull.Combine(ctx, srcs, nil)
if err != nil {
return err
}
Expand Down
5 changes: 3 additions & 2 deletions pkg/buildx/builder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (
"sync"

depotbuild "github.com/depot/cli/pkg/build"
"github.com/depot/cli/pkg/buildx/imagetools"
"github.com/docker/buildx/driver"
"github.com/docker/buildx/store"
"github.com/docker/buildx/store/storeutil"
"github.com/docker/buildx/util/dockerutil"
"github.com/docker/buildx/util/imagetools"
"github.com/docker/buildx/util/progress"
"github.com/docker/cli/cli/command"
v1 "github.com/opencontainers/image-spec/specs-go/v1"
Expand Down Expand Up @@ -165,7 +165,8 @@ func (b *Builder) ContextName() string {

// ImageOpt returns registry auth configuration
func (b *Builder) ImageOpt() (imagetools.Opt, error) {
return storeutil.GetImageConfig(b.opts.dockerCli, b.NodeGroup)
opt, err := storeutil.GetImageConfig(b.opts.dockerCli, b.NodeGroup)
return imagetools.Opt{Auth: opt.Auth, RegistryConfig: opt.RegistryConfig}, err
}

// Boot bootstrap a builder
Expand Down
14 changes: 12 additions & 2 deletions pkg/buildx/builder/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@ package builder
import (
"context"

"github.com/depot/cli/pkg/buildx/imagetools"
buildxbuilder "github.com/docker/buildx/builder"
"github.com/docker/buildx/driver"
ctxkube "github.com/docker/buildx/driver/kubernetes/context"
"github.com/docker/buildx/store"
"github.com/docker/buildx/store/storeutil"
"github.com/docker/buildx/util/dockerutil"
"github.com/docker/buildx/util/imagetools"
buildximagetools "github.com/docker/buildx/util/imagetools"
"github.com/docker/buildx/util/platformutil"
"github.com/moby/buildkit/util/grpcerrors"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
Expand All @@ -33,7 +34,16 @@ type Node struct {
func ToBuildxNodes(nodes []Node) []buildxbuilder.Node {
ret := make([]buildxbuilder.Node, len(nodes))
for i, n := range nodes {
ret[i] = buildxbuilder.Node(n)
ret[i] = buildxbuilder.Node{
Node: n.Node,
Driver: n.Driver,
DriverInfo: n.DriverInfo,
Platforms: n.Platforms,
ImageOpt: buildximagetools.Opt{Auth: n.ImageOpt.Auth, RegistryConfig: n.ImageOpt.RegistryConfig},
ProxyConfig: n.ProxyConfig,
Version: n.Version,
Err: n.Err,
}
}
return ret
}
Expand Down
53 changes: 53 additions & 0 deletions pkg/buildx/imagetools/buildflags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package imagetools

import (
"regexp"
"strings"

"github.com/containerd/containerd/platforms"
"github.com/moby/buildkit/exporter/containerimage/exptypes"
ocispecs "github.com/opencontainers/image-spec/specs-go/v1"
"github.com/pkg/errors"
)

func ParseAnnotations(inp []string) (map[exptypes.AnnotationKey]string, error) {
// TODO: use buildkit's annotation parser once it supports setting custom prefix and ":" separator
annotationRegexp := regexp.MustCompile(`^(?:([a-z-]+)(?:\[([A-Za-z0-9_/-]+)\])?:)?(\S+)$`)
annotations := make(map[exptypes.AnnotationKey]string)
for _, inp := range inp {
k, v, ok := strings.Cut(inp, "=")
if !ok {
return nil, errors.Errorf("invalid annotation %q, expected key=value", inp)
}

groups := annotationRegexp.FindStringSubmatch(k)
if groups == nil {
return nil, errors.Errorf("invalid annotation format, expected <type>:<key>=<value>, got %q", inp)
}

typ, platform, key := groups[1], groups[2], groups[3]
switch typ {
case "":
case exptypes.AnnotationIndex, exptypes.AnnotationIndexDescriptor, exptypes.AnnotationManifest, exptypes.AnnotationManifestDescriptor:
default:
return nil, errors.Errorf("unknown annotation type %q", typ)
}

var ociPlatform *ocispecs.Platform
if platform != "" {
p, err := platforms.Parse(platform)
if err != nil {
return nil, errors.Wrapf(err, "invalid platform %q", platform)
}
ociPlatform = &p
}

ak := exptypes.AnnotationKey{
Type: typ,
Platform: ociPlatform,
Key: key,
}
annotations[ak] = v
}
return annotations, nil
}
Loading

0 comments on commit acff7e9

Please sign in to comment.