Skip to content

Commit

Permalink
Add support for annotations as an action input.
Browse files Browse the repository at this point in the history
  • Loading branch information
AshCorr committed Apr 8, 2024
1 parent 7a95fa7 commit 2d3449c
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 5 deletions.
5 changes: 4 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ module.exports = {
extends: [
"@redhat-actions/eslint-config",
],
};
ignorePatterns: [
"src/generated/*"
]
};
8 changes: 7 additions & 1 deletion .github/workflows/docker_metadata_action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ jobs:
layers: false
tags: ${{ steps.docker-metadata.outputs.tags }}
labels: ${{ steps.docker-metadata.outputs.labels }}
annotations: ${{ steps.docker-metadata.outputs.annotations }}
containerfiles: |
./Containerfile
extra-args: |
Expand All @@ -83,6 +84,8 @@ jobs:
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.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.description"'
Expand All @@ -107,7 +110,7 @@ jobs:

- name: Docker Metadata
id: docker-metadata
uses: docker/metadata-action@v4
uses: docker/metadata-action@v5
with:
images: |
${{ env.IMAGE_NAME }}
Expand Down Expand Up @@ -154,6 +157,7 @@ jobs:
with:
tags: ${{ steps.docker-metadata.outputs.tags }}
labels: ${{ steps.docker-metadata.outputs.labels }}
annotations: ${{ steps.docker-metadata.outputs.annotations }}
base-image: 'registry.access.redhat.com/openjdk/openjdk-11-rhel7'
# To avoid hardcoding a particular version of the binary.
content: |
Expand Down Expand Up @@ -181,5 +185,7 @@ jobs:
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.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.description"'
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ inputs:
labels:
description: 'The labels of the image to build. Seperate by newline. For example, "io.containers.capabilities=sys_admin,mknod".'
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:
description: 'The base image to use to create a new container image'
required: false
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

10 changes: 9 additions & 1 deletion src/buildah.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ export interface BuildahConfigSettings {
workingdir?: string;
arch?: string;
labels?: string[];
annotations?: string[];
}

interface Buildah {
buildUsingDocker(
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,
): Promise<CommandResult>;
from(baseImage: string, tlsVerify: boolean, extraArgs: string[]): Promise<CommandResult>;
Expand Down Expand Up @@ -72,6 +73,7 @@ export class BuildahCli implements Buildah {
buildArgs: string[],
useOCI: boolean,
labels: string[],
annotations: string[],
layers: string,
extraArgs: string[],
tlsVerify: boolean,
Expand All @@ -95,6 +97,12 @@ export class BuildahCli implements Buildah {
args.push("--label");
args.push(label);
});
if (useOCI) {
annotations.forEach((annotation) => {
args.push("--annotation");
args.push(annotation);
});
}
buildArgs.forEach((buildArg) => {
args.push("--build-arg");
args.push(buildArg);
Expand Down
6 changes: 6 additions & 0 deletions src/generated/inputs-outputs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// This file was auto-generated by action-io-generator. Do not edit by hand!
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
* Required: false
Expand Down
8 changes: 8 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ export async function run(): Promise<void> {
const tagsList: string[] = tags.trim().split(/\s+/);
const labels = core.getInput(Inputs.LABELS);
const labelsList: string[] = labels ? splitByNewline(labels) : [];
const annotations = core.getInput(Inputs.ANNOTATIONS);
const annotationList: string[] = annotations ? splitByNewline(annotations) : [];

const normalizedTagsList: string[] = [];
let isNormalized = false;
Expand Down Expand Up @@ -96,6 +98,7 @@ export async function run(): Promise<void> {
archs,
platforms,
labelsList,
annotationList,
buildahExtraArgs
));
}
Expand Down Expand Up @@ -152,6 +155,7 @@ async function doBuildUsingContainerFiles(
archs: string[],
platforms: string[],
labels: string[],
annotations: string[],
extraArgs: string[]
): Promise<string[]> {
if (containerFiles.length === 1) {
Expand Down Expand Up @@ -185,6 +189,7 @@ async function doBuildUsingContainerFiles(
buildArgs,
useOCI,
labels,
annotations,
layers,
extraArgs,
tlsVerify,
Expand All @@ -205,6 +210,7 @@ async function doBuildUsingContainerFiles(
buildArgs,
useOCI,
labels,
annotations,
layers,
extraArgs,
tlsVerify,
Expand All @@ -223,6 +229,7 @@ async function doBuildUsingContainerFiles(
buildArgs,
useOCI,
labels,
annotations,
layers,
extraArgs,
tlsVerify,
Expand All @@ -239,6 +246,7 @@ async function doBuildUsingContainerFiles(
buildArgs,
useOCI,
labels,
annotations,
layers,
extraArgs,
tlsVerify
Expand Down

0 comments on commit 2d3449c

Please sign in to comment.