Skip to content

Commit

Permalink
Merge pull request #2824 from jsternberg/bake-revert-composable-attri…
Browse files Browse the repository at this point in the history
…butes

[v0.19] revert: "bake: initial set of composable bake attributes"
  • Loading branch information
tonistiigi authored Nov 27, 2024
2 parents 71c7889 + 8b02962 commit 5113f9e
Show file tree
Hide file tree
Showing 24 changed files with 374 additions and 3,642 deletions.
321 changes: 115 additions & 206 deletions bake/bake.go

Large diffs are not rendered by default.

119 changes: 60 additions & 59 deletions bake/bake_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package bake

import (
"context"
"fmt"
"os"
"path/filepath"
"sort"
Expand Down Expand Up @@ -229,7 +228,7 @@ func TestPushOverride(t *testing.T) {
m, _, err := ReadTargets(context.TODO(), []File{fp}, []string{"app"}, []string{"*.push=true"}, nil)
require.NoError(t, err)
require.Equal(t, 1, len(m["app"].Outputs))
require.Equal(t, "type=image,push=true", m["app"].Outputs[0].String())
require.Equal(t, "type=image,push=true", m["app"].Outputs[0])
})

t.Run("type image", func(t *testing.T) {
Expand All @@ -243,7 +242,7 @@ func TestPushOverride(t *testing.T) {
m, _, err := ReadTargets(context.TODO(), []File{fp}, []string{"app"}, []string{"*.push=true"}, nil)
require.NoError(t, err)
require.Equal(t, 1, len(m["app"].Outputs))
require.Equal(t, "type=image,compression=zstd,push=true", m["app"].Outputs[0].String())
require.Equal(t, "type=image,compression=zstd,push=true", m["app"].Outputs[0])
})

t.Run("type image push false", func(t *testing.T) {
Expand All @@ -257,7 +256,7 @@ func TestPushOverride(t *testing.T) {
m, _, err := ReadTargets(context.TODO(), []File{fp}, []string{"app"}, []string{"*.push=false"}, nil)
require.NoError(t, err)
require.Equal(t, 1, len(m["app"].Outputs))
require.Equal(t, "type=image,compression=zstd,push=false", m["app"].Outputs[0].String())
require.Equal(t, "type=image,compression=zstd,push=false", m["app"].Outputs[0])
})

t.Run("type registry", func(t *testing.T) {
Expand All @@ -271,7 +270,7 @@ func TestPushOverride(t *testing.T) {
m, _, err := ReadTargets(context.TODO(), []File{fp}, []string{"app"}, []string{"*.push=true"}, nil)
require.NoError(t, err)
require.Equal(t, 1, len(m["app"].Outputs))
require.Equal(t, "type=registry", m["app"].Outputs[0].String())
require.Equal(t, "type=registry", m["app"].Outputs[0])
})

t.Run("type registry push false", func(t *testing.T) {
Expand Down Expand Up @@ -301,9 +300,9 @@ func TestPushOverride(t *testing.T) {
require.NoError(t, err)
require.Equal(t, 2, len(m))
require.Equal(t, 1, len(m["foo"].Outputs))
require.Equal(t, []string{"type=local,dest=out"}, stringify(m["foo"].Outputs))
require.Equal(t, []string{"type=local,dest=out"}, m["foo"].Outputs)
require.Equal(t, 1, len(m["bar"].Outputs))
require.Equal(t, []string{"type=image,push=true"}, stringify(m["bar"].Outputs))
require.Equal(t, []string{"type=image,push=true"}, m["bar"].Outputs)
})
}

Expand All @@ -318,7 +317,7 @@ func TestLoadOverride(t *testing.T) {
m, _, err := ReadTargets(context.TODO(), []File{fp}, []string{"app"}, []string{"*.load=true"}, nil)
require.NoError(t, err)
require.Equal(t, 1, len(m["app"].Outputs))
require.Equal(t, "type=docker", m["app"].Outputs[0].String())
require.Equal(t, "type=docker", m["app"].Outputs[0])
})

t.Run("type docker", func(t *testing.T) {
Expand All @@ -332,7 +331,7 @@ func TestLoadOverride(t *testing.T) {
m, _, err := ReadTargets(context.TODO(), []File{fp}, []string{"app"}, []string{"*.load=true"}, nil)
require.NoError(t, err)
require.Equal(t, 1, len(m["app"].Outputs))
require.Equal(t, []string{"type=docker"}, stringify(m["app"].Outputs))
require.Equal(t, []string{"type=docker"}, m["app"].Outputs)
})

t.Run("type image", func(t *testing.T) {
Expand All @@ -346,7 +345,7 @@ func TestLoadOverride(t *testing.T) {
m, _, err := ReadTargets(context.TODO(), []File{fp}, []string{"app"}, []string{"*.load=true"}, nil)
require.NoError(t, err)
require.Equal(t, 2, len(m["app"].Outputs))
require.Equal(t, []string{"type=docker", "type=image"}, stringify(m["app"].Outputs))
require.Equal(t, []string{"type=image", "type=docker"}, m["app"].Outputs)
})

t.Run("type image load false", func(t *testing.T) {
Expand All @@ -360,7 +359,7 @@ func TestLoadOverride(t *testing.T) {
m, _, err := ReadTargets(context.TODO(), []File{fp}, []string{"app"}, []string{"*.load=false"}, nil)
require.NoError(t, err)
require.Equal(t, 1, len(m["app"].Outputs))
require.Equal(t, []string{"type=image"}, stringify(m["app"].Outputs))
require.Equal(t, []string{"type=image"}, m["app"].Outputs)
})

t.Run("type registry", func(t *testing.T) {
Expand All @@ -374,7 +373,7 @@ func TestLoadOverride(t *testing.T) {
m, _, err := ReadTargets(context.TODO(), []File{fp}, []string{"app"}, []string{"*.load=true"}, nil)
require.NoError(t, err)
require.Equal(t, 2, len(m["app"].Outputs))
require.Equal(t, []string{"type=docker", "type=registry"}, stringify(m["app"].Outputs))
require.Equal(t, []string{"type=registry", "type=docker"}, m["app"].Outputs)
})

t.Run("type oci", func(t *testing.T) {
Expand All @@ -388,7 +387,7 @@ func TestLoadOverride(t *testing.T) {
m, _, err := ReadTargets(context.TODO(), []File{fp}, []string{"app"}, []string{"*.load=true"}, nil)
require.NoError(t, err)
require.Equal(t, 2, len(m["app"].Outputs))
require.Equal(t, []string{"type=docker", "type=oci,dest=out"}, stringify(m["app"].Outputs))
require.Equal(t, []string{"type=oci,dest=out", "type=docker"}, m["app"].Outputs)
})

t.Run("type docker with dest", func(t *testing.T) {
Expand All @@ -402,7 +401,7 @@ func TestLoadOverride(t *testing.T) {
m, _, err := ReadTargets(context.TODO(), []File{fp}, []string{"app"}, []string{"*.load=true"}, nil)
require.NoError(t, err)
require.Equal(t, 2, len(m["app"].Outputs))
require.Equal(t, []string{"type=docker", "type=docker,dest=out"}, stringify(m["app"].Outputs))
require.Equal(t, []string{"type=docker,dest=out", "type=docker"}, m["app"].Outputs)
})

t.Run("type local and empty target", func(t *testing.T) {
Expand All @@ -419,9 +418,9 @@ func TestLoadOverride(t *testing.T) {
require.NoError(t, err)
require.Equal(t, 2, len(m))
require.Equal(t, 1, len(m["foo"].Outputs))
require.Equal(t, []string{"type=local,dest=out"}, stringify(m["foo"].Outputs))
require.Equal(t, []string{"type=local,dest=out"}, m["foo"].Outputs)
require.Equal(t, 1, len(m["bar"].Outputs))
require.Equal(t, []string{"type=docker"}, stringify(m["bar"].Outputs))
require.Equal(t, []string{"type=docker"}, m["bar"].Outputs)
})
}

Expand All @@ -441,10 +440,12 @@ func TestLoadAndPushOverride(t *testing.T) {
require.Equal(t, 2, len(m))

require.Equal(t, 1, len(m["foo"].Outputs))
require.Equal(t, []string{"type=local,dest=out"}, stringify(m["foo"].Outputs))
sort.Strings(m["foo"].Outputs)
require.Equal(t, []string{"type=local,dest=out"}, m["foo"].Outputs)

require.Equal(t, 2, len(m["bar"].Outputs))
require.Equal(t, []string{"type=docker", "type=image,push=true"}, stringify(m["bar"].Outputs))
sort.Strings(m["bar"].Outputs)
require.Equal(t, []string{"type=docker", "type=image,push=true"}, m["bar"].Outputs)
})

t.Run("type registry", func(t *testing.T) {
Expand All @@ -460,7 +461,8 @@ func TestLoadAndPushOverride(t *testing.T) {
require.Equal(t, 1, len(m))

require.Equal(t, 2, len(m["foo"].Outputs))
require.Equal(t, []string{"type=docker", "type=registry"}, stringify(m["foo"].Outputs))
sort.Strings(m["foo"].Outputs)
require.Equal(t, []string{"type=docker", "type=registry"}, m["foo"].Outputs)
})
}

Expand Down Expand Up @@ -672,7 +674,7 @@ func TestOverrideMerge(t *testing.T) {

require.Equal(t, []string{"linux/arm", "linux/ppc64le"}, m["app"].Platforms)
require.Equal(t, 1, len(m["app"].Outputs))
require.Equal(t, "type=registry", m["app"].Outputs[0].String())
require.Equal(t, "type=registry", m["app"].Outputs[0])
}

func TestReadContexts(t *testing.T) {
Expand Down Expand Up @@ -838,7 +840,7 @@ func TestReadContextFromTargetChain(t *testing.T) {
mid, ok := m["mid"]
require.True(t, ok)
require.Equal(t, 1, len(mid.Outputs))
require.Equal(t, "type=cacheonly", mid.Outputs[0].String())
require.Equal(t, "type=cacheonly", mid.Outputs[0])
require.Equal(t, 1, len(mid.Contexts))

base, ok := m["base"]
Expand Down Expand Up @@ -922,8 +924,7 @@ func TestReadTargetsDefault(t *testing.T) {
Data: []byte(`
target "default" {
dockerfile = "test"
}`),
}
}`)}

m, g, err := ReadTargets(ctx, []File{f}, []string{"default"}, nil, nil)
require.NoError(t, err)
Expand All @@ -941,8 +942,7 @@ func TestReadTargetsSpecified(t *testing.T) {
Data: []byte(`
target "image" {
dockerfile = "test"
}`),
}
}`)}

_, _, err := ReadTargets(ctx, []File{f}, []string{"default"}, nil, nil)
require.Error(t, err)
Expand All @@ -967,8 +967,7 @@ group "foo" {
}
target "image" {
dockerfile = "test"
}`),
}
}`)}

m, g, err := ReadTargets(ctx, []File{f}, []string{"foo"}, nil, nil)
require.NoError(t, err)
Expand All @@ -994,8 +993,7 @@ target "foo" {
}
target "image" {
dockerfile = "test"
}`),
}
}`)}

m, g, err := ReadTargets(ctx, []File{f}, []string{"foo"}, nil, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -1038,8 +1036,7 @@ target "image-release" {
inherits = ["image"]
output = ["type=image,push=true"]
tags = ["user/app:latest"]
}`),
}
}`)}

fyml := File{
Name: "docker-compose.yml",
Expand All @@ -1063,8 +1060,7 @@ services:
args:
CT_ECR: foo
CT_TAG: bar
image: ct-fake-aws:bar`),
}
image: ct-fake-aws:bar`)}

fjson := File{
Name: "docker-bake.json",
Expand All @@ -1085,24 +1081,23 @@ services:
]
}
}
}`),
}
}`)}

m, g, err := ReadTargets(ctx, []File{fhcl}, []string{"default"}, nil, nil)
require.NoError(t, err)
require.Equal(t, 1, len(g))
require.Equal(t, []string{"image"}, g["default"].Targets)
require.Equal(t, 1, len(m))
require.Equal(t, 1, len(m["image"].Outputs))
require.Equal(t, "type=docker", m["image"].Outputs[0].String())
require.Equal(t, "type=docker", m["image"].Outputs[0])

m, g, err = ReadTargets(ctx, []File{fhcl}, []string{"image-release"}, nil, nil)
require.NoError(t, err)
require.Equal(t, 1, len(g))
require.Equal(t, []string{"image-release"}, g["default"].Targets)
require.Equal(t, 1, len(m))
require.Equal(t, 1, len(m["image-release"].Outputs))
require.Equal(t, "type=image,push=true", m["image-release"].Outputs[0].String())
require.Equal(t, "type=image,push=true", m["image-release"].Outputs[0])

m, g, err = ReadTargets(ctx, []File{fhcl}, []string{"image", "image-release"}, nil, nil)
require.NoError(t, err)
Expand All @@ -1111,7 +1106,7 @@ services:
require.Equal(t, 2, len(m))
require.Equal(t, ".", *m["image"].Context)
require.Equal(t, 1, len(m["image-release"].Outputs))
require.Equal(t, "type=image,push=true", m["image-release"].Outputs[0].String())
require.Equal(t, "type=image,push=true", m["image-release"].Outputs[0])

