Add support for annotations as an action input.

This commit is contained in:
Ashleigh Carr 2024-04-08 13:29:14 +01:00
parent 7a95fa7ee0
commit 2d3449ca18
No known key found for this signature in database
GPG key ID: 570A83001013E48B
8 changed files with 39 additions and 5 deletions

View file

@ -2,4 +2,7 @@ module.exports = {
extends: [ extends: [
"@redhat-actions/eslint-config", "@redhat-actions/eslint-config",
], ],
ignorePatterns: [
"src/generated/*"
]
}; };

View file

@ -63,6 +63,7 @@ jobs:
layers: false layers: false
tags: ${{ steps.docker-metadata.outputs.tags }} tags: ${{ steps.docker-metadata.outputs.tags }}
labels: ${{ steps.docker-metadata.outputs.labels }} labels: ${{ steps.docker-metadata.outputs.labels }}
annotations: ${{ steps.docker-metadata.outputs.annotations }}
containerfiles: | containerfiles: |
./Containerfile ./Containerfile
extra-args: | extra-args: |
@ -83,6 +84,8 @@ jobs:
set -x set -x
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.title"' buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.title"'
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.description"' buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.description"'
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Annotations."org.opencontainers.image.title"'
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Annotations."org.opencontainers.image.description"'
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.title"' buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.title"'
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.description"' buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.description"'
@ -107,7 +110,7 @@ jobs:
- name: Docker Metadata - name: Docker Metadata
id: docker-metadata id: docker-metadata
uses: docker/metadata-action@v4 uses: docker/metadata-action@v5
with: with:
images: | images: |
${{ env.IMAGE_NAME }} ${{ env.IMAGE_NAME }}
@ -154,6 +157,7 @@ jobs:
with: with:
tags: ${{ steps.docker-metadata.outputs.tags }} tags: ${{ steps.docker-metadata.outputs.tags }}
labels: ${{ steps.docker-metadata.outputs.labels }} labels: ${{ steps.docker-metadata.outputs.labels }}
annotations: ${{ steps.docker-metadata.outputs.annotations }}
base-image: 'registry.access.redhat.com/openjdk/openjdk-11-rhel7' base-image: 'registry.access.redhat.com/openjdk/openjdk-11-rhel7'
# To avoid hardcoding a particular version of the binary. # To avoid hardcoding a particular version of the binary.
content: | content: |
@ -181,5 +185,7 @@ jobs:
set -x set -x
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.title"' buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.title"'
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.description"' buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.description"'
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Annotations."org.opencontainers.image.title"'
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Annotations."org.opencontainers.image.description"'
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.title"' buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.title"'
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.description"' buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.description"'

View file

@ -15,6 +15,9 @@ inputs:
labels: labels:
description: 'The labels of the image to build. Seperate by newline. For example, "io.containers.capabilities=sys_admin,mknod".' description: 'The labels of the image to build. Seperate by newline. For example, "io.containers.capabilities=sys_admin,mknod".'
required: false required: false
annotations:
description: 'The annotations of the image to build. Seperate by newline. For example, "org.opencontainers.image.version=1.5.6". Only supported by OCI images.'
required: false
base-image: base-image:
description: 'The base image to use to create a new container image' description: 'The base image to use to create a new container image'
required: false required: false

2
dist/index.js vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

View file

