Skip to content

Commit 2d3449c

Browse files
committed
Add support for annotations as an action input.
1 parent 7a95fa7 commit 2d3449c

File tree

8 files changed

+39
-5
lines changed

8 files changed

+39
-5
lines changed

.eslintrc.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,7 @@ module.exports = {
22
extends: [
33
"@redhat-actions/eslint-config",
44
],
5-
};
5+
ignorePatterns: [
6+
"src/generated/*"
7+
]
8+
};

.github/workflows/docker_metadata_action.yml

+7-1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ jobs:
6363
layers: false
6464
tags: ${{ steps.docker-metadata.outputs.tags }}
6565
labels: ${{ steps.docker-metadata.outputs.labels }}
66+
annotations: ${{ steps.docker-metadata.outputs.annotations }}
6667
containerfiles: |
6768
./Containerfile
6869
extra-args: |
@@ -83,6 +84,8 @@ jobs:
8384
set -x
8485
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.title"'
8586
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.description"'
87+
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Annotations."org.opencontainers.image.title"'
88+
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Annotations."org.opencontainers.image.description"'
8689
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.title"'
8790
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.description"'
8891
@@ -107,7 +110,7 @@ jobs:
107110

108111
- name: Docker Metadata
109112
id: docker-metadata
110-
uses: docker/metadata-action@v4
113+
uses: docker/metadata-action@v5
111114
with:
112115
images: |
113116
${{ env.IMAGE_NAME }}
@@ -154,6 +157,7 @@ jobs:
154157
with:
155158
tags: ${{ steps.docker-metadata.outputs.tags }}
156159
labels: ${{ steps.docker-metadata.outputs.labels }}
160+
annotations: ${{ steps.docker-metadata.outputs.annotations }}
157161
base-image: 'registry.access.redhat.com/openjdk/openjdk-11-rhel7'
158162
# To avoid hardcoding a particular version of the binary.
159163
content: |
@@ -181,5 +185,7 @@ jobs:
181185
set -x
182186
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.title"'
183187
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Labels."org.opencontainers.image.description"'
188+
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Annotations."org.opencontainers.image.title"'
189+
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.OCIv1.config.Annotations."org.opencontainers.image.description"'
184190
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.title"'
185191
buildah inspect ${{ steps.build_image.outputs.image-with-tag }} | jq '.Docker.config.Labels."org.opencontainers.image.description"'

action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ inputs:
1515
labels:
1616
description: 'The labels of the image to build. Seperate by newline. For example, "io.containers.capabilities=sys_admin,mknod".'
1717
required: false
18+
annotations:
19+
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.'
20+
required: false
1821
base-image:
1922
description: 'The base image to use to create a new container image'
2023
required: false

dist/index.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/buildah.ts

+9-1
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ export interface BuildahConfigSettings {
1616
workingdir?: string;
1717
arch?: string;
1818
labels?: string[];
19+
annotations?: string[];
1920
}
2021

2122
interface Buildah {
2223
buildUsingDocker(
2324
image: string, context: string, containerFiles: string[], buildArgs: string[],
24-
useOCI: boolean, labels: string[], layers: string,
25+
useOCI: boolean, labels: string[], annotations: string[], layers: string,
2526
extraArgs: string[], tlsVerify: boolean, arch?: string, platform?: string,
2627
): Promise<CommandResult>;
2728
from(baseImage: string, tlsVerify: boolean, extraArgs: string[]): Promise<CommandResult>;
@@ -72,6 +73,7 @@ export class BuildahCli implements Buildah {
7273
buildArgs: string[],
7374
useOCI: boolean,
7475
labels: string[],
76+
annotations: string[],
7577
layers: string,
7678
extraArgs: string[],
7779
tlsVerify: boolean,
@@ -95,6 +97,12 @@ export class BuildahCli implements Buildah {
9597
args.push("--label");
9698
args.push(label);
9799
});
100+
if (useOCI) {
101+
annotations.forEach((annotation) => {
102+
args.push("--annotation");
103+
args.push(annotation);
104+
});
105+
}
98106
buildArgs.forEach((buildArg) => {
99107
args.push("--build-arg");
100108
args.push(buildArg);

src/generated/inputs-outputs.ts

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

src/index.ts

+8
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ export async function run(): Promise<void> {
3636
const tagsList: string[] = tags.trim().split(/\s+/);
3737
const labels = core.getInput(Inputs.LABELS);
3838
const labelsList: string[] = labels ? splitByNewline(labels) : [];
39+
const annotations = core.getInput(Inputs.ANNOTATIONS);
40+
const annotationList: string[] = annotations ? splitByNewline(annotations) : [];
3941

4042
const normalizedTagsList: string[] = [];
4143
let isNormalized = false;
@@ -96,6 +98,7 @@ export async function run(): Promise<void> {
9698
archs,
9799
platforms,
98100
labelsList,
101+
annotationList,
99102
buildahExtraArgs
100103
));
101104
}
@@ -152,6 +155,7 @@ async function doBuildUsingContainerFiles(
152155
archs: string[],
153156
platforms: string[],
154157
labels: string[],
158+
annotations: string[],
155159
extraArgs: string[]
156160
): Promise<string[]> {
157161
if (containerFiles.length === 1) {
@@ -185,6 +189,7 @@ async function doBuildUsingContainerFiles(
185189
buildArgs,
186190
useOCI,
187191
labels,
192+
annotations,
188193
layers,
189194
extraArgs,
190195
tlsVerify,
@@ -205,6 +210,7 @@ async function doBuildUsingContainerFiles(
205210
buildArgs,
206211
useOCI,
207212
labels,
213+
annotations,
208214
layers,
209215
extraArgs,
210216
tlsVerify,
@@ -223,6 +229,7 @@ async function doBuildUsingContainerFiles(
223229
buildArgs,
224230
useOCI,
225231
labels,
232+
annotations,
226233
layers,
227234
extraArgs,
228235
tlsVerify,
@@ -239,6 +246,7 @@ async function doBuildUsingContainerFiles(
239246
buildArgs,
240247
useOCI,
241248
labels,
249+
annotations,
242250
layers,
243251
extraArgs,
244252
tlsVerify

0 commit comments

Comments
 (0)