m, g, err = ReadTargets(ctx, []File{fyml, fhcl}, []string{"default"}, nil, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -1171,8 +1166,7 @@ target "foo" {
}
target "image" {
output = ["type=docker"]
}`),
}
}`)}

m, g, err := ReadTargets(ctx, []File{f}, []string{"foo"}, nil, nil)
require.NoError(t, err)
Expand Down Expand Up @@ -1206,8 +1200,7 @@ target "foo" {
}
target "image" {
output = ["type=docker"]
}`),
}
}`)}

m, g, err := ReadTargets(ctx, []File{f}, []string{"foo"}, nil, nil)
require.NoError(t, err)
Expand All @@ -1216,7 +1209,7 @@ target "image" {
require.Equal(t, []string{"foo", "image"}, g["foo"].Targets)
require.Equal(t, 2, len(m))
require.Equal(t, "bar", *m["foo"].Dockerfile)
require.Equal(t, "type=docker", m["image"].Outputs[0].String())
require.Equal(t, "type=docker", m["image"].Outputs[0])

m, g, err = ReadTargets(ctx, []File{f}, []string{"foo", "image"}, nil, nil)
require.NoError(t, err)
Expand All @@ -1225,7 +1218,7 @@ target "image" {
require.Equal(t, []string{"foo", "image"}, g["foo"].Targets)
require.Equal(t, 2, len(m))
require.Equal(t, "bar", *m["foo"].Dockerfile)
require.Equal(t, "type=docker", m["image"].Outputs[0].String())
require.Equal(t, "type=docker", m["image"].Outputs[0])
}

func TestNestedInherits(t *testing.T) {
Expand Down Expand Up @@ -1254,8 +1247,7 @@ target "c" {
}
target "d" {
inherits = ["b", "c"]
}`),
}
}`)}

