mirror of
https://github.com/redhat-actions/buildah-build.git
synced 2025-06-08 01:49:03 +00:00
Refactor inputs to support docker/metadata-action (#76)
This commit is contained in:
parent
f123b1f960
commit
979e6a6c6e
9 changed files with 142 additions and 23 deletions
|
@ -7,7 +7,7 @@ import * as core from "@actions/core";
|
|||
import * as exec from "@actions/exec";
|
||||
import * as path from "path";
|
||||
import CommandResult from "./types";
|
||||
import { isStorageDriverOverlay, findFuseOverlayfsPath } from "./utils";
|
||||
import { isStorageDriverOverlay, findFuseOverlayfsPath, getFullImageName } from "./utils";
|
||||
|
||||
export interface BuildahConfigSettings {
|
||||
entrypoint?: string[];
|
||||
|
@ -157,7 +157,7 @@ export class BuildahCli implements Buildah {
|
|||
async tag(imageName: string, tags: string[]): Promise<CommandResult> {
|
||||
const args: string[] = [ "tag" ];
|
||||
for (const tag of tags) {
|
||||
args.push(`${imageName}:${tag}`);
|
||||
args.push(getFullImageName(imageName, tag));
|
||||
}
|
||||
core.info(`Tagging the built image with tags ${tags.toString()}`);
|
||||
return this.execute(args);
|
||||
|
|
|
@ -69,7 +69,7 @@ export enum Inputs {
|
|||
EXTRA_ARGS = "extra-args",
|
||||
/**
|
||||
* The name (reference) of the image to build
|
||||
* Required: true
|
||||
* Required: false
|
||||
* Default: None.
|
||||
*/
|
||||
IMAGE = "image",
|
||||
|
@ -92,7 +92,7 @@ export enum Inputs {
|
|||
*/
|
||||
PORT = "port",
|
||||
/**
|
||||
* The tags of the image to build. For multiple tags, seperate by a space. For example, "latest v1".
|
||||
* The tags of the image to build. For multiple tags, seperate by whitespace. For example, "latest v1".
|
||||
* Required: false
|
||||
* Default: "latest"
|
||||
*/
|
||||
|
|
19
src/index.ts
19
src/index.ts
|
@ -10,6 +10,7 @@ import { Inputs, Outputs } from "./generated/inputs-outputs";
|
|||
import { BuildahCli, BuildahConfigSettings } from "./buildah";
|
||||
import {
|
||||
getArch, getContainerfiles, getInputList, splitByNewline,
|
||||
isFullImageName, getFullImageName,
|
||||
} from "./utils";
|
||||
|
||||
export async function run(): Promise<void> {
|
||||
|
@ -30,16 +31,26 @@ export async function run(): Promise<void> {
|
|||
const DEFAULT_TAG = "latest";
|
||||
const workspace = process.env.GITHUB_WORKSPACE || process.cwd();
|
||||
const containerFiles = getContainerfiles();
|
||||
const image = core.getInput(Inputs.IMAGE, { required: true });
|
||||
const image = core.getInput(Inputs.IMAGE);
|
||||
const tags = core.getInput(Inputs.TAGS);
|
||||
const tagsList: string[] = tags.split(" ");
|
||||
const tagsList: string[] = tags.trim().split(/\s+/);
|
||||
|
||||
// info message if user doesn't provides any tag
|
||||
if (tagsList.length === 0) {
|
||||
core.info(`Input "${Inputs.TAGS}" is not provided, using default tag "${DEFAULT_TAG}"`);
|
||||
tagsList.push(DEFAULT_TAG);
|
||||
}
|
||||
const newImage = `${image}:${tagsList[0]}`;
|
||||
|
||||
// check if all tags provided are in `image:tag` format
|
||||
const isFullImageNameTag = isFullImageName(tagsList[0]);
|
||||
if (tagsList.some((tag) => isFullImageName(tag) !== isFullImageNameTag)) {
|
||||
throw new Error(`Input "${Inputs.TAGS}" cannot have a mix of full name and non full name tags`);
|
||||
}
|
||||
if (!isFullImageNameTag && !image) {
|
||||
throw new Error(`Input "${Inputs.IMAGE}" must be provided when using non full name tags`);
|
||||
}
|
||||
|
||||
const newImage = getFullImageName(image, tagsList[0]);
|
||||
const useOCI = core.getInput(Inputs.OCI) === "true";
|
||||
|
||||
const arch = getArch();
|
||||
|
@ -56,7 +67,7 @@ export async function run(): Promise<void> {
|
|||
}
|
||||
core.setOutput(Outputs.IMAGE, image);
|
||||
core.setOutput(Outputs.TAGS, tags);
|
||||
core.setOutput(Outputs.IMAGE_WITH_TAG, `${image}:${tagsList[0]}`);
|
||||
core.setOutput(Outputs.IMAGE_WITH_TAG, newImage);
|
||||
}
|
||||
|
||||
async function doBuildUsingContainerFiles(
|
||||
|
|
11
src/utils.ts
11
src/utils.ts
|
@ -110,3 +110,14 @@ export function getInputList(name: string): string[] {
|
|||
[],
|
||||
);
|
||||
}
|
||||
|
||||
export function isFullImageName(image: string): boolean {
|
||||
return image.indexOf(":") > 0;
|
||||
}
|
||||
|
||||
export function getFullImageName(image: string, tag: string): string {
|
||||
if (isFullImageName(tag)) {
|
||||
return tag;
|
||||
}
|
||||
return `${image}:${tag}`;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue