mirror of
https://gitea.com/Lydanne/buildx.git
synced 2025-05-18 09:17:49 +08:00
bake: add annotations field
Signed-off-by: Justin Chadwell <me@jedevc.com>
This commit is contained in:
parent
a59058e8a5
commit
0138f2a00f
17
bake/bake.go
17
bake/bake.go
@ -589,6 +589,7 @@ type Target struct {
|
|||||||
// Inherits is the only field that cannot be overridden with --set
|
// Inherits is the only field that cannot be overridden with --set
|
||||||
Inherits []string `json:"inherits,omitempty" hcl:"inherits,optional" cty:"inherits"`
|
Inherits []string `json:"inherits,omitempty" hcl:"inherits,optional" cty:"inherits"`
|
||||||
|
|
||||||
|
Annotations []string `json:"annotations,omitempty" hcl:"annotations,optional" cty:"annotations"`
|
||||||
Attest []string `json:"attest,omitempty" hcl:"attest,optional" cty:"attest"`
|
Attest []string `json:"attest,omitempty" hcl:"attest,optional" cty:"attest"`
|
||||||
Context *string `json:"context,omitempty" hcl:"context,optional" cty:"context"`
|
Context *string `json:"context,omitempty" hcl:"context,optional" cty:"context"`
|
||||||
Contexts map[string]string `json:"contexts,omitempty" hcl:"contexts,optional" cty:"contexts"`
|
Contexts map[string]string `json:"contexts,omitempty" hcl:"contexts,optional" cty:"contexts"`
|
||||||
@ -620,6 +621,7 @@ var _ hclparser.WithEvalContexts = &Group{}
|
|||||||
var _ hclparser.WithGetName = &Group{}
|
var _ hclparser.WithGetName = &Group{}
|
||||||
|
|
||||||
func (t *Target) normalize() {
|
func (t *Target) normalize() {
|
||||||
|
t.Annotations = removeDupes(t.Annotations)
|
||||||
t.Attest = removeAttestDupes(t.Attest)
|
t.Attest = removeAttestDupes(t.Attest)
|
||||||
t.Tags = removeDupes(t.Tags)
|
t.Tags = removeDupes(t.Tags)
|
||||||
t.Secrets = removeDupes(t.Secrets)
|
t.Secrets = removeDupes(t.Secrets)
|
||||||
@ -680,6 +682,9 @@ func (t *Target) Merge(t2 *Target) {
|
|||||||
if t2.Target != nil {
|
if t2.Target != nil {
|
||||||
t.Target = t2.Target
|
t.Target = t2.Target
|
||||||
}
|
}
|
||||||
|
if t2.Annotations != nil { // merge
|
||||||
|
t.Annotations = append(t.Annotations, t2.Annotations...)
|
||||||
|
}
|
||||||
if t2.Attest != nil { // merge
|
if t2.Attest != nil { // merge
|
||||||
t.Attest = append(t.Attest, t2.Attest...)
|
t.Attest = append(t.Attest, t2.Attest...)
|
||||||
t.Attest = removeAttestDupes(t.Attest)
|
t.Attest = removeAttestDupes(t.Attest)
|
||||||
@ -766,6 +771,8 @@ func (t *Target) AddOverrides(overrides map[string]Override) error {
|
|||||||
t.Platforms = o.ArrValue
|
t.Platforms = o.ArrValue
|
||||||
case "output":
|
case "output":
|
||||||
t.Outputs = o.ArrValue
|
t.Outputs = o.ArrValue
|
||||||
|
case "annotations":
|
||||||
|
t.Annotations = append(t.Annotations, o.ArrValue...)
|
||||||
case "attest":
|
case "attest":
|
||||||
t.Attest = append(t.Attest, o.ArrValue...)
|
t.Attest = append(t.Attest, o.ArrValue...)
|
||||||
case "no-cache":
|
case "no-cache":
|
||||||
@ -1164,6 +1171,16 @@ func toBuildOpt(t *Target, inp *Input) (*build.Options, error) {
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
annotations, err := buildflags.ParseAnnotations(t.Annotations)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
for _, e := range bo.Exports {
|
||||||
|
for k, v := range annotations {
|
||||||
|
e.Attrs[k.String()] = v
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
attests, err := buildflags.ParseAttests(t.Attest)
|
attests, err := buildflags.ParseAttests(t.Attest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -1460,3 +1460,31 @@ func TestAttestDuplicates(t *testing.T) {
|
|||||||
"provenance": ptrstr("type=provenance,mode=max"),
|
"provenance": ptrstr("type=provenance,mode=max"),
|
||||||
}, opts["default"].Attests)
|
}, opts["default"].Attests)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAnnotations(t *testing.T) {
|
||||||
|
fp := File{
|
||||||
|
Name: "docker-bake.hcl",
|
||||||
|
Data: []byte(
|
||||||
|
`target "app" {
|
||||||
|
output = ["type=image,name=foo"]
|
||||||
|
annotations = ["manifest[linux/amd64]:foo=bar"]
|
||||||
|
}`),
|
||||||
|
}
|
||||||
|
ctx := context.TODO()
|
||||||
|
m, g, err := ReadTargets(ctx, []File{fp}, []string{"app"}, nil, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
bo, err := TargetsToBuildOpt(m, &Input{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
require.Equal(t, 1, len(g))
|
||||||
|
require.Equal(t, []string{"app"}, g["default"].Targets)
|
||||||
|
|
||||||
|
require.Equal(t, 1, len(m))
|
||||||
|
require.Contains(t, m, "app")
|
||||||
|
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)
|
||||||
|
require.Equal(t, "bar", bo["app"].Exports[0].Attrs["annotation-manifest[linux/amd64].foo"])
|
||||||
|
}
|
||||||
|
@ -115,6 +115,7 @@ The following table shows the complete list of attributes that you can assign to
|
|||||||
| Name | Type | Description |
|
| Name | Type | Description |
|
||||||
| ----------------------------------------------- | ------- | -------------------------------------------------------------------- |
|
| ----------------------------------------------- | ------- | -------------------------------------------------------------------- |
|
||||||
| [`args`](#targetargs) | Map | Build arguments |
|
| [`args`](#targetargs) | Map | Build arguments |
|
||||||
|
| [`annotations`](#targetannotations) | List | Exporter annotations |
|
||||||
| [`attest`](#targetattest) | List | Build attestations |
|
| [`attest`](#targetattest) | List | Build attestations |
|
||||||
| [`cache-from`](#targetcache-from) | List | External cache sources |
|
| [`cache-from`](#targetcache-from) | List | External cache sources |
|
||||||
| [`cache-to`](#targetcache-to) | List | External cache destinations |
|
| [`cache-to`](#targetcache-to) | List | External cache destinations |
|
||||||
@ -171,6 +172,26 @@ target "db" {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `target.annotations`
|
||||||
|
|
||||||
|
The `annotations` attribute is a shortcut to allow you to easily set a list of
|
||||||
|
annotations on the target.
|
||||||
|
|
||||||
|
```hcl
|
||||||
|
target "default" {
|
||||||
|
output = ["type=image,name=foo"]
|
||||||
|
annotations = ["key=value"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
is the same as
|
||||||
|
|
||||||
|
```hcl
|
||||||
|
target "default" {
|
||||||
|
output = ["type=image,name=foo,annotation.key=value"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### `target.attest`
|
### `target.attest`
|
||||||
|
|
||||||
The `attest` attribute lets you apply [build attestations][attestations] to the target.
|
The `attest` attribute lets you apply [build attestations][attestations] to the target.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user