Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bake/bake.go
Original file line number Diff line number Diff line change
Expand Up @@ -1544,12 +1544,12 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
return nil, err
}

annotations, err := buildflags.ParseAnnotations(t.Annotations)
bo.Annotations, err = buildflags.ParseAnnotations(t.Annotations)
if err != nil {
return nil, err
}
for _, e := range bo.Exports {
for k, v := range annotations {
for k, v := range bo.Annotations {
e.Attrs[k.String()] = v
}
}
Expand Down
1 change: 1 addition & 0 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ type Options struct {
ProvenanceResponseMode confutil.MetadataProvenanceMode
SourcePolicy *spb.Policy
GroupRef string
Annotations map[exptypes.AnnotationKey]string // Not used during build, annotations are already set in Exports. Just used to check for support with drivers.
}

type CallFunc struct {
Expand Down
15 changes: 15 additions & 0 deletions build/opt.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/moby/buildkit/client"
"github.com/moby/buildkit/client/llb"
"github.com/moby/buildkit/client/ociindex"
"github.com/moby/buildkit/exporter/containerimage/exptypes"
gateway "github.com/moby/buildkit/frontend/gateway/client"
"github.com/moby/buildkit/identity"
"github.com/moby/buildkit/session"
Expand Down Expand Up @@ -180,6 +181,20 @@ func toSolveOpt(ctx context.Context, node builder.Node, multiDriver bool, opt *O
}
}

// check if index annotations are supported by docker driver
if len(opt.Exports) > 0 && opt.CallFunc == nil && len(opt.Annotations) > 0 && nodeDriver.IsMobyDriver() && !nodeDriver.Features(ctx)[driver.MultiPlatform] {
for _, exp := range opt.Exports {
if exp.Type == "image" || exp.Type == "docker" {
for ak := range opt.Annotations {
switch ak.Type {
case exptypes.AnnotationIndex, exptypes.AnnotationIndexDescriptor:
return nil, nil, errors.New("index annotations not supported for single platform export")
}
}
}
}
}

// fill in image exporter names from tags
if len(opt.Tags) > 0 {
tags := make([]string, len(opt.Tags))
Expand Down
4 changes: 2 additions & 2 deletions commands/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -1062,13 +1062,13 @@ func RunBuild(ctx context.Context, dockerCli command.Cli, in *BuildOptions, inSt
}
}

annotations, err := buildflags.ParseAnnotations(in.Annotations)
opts.Annotations, err = buildflags.ParseAnnotations(in.Annotations)
if err != nil {
return nil, nil, errors.Wrap(err, "parse annotations")
}

for _, o := range outputs {
for k, v := range annotations {
for k, v := range opts.Annotations {
o.Attrs[k.String()] = v
}
}
Expand Down
12 changes: 12 additions & 0 deletions tests/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ var buildTests = []func(t *testing.T, sb integration.Sandbox){
testBuildCall,
testBuildCheckCallOutput,
testBuildExtraHosts,
testBuildIndexAnnotationsLoadDocker,
}

func testBuild(t *testing.T, sb integration.Sandbox) {
Expand Down Expand Up @@ -1341,6 +1342,17 @@ RUN cat /etc/hosts | grep myhostmulti | grep 162.242.195.82
require.NoError(t, err, string(out))
}

func testBuildIndexAnnotationsLoadDocker(t *testing.T, sb integration.Sandbox) {
if sb.DockerAddress() == "" {
t.Skip("only testing with docker available")
}
skipNoCompatBuildKit(t, sb, ">= 0.11.0-0", "annotations")
dir := createTestProject(t)
out, err := buildCmd(sb, withArgs("--annotation", "index:foo=bar", "--provenance", "false", "--output", "type=docker", dir))
require.Error(t, err, out)
require.Contains(t, out, "index annotations not supported for single platform export")
}

func createTestProject(t *testing.T) string {
dockerfile := []byte(`
FROM busybox:latest AS base
Expand Down