Merge pull request #992 from crazy-max/annotations
add annotations input
This commit is contained in:
		
						commit
						7a786bb2b9
					
				
							
								
								
									
										54
									
								
								.github/workflows/ci.yml
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										54
									
								
								.github/workflows/ci.yml
									
									
									
									
										vendored
									
									
								
							@ -24,7 +24,7 @@ on:
 | 
				
			|||||||
  pull_request:
 | 
					  pull_request:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
env:
 | 
					env:
 | 
				
			||||||
  BUILDX_VERSION: latest
 | 
					  BUILDX_VERSION: v0.12.0-rc1
 | 
				
			||||||
  BUILDKIT_IMAGE: moby/buildkit:buildx-stable-1
 | 
					  BUILDKIT_IMAGE: moby/buildkit:buildx-stable-1
 | 
				
			||||||
 | 
					
 | 
				
			||||||
jobs:
 | 
					jobs:
 | 
				
			||||||
@ -1125,3 +1125,55 @@ jobs:
 | 
				
			|||||||
        with:
 | 
					        with:
 | 
				
			||||||
          context: ./test
 | 
					          context: ./test
 | 
				
			||||||
          file: ./test/Dockerfile
 | 
					          file: ./test/Dockerfile
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					  annotations:
 | 
				
			||||||
 | 
					    runs-on: ubuntu-latest
 | 
				
			||||||
 | 
					    env:
 | 
				
			||||||
 | 
					      DOCKER_IMAGE: localhost:5000/name/app
 | 
				
			||||||
 | 
					    services:
 | 
				
			||||||
 | 
					      registry:
 | 
				
			||||||
 | 
					        image: registry:2
 | 
				
			||||||
 | 
					        ports:
 | 
				
			||||||
 | 
					          - 5000:5000
 | 
				
			||||||
 | 
					    steps:
 | 
				
			||||||
 | 
					      -
 | 
				
			||||||
 | 
					        name: Checkout
 | 
				
			||||||
 | 
					        uses: actions/checkout@v4
 | 
				
			||||||
 | 
					      -
 | 
				
			||||||
 | 
					        name: Docker meta
 | 
				
			||||||
 | 
					        id: meta
 | 
				
			||||||
 | 
					        uses: docker/metadata-action@v5
 | 
				
			||||||
 | 
					        with:
 | 
				
			||||||
 | 
					          images: ${{ env.DOCKER_IMAGE }}
 | 
				
			||||||
 | 
					          tags: |
 | 
				
			||||||
 | 
					            type=schedule
 | 
				
			||||||
 | 
					            type=ref,event=branch
 | 
				
			||||||
 | 
					            type=ref,event=pr
 | 
				
			||||||
 | 
					            type=semver,pattern={{version}}
 | 
				
			||||||
 | 
					            type=semver,pattern={{major}}.{{minor}}
 | 
				
			||||||
 | 
					            type=semver,pattern={{major}}
 | 
				
			||||||
 | 
					            type=sha
 | 
				
			||||||
 | 
					      -
 | 
				
			||||||
 | 
					        name: Set up Docker Buildx
 | 
				
			||||||
 | 
					        uses: docker/setup-buildx-action@v3
 | 
				
			||||||
 | 
					        with:
 | 
				
			||||||
 | 
					          version: ${{ inputs.buildx-version || env.BUILDX_VERSION }}
 | 
				
			||||||
 | 
					          driver-opts: |
 | 
				
			||||||
 | 
					            network=host
 | 
				
			||||||
 | 
					            image=${{ inputs.buildkit-image || env.BUILDKIT_IMAGE }}
 | 
				
			||||||
 | 
					      -
 | 
				
			||||||
 | 
					        name: Build and push to local registry
 | 
				
			||||||
 | 
					        uses: ./
 | 
				
			||||||
 | 
					        with:
 | 
				
			||||||
 | 
					          context: ./test
 | 
				
			||||||
 | 
					          file: ./test/Dockerfile
 | 
				
			||||||
 | 
					          push: true
 | 
				
			||||||
 | 
					          tags: ${{ steps.meta.outputs.tags }}
 | 
				
			||||||
 | 
					          annotations: |
 | 
				
			||||||
 | 
					            index:com.example.key=value
 | 
				
			||||||
 | 
					            index:com.example.key2=value2
 | 
				
			||||||
 | 
					            manifest:com.example.key3=value3
 | 
				
			||||||
 | 
					      -
 | 
				
			||||||
 | 
					        name: Check manifest
 | 
				
			||||||
 | 
					        run: |
 | 
				
			||||||
 | 
					          docker buildx imagetools inspect ${{ env.DOCKER_IMAGE }}:${{ steps.meta.outputs.version }} --format '{{json .}}'
 | 
				
			||||||
 | 
				
			|||||||
@ -217,6 +217,7 @@ Following inputs can be used as `step.with` keys
 | 
				
			|||||||
