Skip to content

Commit

Permalink
custom annotations support
Browse files Browse the repository at this point in the history
Signed-off-by: CrazyMax <[email protected]>
  • Loading branch information
crazy-max committed Nov 30, 2023
1 parent f19c369 commit cb0becc
Show file tree
Hide file tree
Showing 9 changed files with 299 additions and 149 deletions.
10 changes: 9 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ jobs:
name=ghcr.io/name/app,enable=${{ github.event_name == 'pull_request' }}
name=ghcr.io/name/release,enable=${{ startsWith(github.ref, 'refs/tags/') }}
labels:
custom-labels-annotations:
runs-on: ubuntu-latest
steps:
-
Expand All @@ -183,6 +183,11 @@ jobs:
org.opencontainers.image.title=MyCustomTitle
org.opencontainers.image.description=this is a "good" example
org.opencontainers.image.vendor=MyCompany
annotations: |
maintainer=Foo
org.opencontainers.image.title=MyFooTitle
org.opencontainers.image.description=this is a "foo" example
org.opencontainers.image.vendor=MyFooCompany
global-exps:
runs-on: ubuntu-latest
Expand Down Expand Up @@ -372,6 +377,8 @@ jobs:
ghcr.io/name/app
labels: |
maintainer=CrazyMax
annotations: |
maintainer=Foo
-
name: Build
uses: docker/build-push-action@v5
Expand All @@ -382,6 +389,7 @@ jobs:
DOCKER_METADATA_OUTPUT_VERSION
DOCKER_METADATA_OUTPUT_TAGS
DOCKER_METADATA_OUTPUT_LABELS
DOCKER_METADATA_OUTPUT_ANNOTATIONS
DOCKER_METADATA_OUTPUT_JSON
bake-annotations:
Expand Down
29 changes: 16 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ ___
* [`{{date '<format>' tz='<timezone>'}}`](#date-format-tztimezone)
* [Major version zero](#major-version-zero)
* [JSON output object](#json-output-object)
* [Overwrite labels](#overwrite-labels)
* [Overwrite labels and annotations](#overwrite-labels-and-annotations)
* [Annotations](#annotations)
* [Contributing](#contributing)

Expand Down Expand Up @@ -293,16 +293,18 @@ The following inputs can be used as `step.with` keys:
> org.opencontainers.image.vendor=MyCompany
> ```

| Name | Type | Description |
|---------------|--------|-------------------------------------------------------------------------------|
| `context` | String | Where to get context data. Allowed options are: `workflow` (default), `git`. |
| `images` | List | List of Docker images to use as base name for tags |
| `tags` | List | List of [tags](#tags-input) as key-value pair attributes |
| `flavor` | List | [Flavor](#flavor-input) to apply |
| `labels` | List | List of custom labels |
| `sep-tags` | String | Separator to use for tags output (default `\n`) |
| `sep-labels` | String | Separator to use for labels output (default `\n`) |
| `bake-target` | String | Bake target name (default `docker-metadata-action`) |
| Name | Type | Description |
|-------------------|--------|------------------------------------------------------------------------------|
| `context` | String | Where to get context data. Allowed options are: `workflow` (default), `git`. |
| `images` | List | List of Docker images to use as base name for tags |
| `tags` | List | List of [tags](#tags-input) as key-value pair attributes |
| `flavor` | List | [Flavor](#flavor-input) to apply |
| `labels` | List | List of custom labels |
| `annotations` | List | List of custom anntoations |
| `sep-tags` | String | Separator to use for tags output (default `\n`) |
| `sep-labels` | String | Separator to use for labels output (default `\n`) |
| `sep-annotations` | String | Separator to use for annotations output (default `\n`) |
| `bake-target` | String | Bake target name (default `docker-metadata-action`) |

### outputs

Expand Down Expand Up @@ -893,10 +895,11 @@ that you can reuse them further in your workflow using the [`fromJSON` function]
REVISION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
```

### Overwrite labels
### Overwrite labels and annotations

If some [OCI Image Format Specification](https://github.com/opencontainers/image-spec/blob/master/annotations.md)
labels generated are not suitable, you can overwrite them like this:
generated are not suitable as labels/annotations, you can overwrite them like
this:

```yaml
-
Expand Down
7 changes: 7 additions & 0 deletions __tests__/context.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ describe('getInputs', () => {
githubToken: '',
images: ['moby/buildkit', 'ghcr.io/moby/mbuildkit'],
labels: [],
annotations: [],
sepLabels: '\n',
sepTags: '\n',
sepAnnotations: '\n',
tags: [],
} as Inputs
],
Expand All @@ -51,6 +53,7 @@ describe('getInputs', () => {
['images', 'moby/buildkit'],
['sep-labels', ','],
['sep-tags', ','],
['sep-annotations', ',']
]),
{
context: ContextSource.workflow,
Expand All @@ -59,8 +62,10 @@ describe('getInputs', () => {
githubToken: '',
images: ['moby/buildkit'],
labels: [],
annotations: [],
sepLabels: ',',
sepTags: ',',
sepAnnotations: ',',
tags: [],
} as Inputs
],
Expand All @@ -76,8 +81,10 @@ describe('getInputs', () => {
githubToken: '',
images: ['moby/buildkit', 'ghcr.io/moby/mbuildkit'],
labels: [],
annotations: [],
sepLabels: '\n',
sepTags: '\n',
sepAnnotations: '\n',
tags: [],
} as Inputs
],
Expand Down
Loading

0 comments on commit cb0becc

Please sign in to comment.