Skip to content

Commit

Permalink
annotations support
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <crazy-max@users.noreply.github.com>
  • Loading branch information
crazy-max committed Nov 16, 2023
1 parent f2a2ebe commit 59e85de
Show file tree
Hide file tree
Showing 6 changed files with 396 additions and 32 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -383,3 +383,45 @@ jobs:
DOCKER_METADATA_OUTPUT_TAGS
DOCKER_METADATA_OUTPUT_LABELS
DOCKER_METADATA_OUTPUT_JSON
bake-annotations:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v4
-
name: Docker meta
id: docker_meta
uses: ./
with:
images: |
${{ env.DOCKER_IMAGE }}
ghcr.io/name/app
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha
-
name: Set up QEMU
uses: docker/setup-qemu-action@v3
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: v0.12.0-rc1
-
name: Build
uses: docker/bake-action@v4
with:
files: |
./test/docker-bake.hcl
${{ steps.docker_meta.outputs.bake-file-tags }}
${{ steps.docker_meta.outputs.bake-file-annotations-index }}
targets: |
release
73 changes: 65 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ ___
* [Major version zero](#major-version-zero)
* [JSON output object](#json-output-object)
* [Overwrite labels](#overwrite-labels)
* [Annotations](#annotations)
* [Contributing](#contributing)

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

The following outputs are available:

| Name | Type | Description |
|--------------------|--------|----------------------------------------------------------------------------------------|
| `version` | String | Docker image version |
| `tags` | String | Docker tags |
| `labels` | String | Docker labels |
| `json` | String | JSON output of tags and labels |
| `bake-file-tags` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with tags |
| `bake-file-labels` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with labels |
| Name | Type | Description |
|---------------------------------------------|--------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `version` | String | Docker image version |
| `tags` | String | Docker tags |
| `labels` | String | Docker labels |
| `annotations-index` | String | Index level [annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
| `annotations-index-descriptor` | String | Index descriptor level [annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
| `annotations-manifest` | String | Manifest level [annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
| `annotations-manifest-descriptor` | String | Manifest descriptor level [annotations](https://github.com/moby/buildkit/blob/master/docs/annotations.md) |
| `json` | String | JSON output of tags and labels |
| `bake-file-tags` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with tags |
| `bake-file-labels` | File | [Bake file definition](https://docs.docker.com/build/bake/reference/) path with labels |
| `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) |
| `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) |
| `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) |
| `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) |

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

* `DOCKER_METADATA_OUTPUT_VERSION`
* `DOCKER_METADATA_OUTPUT_TAGS`
* `DOCKER_METADATA_OUTPUT_LABELS`
* `DOCKER_METADATA_OUTPUT_ANNOTATIONS_INDEX`
* `DOCKER_METADATA_OUTPUT_ANNOTATIONS_INDEX_DESCRIPTOR`
* `DOCKER_METADATA_OUTPUT_ANNOTATIONS_MANIFEST`
* `DOCKER_METADATA_OUTPUT_ANNOTATIONS_MANIFEST_DESCRIPTOR`
* `DOCKER_METADATA_OUTPUT_JSON`
* `DOCKER_METADATA_OUTPUT_BAKE_FILE_TAGS`
* `DOCKER_METADATA_OUTPUT_BAKE_FILE_LABELS`
* `DOCKER_METADATA_OUTPUT_BAKE_FILE_ANNOTATIONS_INDEX`
* `DOCKER_METADATA_OUTPUT_BAKE_FILE_ANNOTATIONS_INDEX_DESCRIPTOR`
* `DOCKER_METADATA_OUTPUT_BAKE_FILE_ANNOTATIONS_MANIFEST_INDEX`
* `DOCKER_METADATA_OUTPUT_BAKE_FILE_ANNOTATIONS_MANIFEST_DESCRIPTOR`

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

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

### Annotations

Since Buildx 0.12, it is possible to set annotations to your image through the
`--annotation` flag. With the [`build-push-action`](https://github.com/docker/build-push-action/),
you can set the `annotations` input with one of the `annotations-*` outputs
of the `metadata-action`:

```yaml
-
name: Docker meta
uses: docker/metadata-action@v5
with:
images: name/app
-
name: Build and push
uses: docker/build-push-action@v5
with:
tags: ${{ steps.meta.outputs.tags }}
annotations: ${{ steps.meta.outputs.annotations-index }}
```

The same can be done with the [`bake-action`](https://github.com/docker/bake-action/):

```yaml
-
name: Docker meta
uses: docker/metadata-action@v5
with:
images: name/app
-
name: Build
uses: docker/bake-action@v3
with:
files: |
./docker-bake.hcl
${{ steps.meta.outputs.bake-file-tags }}
${{ steps.meta.outputs.bake-file-annotations-index }}
targets: build
```

## Contributing

Want to contribute? Awesome! You can find information about contributing to
Expand Down
Loading

0 comments on commit 59e85de

Please sign in to comment.