mirror of
https://github.com/redhat-actions/buildah-build.git
synced 2025-04-20 17:11:23 +00:00
Code Cleanup
Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
parent
48975824e7
commit
557824d2d1
10 changed files with 12 additions and 50 deletions
|
@ -2,8 +2,4 @@ module.exports = {
|
||||||
extends: [
|
extends: [
|
||||||
"@redhat-actions/eslint-config",
|
"@redhat-actions/eslint-config",
|
||||||
],
|
],
|
||||||
ignorePatterns: [
|
|
||||||
"dist/",
|
|
||||||
"out/",
|
|
||||||
]
|
|
||||||
};
|
};
|
1
.github/workflows/verify-build.yml
vendored
1
.github/workflows/verify-build.yml
vendored
|
@ -79,6 +79,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
image: ${{ env.IMAGE_NAME }}
|
image: ${{ env.IMAGE_NAME }}
|
||||||
tags: 'latest v2'
|
tags: 'latest v2'
|
||||||
|
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: |
|
||||||
./spring-petclinic/target/spring-petclinic-*.BUILD-SNAPSHOT.jar
|
./spring-petclinic/target/spring-petclinic-*.BUILD-SNAPSHOT.jar
|
||||||
|
|
|
@ -42,7 +42,7 @@ After building your image, use [push-to-registry](https://github.com/redhat-acti
|
||||||
<tr>
|
<tr>
|
||||||
<td>base-image</td>
|
<td>base-image</td>
|
||||||
<td>No</td>
|
<td>No</td>
|
||||||
<td>The base image to use to create the initial container. If not specified, the action will try to pick one automatically. (N.B: At this time the action is only able to auto select Java base image)</td>
|
<td>The base image to use to create the initial container.</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -153,6 +153,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
image: my-new-image
|
image: my-new-image
|
||||||
tags: v1
|
tags: v1
|
||||||
|
base-image: some_image
|
||||||
dockerfiles: |
|
dockerfiles: |
|
||||||
./Dockerfile
|
./Dockerfile
|
||||||
build-args: |
|
build-args: |
|
||||||
|
|
|
@ -14,7 +14,7 @@ inputs:
|
||||||
default: latest
|
default: latest
|
||||||
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: true
|
||||||
dockerfiles:
|
dockerfiles:
|
||||||
description: 'List of Dockerfile paths (eg: ./Dockerfile)'
|
description: 'List of Dockerfile paths (eg: ./Dockerfile)'
|
||||||
required: false
|
required: false
|
||||||
|
|
2
dist/index.js
vendored
2
dist/index.js
vendored
File diff suppressed because one or more lines are too long
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
|
@ -1,3 +0,0 @@
|
||||||
{
|
|
||||||
"java": "docker.io/fabric8/java-alpine-openjdk11-jre"
|
|
||||||
}
|
|
|
@ -1,6 +1,7 @@
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as exec from "@actions/exec";
|
import * as exec from "@actions/exec";
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
|
import CommandResult from "./types";
|
||||||
|
|
||||||
export interface BuildahConfigSettings {
|
export interface BuildahConfigSettings {
|
||||||
entrypoint?: string[];
|
entrypoint?: string[];
|
||||||
|
|
42
src/index.ts
42
src/index.ts
|
@ -1,9 +1,6 @@
|
||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import * as io from "@actions/io";
|
import * as io from "@actions/io";
|
||||||
import * as recognizer from "language-recognizer";
|
|
||||||
import { promises as fs } from "fs";
|
|
||||||
import * as path from "path";
|
import * as path from "path";
|
||||||
import { Language } from "language-recognizer/lib/types";
|
|
||||||
import { BuildahCli, BuildahConfigSettings } from "./buildah";
|
import { BuildahCli, BuildahConfigSettings } from "./buildah";
|
||||||
|
|
||||||
export async function run(): Promise<void> {
|
export async function run(): Promise<void> {
|
||||||
|
@ -27,7 +24,7 @@ export async function run(): Promise<void> {
|
||||||
await doBuildUsingDockerFiles(cli, newImage, workspace, dockerFiles, useOCI);
|
await doBuildUsingDockerFiles(cli, newImage, workspace, dockerFiles, useOCI);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
await doBuildFromScratch(cli, newImage, workspace, useOCI);
|
await doBuildFromScratch(cli, newImage, useOCI);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tagsList.length > 1) {
|
if (tagsList.length > 1) {
|
||||||
|
@ -54,32 +51,17 @@ async function doBuildUsingDockerFiles(
|
||||||
}
|
}
|
||||||
|
|
||||||
async function doBuildFromScratch(
|
async function doBuildFromScratch(
|
||||||
cli: BuildahCli, newImage: string, workspace: string, useOCI: boolean,
|
cli: BuildahCli, newImage: string, useOCI: boolean,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
core.info(`Performing build from scratch`);
|
core.info(`Performing build from scratch`);
|
||||||
|
|
||||||
let baseImage = core.getInput("base-image");
|
const baseImage = core.getInput("base-image", { required: true });
|
||||||
const content = getInputList("content");
|
const content = getInputList("content");
|
||||||
const entrypoint = getInputList("entrypoint");
|
const entrypoint = getInputList("entrypoint");
|
||||||
const port = core.getInput("port");
|
const port = core.getInput("port");
|
||||||
const workingDir = core.getInput("workdir");
|
const workingDir = core.getInput("workdir");
|
||||||
const envs = getInputList("envs");
|
const envs = getInputList("envs");
|
||||||
|
|
||||||
// if base-image is not specified by the user we need to pick one automatically
|
|
||||||
if (!baseImage) {
|
|
||||||
if (workspace) {
|
|
||||||
// check language/framework used and pick base-image automatically
|
|
||||||
const languages = await recognizer.detectLanguages(workspace);
|
|
||||||
baseImage = await getSuggestedBaseImage(languages);
|
|
||||||
if (!baseImage) {
|
|
||||||
throw new Error("No base image found to create a new container");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
throw new Error("No base image found to create a new container");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const container = await cli.from(baseImage);
|
const container = await cli.from(baseImage);
|
||||||
const containerId = container.output.replace("\n", "");
|
const containerId = container.output.replace("\n", "");
|
||||||
|
|
||||||
|
@ -109,22 +91,4 @@ function getInputList(name: string): string[] {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSuggestedBaseImage(languages: Language[]): Promise<string> {
|
|
||||||
let baseImage = "";
|
|
||||||
for (const language of languages) {
|
|
||||||
baseImage = await getBaseImageByLanguage(language);
|
|
||||||
if (baseImage) {
|
|
||||||
return baseImage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return baseImage;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function getBaseImageByLanguage(language: Language): Promise<string> {
|
|
||||||
const rawData = await fs.readFile(path.join(__dirname, "..", "language-image.json"), "utf-8");
|
|
||||||
const languageImageJSON = JSON.parse(rawData);
|
|
||||||
return languageImageJSON[language.name];
|
|
||||||
}
|
|
||||||
|
|
||||||
run().catch(core.setFailed);
|
run().catch(core.setFailed);
|
||||||
|
|
|
@ -3,3 +3,5 @@ type CommandResult = {
|
||||||
output: string
|
output: string
|
||||||
error: string
|
error: string
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default CommandResult;
|
||||||
|
|
Loading…
Reference in a new issue