Skip to content

Commit f33ad1e

Browse files
authored
Merge pull request #352 from crazy-max/annotations-alt
annotations support
2 parents 2a4836a + 6bbe00c commit f33ad1e

File tree

8 files changed

+446
-49
lines changed

8 files changed

+446
-49
lines changed

.github/workflows/ci.yml

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,3 +383,47 @@ 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+
env:
411+
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
412+
-
413+
name: Set up QEMU
414+
uses: docker/setup-qemu-action@v3
415+
-
416+
name: Set up Docker Buildx
417+
uses: docker/setup-buildx-action@v3
418+
with:
419+
version: v0.12.0-rc1
420+
-
421+
name: Build
422+
uses: docker/bake-action@v4
423+
with:
424+
files: |
425+
./test/docker-bake.hcl
426+
${{ steps.docker_meta.outputs.bake-file-tags }}
427+
${{ steps.docker_meta.outputs.bake-file-annotations }}
428+
targets: |
429+
release

README.md

Lines changed: 81 additions & 11 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
@@ -307,23 +308,27 @@ The following inputs can be used as `step.with` keys:
307308

308309
The following outputs are available:
309310

310-
| Name | Type | Description |
311-
|--------------------|--------|-------------------------------------------------------------------------------------------------|
312-
| `version` | String | Docker image version |
313-
| `tags` | String | Docker tags |
314-
| `labels` | String | Docker labels |
315-
| `json` | String | JSON output of tags and labels |
316-
| `bake-file-tags` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with tags |
317-
| `bake-file-labels` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with labels |
311+
| Name | Type | Description |
312+
|-------------------------|--------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------|
313+
| `version` | String | Docker image version |
314+
| `tags` | String | Docker tags |
315+
| `labels` | String | Docker labels |
316+
| `annotations` | String | [Annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
317+
| `json` | String | JSON output of tags and labels |
318+
| `bake-file-tags` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with tags |
319+
| `bake-file-labels` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with labels |
320+
| `bake-file-annotations` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with [annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
318321

319322
Alternatively, each output is also exported as an environment variable:
320323

321324
* `DOCKER_METADATA_OUTPUT_VERSION`
322325
* `DOCKER_METADATA_OUTPUT_TAGS`
323326
* `DOCKER_METADATA_OUTPUT_LABELS`
327+
* `DOCKER_METADATA_OUTPUT_ANNOTATIONS`
324328
* `DOCKER_METADATA_OUTPUT_JSON`
325329
* `DOCKER_METADATA_OUTPUT_BAKE_FILE_TAGS`
326330
* `DOCKER_METADATA_OUTPUT_BAKE_FILE_LABELS`
331+
* `DOCKER_METADATA_OUTPUT_BAKE_FILE_ANNOTATIONS`
327332

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

@@ -336,9 +341,10 @@ So it can be used with our [Docker Build Push action](https://github.com/docker/
336341

337342
### environment variables
338343

339-
| Name | Type | Description |
340-
|-------------------------------|------|------------------------------------------------------------------------------------------------------------|
341-
| `DOCKER_METADATA_PR_HEAD_SHA` | Bool | If `true`, set associated head SHA instead of commit SHA that triggered the workflow on pull request event |
344+
| Name | Type | Description |
345+
|--------------------------------------|--------|------------------------------------------------------------------------------------------------------------|
346+
| `DOCKER_METADATA_PR_HEAD_SHA` | Bool | If `true`, set associated head SHA instead of commit SHA that triggered the workflow on pull request event |
347+
| `DOCKER_METADATA_ANNOTATIONS_LEVELS` | String | Comma separated list of annotations levels to set for annotations output separated (default `manifest`) |
342348

343349
## `context` input
344350

@@ -904,6 +910,70 @@ labels generated are not suitable, you can overwrite them like this:
904910
org.opencontainers.image.vendor=MyCompany
905911
```
906912

913+
### Annotations
914+
915+
Since Buildx 0.12, it is possible to set annotations to your image through the
916+
`--annotation` flag.
917+
918+
With the [`build-push-action`](https://github.com/docker/build-push-action/),
919+
you can set the `annotations` input with the value of the `annotations` output
920+
of the `metadata-action`:
921+
922+
```yaml
923+
-
924+
name: Docker meta
925+
uses: docker/metadata-action@v5
926+
with:
927+
images: name/app
928+
-
929+
name: Build and push
930+
uses: docker/build-push-action@v5
931+
with:
932+
tags: ${{ steps.meta.outputs.tags }}
933+
annotations: ${{ steps.meta.outputs.annotations }}
934+
```
935+
936+
The same can be done with the [`bake-action`](https://github.com/docker/bake-action/):
937+
938+
```yaml
939+
-
940+
name: Docker meta
941+
uses: docker/metadata-action@v5
942+
with:
943+
images: name/app
944+
-
945+
name: Build
946+
uses: docker/bake-action@v3
947+
with:
948+
files: |
949+
./docker-bake.hcl
950+
${{ steps.meta.outputs.bake-file-tags }}
951+
${{ steps.meta.outputs.bake-file-annotations }}
952+
targets: build
953+
```
954+
955+
If you want to set specific level(s) for your annotations, you can use the
956+
[`DOCKER_METADATA_ANNOTATIONS_LEVELS` environment variable](#environment-variables)
957+
with a comma separated list of levels (defaults to `manifest`):
958+
959+
```yaml
960+
-
961+
name: Docker meta
962+
uses: docker/metadata-action@v5
963+
with:
964+
images: name/app
965+
env:
966+
DOCKER_METADATA_ANNOTATIONS_LEVELS: manifest,index
967+
-
968+
name: Build and push
969+
uses: docker/build-push-action@v5
970+
with:
971+
tags: ${{ steps.meta.outputs.tags }}
972+
annotations: ${{ steps.meta.outputs.annotations }}
973+
```
974+
975+
More information about annotations in the [BuildKit documentation](https://github.com/moby/buildkit/blob/master/docs/annotations.md).
976+
907977
## Contributing
908978

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

0 commit comments

Comments
 (0)