cases := []struct {
name string
Expand Down Expand Up @@ -1323,8 +1315,7 @@ group "default" {
"child1",
"child2"
]
}`),
}
}`)}

cases := []struct {
name string
Expand Down Expand Up @@ -1360,9 +1351,9 @@ group "default" {
require.Equal(t, []string{"child1", "child2"}, g["default"].Targets)
require.Equal(t, 2, len(m))
require.Equal(t, tt.wantch1, m["child1"].Args)
require.Equal(t, []string{"type=docker"}, stringify(m["child1"].Outputs))
require.Equal(t, []string{"type=docker"}, m["child1"].Outputs)
require.Equal(t, tt.wantch2, m["child2"].Args)
require.Equal(t, []string{"type=docker"}, stringify(m["child2"].Outputs))
require.Equal(t, []string{"type=docker"}, m["child2"].Outputs)
})
}
}
Expand Down Expand Up @@ -1451,8 +1442,7 @@ group "e" {
target "f" {
context = "./foo"
}`),
}
}`)}

cases := []struct {
names []string
Expand Down Expand Up @@ -1731,7 +1721,7 @@ func TestAnnotations(t *testing.T) {

require.Equal(t, 1, len(m))
require.Contains(t, m, "app")
require.Equal(t, "type=image,name=foo", m["app"].Outputs[0].String())
require.Equal(t, "type=image,name=foo", m["app"].Outputs[0])
require.Equal(t, "manifest[linux/amd64]:foo=bar", m["app"].Annotations[0])

require.Len(t, bo["app"].Exports, 1)
Expand Down Expand Up @@ -2019,11 +2009,22 @@ target "app" {
})
}

func stringify[V fmt.Stringer](values []V) []string {
s := make([]string, len(values))
for i, v := range values {
s[i] = v.String()
// https://github.com/docker/buildx/issues/2822
func TestVariableEmpty(t *testing.T) {
fp := File{
Name: "docker-bake.hcl",
Data: []byte(`
variable "FOO" {
default = ""
}
target "app" {
output = [FOO]
}
`),
}
sort.Strings(s)
return s

ctx := context.TODO()

_, _, err := ReadTargets(ctx, []File{fp}, []string{"app"}, nil, nil)
require.NoError(t, err)
}
Loading

0 comments on commit 5113f9e

Please sign in to comment.