Skip to content

Commit 59e85de

Browse files
committed
annotations support
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
1 parent f2a2ebe commit 59e85de

File tree

6 files changed

+396
-32
lines changed

6 files changed

+396
-32
lines changed

.github/workflows/ci.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,45 @@ jobs:
383383
DOCKER_METADATA_OUTPUT_TAGS
384384
DOCKER_METADATA_OUTPUT_LABELS
385385
DOCKER_METADATA_OUTPUT_JSON
386+
387+
bake-annotations:
388+
runs-on: ubuntu-latest
389+
steps:
390+
-
391+
name: Checkout
392+
uses: actions/checkout@v4
393+
-
394+
name: Docker meta
395+
id: docker_meta
396+
uses: ./
397+
with:
398+
images: |
399+
${{ env.DOCKER_IMAGE }}
400+
ghcr.io/name/app
401+
tags: |
402+
type=schedule
403+
type=ref,event=branch
404+
type=ref,event=tag
405+
type=ref,event=pr
406+
type=semver,pattern={{version}}
407+
type=semver,pattern={{major}}.{{minor}}
408+
type=semver,pattern={{major}}
409+
type=sha
410+
-
411+
name: Set up QEMU
412+
uses: docker/setup-qemu-action@v3
413+
-
414+
name: Set up Docker Buildx
415+
uses: docker/setup-buildx-action@v3
416+
with:
417+
version: v0.12.0-rc1
418+
-
419+
name: Build
420+
uses: docker/bake-action@v4
421+
with:
422+
files: |
423+
./test/docker-bake.hcl
424+
${{ steps.docker_meta.outputs.bake-file-tags }}
425+
${{ steps.docker_meta.outputs.bake-file-annotations-index }}
426+
targets: |
427+
release

README.md

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ ___
4848
* [Major version zero](#major-version-zero)
4949
* [JSON output object](#json-output-object)
5050
* [Overwrite labels](#overwrite-labels)
51+
* [Annotations](#annotations)
5152
* [Contributing](#contributing)
5253

5354
## Usage
@@ -292,23 +293,39 @@ The following inputs can be used as `step.with` keys:
292293

293294
The following outputs are available:
294295

295-
| Name | Type | Description |
296-
|--------------------|--------|----------------------------------------------------------------------------------------|
297-
| `version` | String | Docker image version |
298-
| `tags` | String | Docker tags |
299-
| `labels` | String | Docker labels |
300-
| `json` | String | JSON output of tags and labels |
301-
| `bake-file-tags` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with tags |
302-
| `bake-file-labels` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with labels |
296+
| Name | Type | Description |
297+
|---------------------------------------------|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
298+
| `version` | String | Docker image version |
299+
| `tags` | String | Docker tags |
300+
| `labels` | String | Docker labels |
301+
| `annotations-index` | String | Index level [annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
302+
| `annotations-index-descriptor` | String | Index descriptor level [annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
303+
| `annotations-manifest` | String | Manifest level [annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
304+
| `annotations-manifest-descriptor` | String | Manifest descriptor level [annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
305+
| `json` | String | JSON output of tags and labels |
306+
| `bake-file-tags` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with tags |
307+
| `bake-file-labels` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with labels |
308+
| `bake-file-annotations-index` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with index level [annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
309+
| `bake-file-annotations-index-descriptor` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with index descriptor level [annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
310+
| `bake-file-annotations-manifest` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with manifest level [annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
311+
| `bake-file-annotations-manifest-descriptor` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with manifest descriptor level [annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
303312

304313
Alternatively, each output is also exported as an environment variable:
305314

306315
* `DOCKER_METADATA_OUTPUT_VERSION`
307316
* `DOCKER_METADATA_OUTPUT_TAGS`
308317
* `DOCKER_METADATA_OUTPUT_LABELS`
318+
* `DOCKER_METADATA_OUTPUT_ANNOTATIONS_INDEX`
319+
* `DOCKER_METADATA_OUTPUT_ANNOTATIONS_INDEX_DESCRIPTOR`
320+
* `DOCKER_METADATA_OUTPUT_ANNOTATIONS_MANIFEST`
321+
* `DOCKER_METADATA_OUTPUT_ANNOTATIONS_MANIFEST_DESCRIPTOR`
309322
* `DOCKER_METADATA_OUTPUT_JSON`
310323
* `DOCKER_METADATA_OUTPUT_BAKE_FILE_TAGS`
311324
* `DOCKER_METADATA_OUTPUT_BAKE_FILE_LABELS`
325+
* `DOCKER_METADATA_OUTPUT_BAKE_FILE_ANNOTATIONS_INDEX`
326+
* `DOCKER_METADATA_OUTPUT_BAKE_FILE_ANNOTATIONS_INDEX_DESCRIPTOR`
327+
* `DOCKER_METADATA_OUTPUT_BAKE_FILE_ANNOTATIONS_MANIFEST_INDEX`
328+
* `DOCKER_METADATA_OUTPUT_BAKE_FILE_ANNOTATIONS_MANIFEST_DESCRIPTOR`
312329

313330
So it can be used with our [Docker Build Push action](https://github.com/docker/build-push-action/):
314331

@@ -889,6 +906,46 @@ labels generated are not suitable, you can overwrite them like this:
889906
org.opencontainers.image.vendor=MyCompany
890907
```
891908

909+
### Annotations
910+
911+
Since Buildx 0.12, it is possible to set annotations to your image through the
912+
`--annotation` flag. With the [`build-push-action`](https://github.com/docker/build-push-action/),
913+
you can set the `annotations` input with one of the `annotations-*` outputs
914+
of the `metadata-action`:
915+
916+
```yaml
917+
-
918+
name: Docker meta
919+
uses: docker/metadata-action@v5
920+
with:
921+
images: name/app
922+
-
923+
name: Build and push
924+
uses: docker/build-push-action@v5
925+
with:
926+
tags: ${{ steps.meta.outputs.tags }}
927+
annotations: ${{ steps.meta.outputs.annotations-index }}
928+
```
929+
930+
The same can be done with the [`bake-action`](https://github.com/docker/bake-action/):
931+
932+
```yaml
933+
-
934+
name: Docker meta
935+
uses: docker/metadata-action@v5
936+
with:
937+
images: name/app
938+
-
939+
name: Build
940+
uses: docker/bake-action@v3
941+
with:
942+
files: |
943+
./docker-bake.hcl
944+
${{ steps.meta.outputs.bake-file-tags }}
945+
${{ steps.meta.outputs.bake-file-annotations-index }}
946+
targets: build
947+
```
948+
892949
## Contributing
893950

894951
Want to contribute? Awesome! You can find information about contributing to

0 commit comments

Comments
 (0)