|--------------------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
 | 
					|--------------------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
 | 
				
			||||||
| `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`)      |
 | 
					| `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`)      |
 | 
				
			||||||
| `allow`            | List/CSV    | List of [extra privileged entitlement](https://docs.docker.com/engine/reference/commandline/buildx_build/#allow) (e.g., `network.host,security.insecure`)                         |
 | 
					| `allow`            | List/CSV    | List of [extra privileged entitlement](https://docs.docker.com/engine/reference/commandline/buildx_build/#allow) (e.g., `network.host,security.insecure`)                         |
 | 
				
			||||||
 | 
					| `annotations`      | List        | List of annotation to set to the image                                                                                                                                            |
 | 
				
			||||||
| `attests`          | List        | List of [attestation](https://docs.docker.com/build/attestations/) parameters (e.g., `type=sbom,generator=image`)                                                                 | 
 | 
					| `attests`          | List        | List of [attestation](https://docs.docker.com/build/attestations/) parameters (e.g., `type=sbom,generator=image`)                                                                 | 
 | 
				
			||||||
| `builder`          | String      | Builder instance (see [setup-buildx](https://github.com/docker/setup-buildx-action) action)                                                                                       |
 | 
					| `builder`          | String      | Builder instance (see [setup-buildx](https://github.com/docker/setup-buildx-action) action)                                                                                       |
 | 
				
			||||||
| `build-args`       | List        | List of [build-time variables](https://docs.docker.com/engine/reference/commandline/buildx_build/#build-arg)                                                                      |
 | 
					| `build-args`       | List        | List of [build-time variables](https://docs.docker.com/engine/reference/commandline/buildx_build/#build-arg)                                                                      |
 | 
				
			||||||
 | 
				
			|||||||
@ -662,6 +662,50 @@ ANOTHER_SECRET=ANOTHER_SECRET_ENV`]
 | 
				
			|||||||
        '.'
 | 
					        '.'
 | 
				
			||||||
      ]
 | 
					      ]
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
 | 
					    [
 | 
				
			||||||
 | 
					      27,
 | 
				
			||||||
 | 
					      '0.11.0',
 | 
				
			||||||
 | 
					      new Map<string, string>([
 | 
				
			||||||
 | 
					        ['context', '.'],
 | 
				
			||||||
 | 
					        ['annotations', 'example1=www\nindex:example2=xxx\nmanifest:example3=yyy\nmanifest-descriptor[linux/amd64]:example4=zzz'],
 | 
				
			||||||
 | 
					        ['outputs', 'type=local,dest=./release-out'],
 | 
				
			||||||
 | 
					        ['load', 'false'],
 | 
				
			||||||
 | 
					        ['no-cache', 'false'],
 | 
				
			||||||
 | 
					        ['push', 'false'],
 | 
				
			||||||
 | 
					        ['pull', 'false'],
 | 
				
			||||||
 | 
					      ]),
 | 
				
			||||||
 | 
					      [
 | 
				
			||||||
 | 
					        'build',
 | 
				
			||||||
 | 
					        '--output', 'type=local,dest=./release-out',
 | 
				
			||||||
 | 
					        "--provenance", `mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789`,
 | 
				
			||||||
 | 
					        '--metadata-file', path.join(tmpDir, 'metadata-file'),
 | 
				
			||||||
 | 
					        '.'
 | 
				
			||||||
 | 
					      ]
 | 
				
			||||||
 | 
					    ],
 | 
				
			||||||
 | 
					    [
 | 
				
			||||||
 | 
					      28,
 | 
				
			||||||
 | 
					      '0.12.0',
 | 
				
			||||||
 | 
					      new Map<string, string>([
 | 
				
			||||||
 | 
					        ['context', '.'],
 | 
				
			||||||
 | 
					        ['annotations', 'example1=www\nindex:example2=xxx\nmanifest:example3=yyy\nmanifest-descriptor[linux/amd64]:example4=zzz'],
 | 
				
			||||||
 | 
					        ['outputs', 'type=local,dest=./release-out'],
 | 
				
			||||||
 | 
					        ['load', 'false'],
 | 
				
			||||||
 | 
					        ['no-cache', 'false'],
 | 
				
			||||||
 | 
					        ['push', 'false'],
 | 
				
			||||||
 | 
					        ['pull', 'false'],
 | 
				
			||||||
 | 
					      ]),
 | 
				
			||||||
 | 
					      [
 | 
				
			||||||
 | 
					        'build',
 | 
				
			||||||
 | 
					        '--annotation', 'example1=www',
 | 
				
			||||||
 | 
					        '--annotation', 'index:example2=xxx',
 | 
				
			||||||
 | 
					        '--annotation', 'manifest:example3=yyy',
 | 
				
			||||||
 | 
					        '--annotation', 'manifest-descriptor[linux/amd64]:example4=zzz',
 | 
				
			||||||
 | 
					        '--output', 'type=local,dest=./release-out',
 | 
				
			||||||
 | 
					        "--provenance", `mode=min,inline-only=true,builder-id=https://github.com/docker/build-push-action/actions/runs/123456789`,
 | 
				
			||||||
 | 
					        '--metadata-file', path.join(tmpDir, 'metadata-file'),
 | 
				
			||||||
 | 
					        '.'
 | 
				
			||||||
 | 
					      ]
 | 
				
			||||||
 | 
					    ]
 | 
				
			||||||
  ])(
 | 
					  ])(
 | 
				
			||||||
    '[%d] given %p with %p as inputs, returns %p',
 | 
					    '[%d] given %p with %p as inputs, returns %p',
 | 
				
			||||||
    async (num: number, buildxVersion: string, inputs: Map<string, string>, expected: Array<string>) => {
 | 
					    async (num: number, buildxVersion: string, inputs: Map<string, string>, expected: Array<string>) => {
 | 
				
			||||||
 | 
				
			|||||||
@ -13,6 +13,9 @@ inputs:
 | 
				
			|||||||
  allow:
 | 
					  allow:
 | 
				
			||||||
    description: "List of extra privileged entitlement (e.g., network.host,security.insecure)"
 | 
					    description: "List of extra privileged entitlement (e.g., network.host,security.insecure)"
 | 
				
			||||||
    required: false
 | 
					    required: false
 | 
				
			||||||
 | 
					  annotations:
 | 
				
			||||||
 | 
					    description: "List of annotation to set to the image"
 | 
				
			||||||
 | 
					    required: false
 | 
				
			||||||
  attests:
 | 
					  attests:
 | 
				
			||||||
    description: "List of attestation parameters (e.g., type=sbom,generator=image)"
 | 
					    description: "List of attestation parameters (e.g., type=sbom,generator=image)"
 | 
				
			||||||
    required: false
 | 
					    required: false
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										2
									
								
								dist/index.js
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/index.js
									
									
									
										generated
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							
							
								
								
									
										2
									
								
								dist/index.js.map
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										2
									
								
								dist/index.js.map
									
									
									
										generated
									
									
										vendored
									
									
								
							
										
											
												File diff suppressed because one or more lines are too long
											
										
									
								
							@ -9,6 +9,7 @@ import {Util} from '@docker/actions-toolkit/lib/util';
 | 
				
			|||||||
export interface Inputs {
 | 
					export interface Inputs {
 | 
				
			||||||
  addHosts: string[];
 | 
					  addHosts: string[];
 | 
				
			||||||
  allow: string[];
 | 
					  allow: string[];
 | 
				
			||||||
 | 
					  annotations: string[];
 | 
				
			||||||
  attests: string[];
 | 
					  attests: string[];
 | 
				
			||||||
  buildArgs: string[];
 | 
					  buildArgs: string[];
 | 
				
			||||||
  buildContexts: string[];
 | 
					  buildContexts: string[];
 | 
				
			||||||
@ -44,6 +45,7 @@ export async function getInputs(): Promise<Inputs> {
 | 
				
			|||||||
  return {
 | 
					  return {
 | 
				
			||||||
    addHosts: Util.getInputList('add-hosts'),
 | 
					    addHosts: Util.getInputList('add-hosts'),
 | 
				
			||||||
    allow: Util.getInputList('allow'),
 | 
					    allow: Util.getInputList('allow'),
 | 
				
			||||||
 | 
					    annotations: Util.getInputList('annotations', {ignoreComma: true}),
 | 
				
			||||||
    attests: Util.getInputList('attests', {ignoreComma: true}),
 | 
					    attests: Util.getInputList('attests', {ignoreComma: true}),
 | 
				
			||||||
    buildArgs: Util.getInputList('build-args', {ignoreComma: true}),
 | 
					    buildArgs: Util.getInputList('build-args', {ignoreComma: true}),
 | 
				
			||||||
    buildContexts: Util.getInputList('build-contexts', {ignoreComma: true}),
 | 
					    buildContexts: Util.getInputList('build-contexts', {ignoreComma: true}),
 | 
				
			||||||
@ -101,6 +103,11 @@ async function getBuildArgs(inputs: Inputs, context: string, toolkit: Toolkit):
 | 
				
			|||||||
      args.push('--attest', attest);
 | 
					      args.push('--attest', attest);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					  if (await toolkit.buildx.versionSatisfies('>=0.12.0')) {
 | 
				
			||||||
 | 
					    await Util.asyncForEach(inputs.annotations, async annotation => {
 | 
				
			||||||
 | 
					      args.push('--annotation', annotation);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
 | 
					  }
 | 
				
			||||||
  await Util.asyncForEach(inputs.buildArgs, async buildArg => {
 | 
					  await Util.asyncForEach(inputs.buildArgs, async buildArg => {
 | 
				
			||||||
    args.push('--build-arg', buildArg);
 | 
					    args.push('--build-arg', buildArg);
 | 
				
			||||||
  });
 | 
					  });
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user