Skip to content

Commit 7a786bb

Browse files
authored
Merge pull request #992 from crazy-max/annotations
add annotations input
2 parents fdf7f43 + c66ae3a commit 7a786bb

File tree

7 files changed

+110
-3
lines changed

7 files changed

+110
-3
lines changed

.github/workflows/ci.yml

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ on:
2424
pull_request:
2525

2626
env:
27-
BUILDX_VERSION: latest
27+
BUILDX_VERSION: v0.12.0-rc1
2828
BUILDKIT_IMAGE: moby/buildkit:buildx-stable-1
2929

3030
jobs:
@@ -1125,3 +1125,55 @@ jobs:
11251125
with:
11261126
context: ./test
11271127
file: ./test/Dockerfile
1128+
1129+
annotations:
1130+
runs-on: ubuntu-latest
1131+
env:
1132+
DOCKER_IMAGE: localhost:5000/name/app
1133+
services:
1134+
registry:
1135+
image: registry:2
1136+
ports:
1137+
- 5000:5000
1138+
steps:
1139+
-
1140+
name: Checkout
1141+
uses: actions/checkout@v4
1142+
-
1143+
name: Docker meta
1144+
id: meta
1145+
uses: docker/metadata-action@v5
1146+
with:
1147+
images: ${{ env.DOCKER_IMAGE }}
1148+
tags: |
1149+
type=schedule
1150+
type=ref,event=branch
1151+
type=ref,event=pr
1152+
type=semver,pattern={{version}}
1153+
type=semver,pattern={{major}}.{{minor}}
1154+
type=semver,pattern={{major}}
1155+
type=sha
1156+
-
1157+
name: Set up Docker Buildx
1158+
uses: docker/setup-buildx-action@v3
1159+
with:
1160+
version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
1161+
driver-opts: |
1162+
network=host
1163+
image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
1164+
-
1165+
name: Build and push to local registry
1166+
uses: ./
1167+
with:
1168+
context: ./test
1169+
file: ./test/Dockerfile
1170+
push: true
1171+
tags: ${{ steps.meta.outputs.tags }}
1172+
annotations: |
1173+
index:com.example.key=value
1174+
index:com.example.key2=value2
1175+
manifest:com.example.key3=value3
1176+
-
1177+
name: Check manifest
1178+
run: |
1179+
docker buildx imagetools inspect ${{ env.DOCKER_IMAGE }}:${{ steps.meta.outputs.version }} --format '{{json .}}'

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,7 @@ Following inputs can be used as `step.with` keys
217217
|--------------------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
218218
| `add-hosts` | List/CSV | List of [customs host-to-IP mapping](https://docs.docker.com/engine/reference/commandline/build/#add-entries-to-container-hosts-file---add-host) (e.g., `docker:10.180.0.1`) |
219219
| `allow` | List/CSV | List of [extra privileged entitlement](https://docs.docker.com/engine/reference/commandline/buildx_build/#allow) (e.g., `network.host,security.insecure`) |
220+
| `annotations` | List | List of annotation to set to the image |
220221
| `attests` | List | List of [attestation](https://docs.docker.com/build/attestations/) parameters (e.g., `type=sbom,generator=image`) |
221222
| `builder` | String | Builder instance (see [setup-buildx](https://github.com/docker/setup-buildx-action) action) |
222223
| `build-args` | List | List of [build-time variables](https://docs.docker.com/engine/reference/commandline/buildx_build/#build-arg) |

__tests__/context.test.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,50 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
662662
'.'
663663
]
664664
],
665+
[
666+
27,
667+
'0.11.0',
668+
new Map<string, string>([
669+
['context', '.'],
670+
['annotations', 'example1=www\nindex:example2=xxx\nmanifest:example3=yyy\nmanifest-descriptor[linux/amd64]:example4=zzz'],
671+
['outputs', 'type=local,dest=./release-out'],
672+
['load', 'false'],
673+
['no-cache', 'false'],
674+
['push', 'false'],
675+
['pull', 'false'],
676+
]),
677+
[
678+
'build',
679+
'--output', 'type=local,dest=./release-out',
680+
"--provenance", `mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789`,
681+
'--metadata-file', path.join(tmpDir, 'metadata-file'),
682+
'.'
683+
]
684+
],
685+
[
686+
28,
687+
'0.12.0',
688+
new Map<string, string>([
689+
['context', '.'],
690+
['annotations', 'example1=www\nindex:example2=xxx\nmanifest:example3=yyy\nmanifest-descriptor[linux/amd64]:example4=zzz'],
691+
['outputs', 'type=local,dest=./release-out'],
692+
['load', 'false'],
693+
['no-cache', 'false'],
694+
['push', 'false'],
695+
['pull', 'false'],
696+
]),
697+
[
698+
'build',
699+
'--annotation', 'example1=www',
700+
'--annotation', 'index:example2=xxx',
701+
'--annotation', 'manifest:example3=yyy',
702+
'--annotation', 'manifest-descriptor[linux/amd64]:example4=zzz',
703+
'--output', 'type=local,dest=./release-out',
704+
"--provenance", `mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789`,
705+
'--metadata-file', path.join(tmpDir, 'metadata-file'),
706+
'.'
707+
]
708+
]
665709
])(
666710
'[%d] given %p with %p as inputs, returns %p',
667711
async (num: number, buildxVersion: string, inputs: Map<string, string>, expected: Array<string>) => {

action.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ inputs:
1313
allow:
1414
description: "List of extra privileged entitlement (e.g., network.host,security.insecure)"
1515
required: false
16+
annotations:
17+
description: "List of annotation to set to the image"
18+
required: false
1619
attests:
1720
description: "List of attestation parameters (e.g., type=sbom,generator=image)"
1821
required: false

dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/context.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import {Util} from '@docker/actions-toolkit/lib/util';
99
export interface Inputs {
1010
addHosts: string[];
1111
allow: string[];
12+
annotations: string[];
1213
attests: string[];
1314
buildArgs: string[];
1415
buildContexts: string[];
@@ -44,6 +45,7 @@ export async function getInputs(): Promise<Inputs> {
4445
return {
4546
addHosts: Util.getInputList('add-hosts'),
4647
allow: Util.getInputList('allow'),
48+
annotations: Util.getInputList('annotations', {ignoreComma: true}),
4749
attests: Util.getInputList('attests', {ignoreComma: true}),
4850
buildArgs: Util.getInputList('build-args', {ignoreComma: true}),
4951
buildContexts: Util.getInputList('build-contexts', {ignoreComma: true}),
@@ -101,6 +103,11 @@ async function getBuildArgs(inputs: Inputs, context: string, toolkit: Toolkit):
101103
args.push('--attest', attest);
102104
});
103105
}
106+
if (await toolkit.buildx.versionSatisfies('>=0.12.0')) {
107+
await Util.asyncForEach(inputs.annotations, async annotation => {
108+
args.push('--annotation', annotation);
109+
});
110+
}
104111
await Util.asyncForEach(inputs.buildArgs, async buildArg => {
105112
args.push('--build-arg', buildArg);
106113
});

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy