Skip to content

Commit 705cfd1

Browse files
authored
Merge pull request docker#20419 from dvdksn/build-annotation-component-output
build: output must include specified component for annotation
2 parents 5c84b8c + aae0d6a commit 705cfd1

File tree

2 files changed

+36
-6
lines changed

2 files changed

+36
-6
lines changed

content/build/building/annotations.md

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,14 @@ $ docker buildx imagetools inspect <IMAGE>@sha256:d20246ef744b1d05a1dd69d0b3fa90
137137
## Specify annotation level
138138

139139
By default, annotations are added to the image manifest. You can specify which
140-
level(s) to attach the manifest to, by prefixing the annotation string with a
141-
special type declaration:
140+
level (OCI image component) to attach the annotation to by prefixing the
141+
annotation string with a special type declaration:
142+
143+
```console
144+
$ docker build --annotation "<TYPE>:<KEY>=<VALUE>" .
145+
```
146+
147+
The following types are supported:
142148

143149
- `manifest`: annotates manifests.
144150
- `index`: annotates the root index.
@@ -152,17 +158,34 @@ image index:
152158
$ docker build --tag <IMAGE> --push --annotation "index:foo=bar" .
153159
```
154160

155-
It's possible to specify types, separated by a comma, to add the annotation to
161+
Note that the build must produce the component that you specify, or else the
162+
build will fail. For example, the following does not work, because the `docker`
163+
exporter does not produce an index:
164+
165+
```console
166+
$ docker build --output type=docker --annotation "index:foo=bar" .
167+
```
168+
169+
Likewise, the following example also does not work, because buildx creates a
170+
`docker` output by default under some circumstances, such as when provenance
171+
attestations are explicitly disabled:
172+
173+
```console
174+
$ docker build --provenance=false --annotation "index:foo=bar" .
175+
```
176+
177+
It is possible to specify types, separated by a comma, to add the annotation to
156178
more than one level. The following example creates an image with the annotation
157179
`foo=bar` on both the image index and the image manifest:
158180

159181
```console
160182
$ docker build --tag <IMAGE> --push --annotation "index,manifest:foo=bar" .
161183
```
162184

163-
You can also specify a platform qualifier in the type prefix, to annotate only
164-
components matching specific OS and architectures. The following example adds
165-
the `foo=bar` annotation only to the `linux/amd64` manifest:
185+
You can also specify a platform qualifier within square brackets in the type
186+
prefix, to annotate only components matching specific OS and architectures. The
187+
following example adds the `foo=bar` annotation only to the `linux/amd64`
188+
manifest:
166189

167190
```console
168191
$ docker build --tag <IMAGE> --push --annotation "manifest[linux/amd64]:foo=bar" .

content/build/ci/github-actions/annotations.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,10 @@ jobs:
151151
annotations: ${{ steps.meta.outputs.annotations }}
152152
push: true
153153
```
154+
155+
> **Note**
156+
>
157+
> The build must produce the components that you want to annotate. For example,
158+
> to annotate an image index, the build must produce an index. If the build
159+
> produces only a manifest and you specify `index` or `index-descriptor`, the
160+
> build fails.

0 commit comments

Comments
 (0)