@ -16,12 +16,13 @@ export interface BuildahConfigSettings {
workingdir?: string; workingdir?: string;
arch?: string; arch?: string;
labels?: string[]; labels?: string[];
annotations?: string[];
} }
interface Buildah { interface Buildah {
buildUsingDocker( buildUsingDocker(
image: string, context: string, containerFiles: string[], buildArgs: string[], image: string, context: string, containerFiles: string[], buildArgs: string[],
useOCI: boolean, labels: string[], layers: string, useOCI: boolean, labels: string[], annotations: string[], layers: string,
extraArgs: string[], tlsVerify: boolean, arch?: string, platform?: string, extraArgs: string[], tlsVerify: boolean, arch?: string, platform?: string,
): Promise<CommandResult>; ): Promise<CommandResult>;
from(baseImage: string, tlsVerify: boolean, extraArgs: string[]): Promise<CommandResult>; from(baseImage: string, tlsVerify: boolean, extraArgs: string[]): Promise<CommandResult>;
@ -72,6 +73,7 @@ export class BuildahCli implements Buildah {
buildArgs: string[], buildArgs: string[],
useOCI: boolean, useOCI: boolean,
labels: string[], labels: string[],
annotations: string[],
layers: string, layers: string,
extraArgs: string[], extraArgs: string[],
tlsVerify: boolean, tlsVerify: boolean,
@ -95,6 +97,12 @@ export class BuildahCli implements Buildah {
args.push("--label"); args.push("--label");
args.push(label); args.push(label);
}); });
if (useOCI) {
annotations.forEach((annotation) => {
args.push("--annotation");
args.push(annotation);
});
}
buildArgs.forEach((buildArg) => { buildArgs.forEach((buildArg) => {
args.push("--build-arg"); args.push("--build-arg");
args.push(buildArg); args.push(buildArg);

View file

@ -1,5 +1,11 @@
// This file was auto-generated by action-io-generator. Do not edit by hand! // This file was auto-generated by action-io-generator. Do not edit by hand!
export enum Inputs { export enum Inputs {
/**
* The annotations of the image to build. Seperate by newline. For example, "org.opencontainers.image.version=1.5.6". Only supported by OCI images.
* Required: false
* Default: None.
*/
ANNOTATIONS = "annotations",
/** /**
* Label the image with this ARCH, instead of defaulting to the host architecture * Label the image with this ARCH, instead of defaulting to the host architecture
* Required: false * Required: false

View file

@ -36,6 +36,8 @@ export async function run(): Promise<void> {
const tagsList: string[] = tags.trim().split(/\s+/); const tagsList: string[] = tags.trim().split(/\s+/);
const labels = core.getInput(Inputs.LABELS); const labels = core.getInput(Inputs.LABELS);
const labelsList: string[] = labels ? splitByNewline(labels) : []; const labelsList: string[] = labels ? splitByNewline(labels) : [];
const annotations = core.getInput(Inputs.ANNOTATIONS);
const annotationList: string[] = annotations ? splitByNewline(annotations) : [];
const normalizedTagsList: string[] = []; const normalizedTagsList: string[] = [];
let isNormalized = false; let isNormalized = false;
@ -96,6 +98,7 @@ export async function run(): Promise<void> {
archs, archs,
platforms, platforms,
labelsList, labelsList,
annotationList,
buildahExtraArgs buildahExtraArgs
)); ));
} }
@ -152,6 +155,7 @@ async function doBuildUsingContainerFiles(
archs: string[], archs: string[],
platforms: string[], platforms: string[],
labels: string[], labels: string[],
annotations: string[],
extraArgs: string[] extraArgs: string[]
): Promise<string[]> { ): Promise<string[]> {
if (containerFiles.length === 1) { if (containerFiles.length === 1) {
@ -185,6 +189,7 @@ async function doBuildUsingContainerFiles(
buildArgs, buildArgs,
useOCI, useOCI,
labels, labels,
annotations,
layers, layers,
extraArgs, extraArgs,
tlsVerify, tlsVerify,
@ -205,6 +210,7 @@ async function doBuildUsingContainerFiles(
buildArgs, buildArgs,
useOCI, useOCI,
labels, labels,
annotations,
layers, layers,
extraArgs, extraArgs,
tlsVerify, tlsVerify,
@ -223,6 +229,7 @@ async function doBuildUsingContainerFiles(
buildArgs, buildArgs,
useOCI, useOCI,
labels, labels,
annotations,
layers, layers,
extraArgs, extraArgs,
tlsVerify, tlsVerify,
@ -239,6 +246,7 @@ async function doBuildUsingContainerFiles(
buildArgs, buildArgs,
useOCI, useOCI,
labels, labels,
annotations,
layers, layers,
extraArgs, extraArgs,
tlsVerify tlsVerify