Code Cleanup

Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
divyansh42 2021-01-27 16:43:59 +05:30
parent 48975824e7
commit 557824d2d1
10 changed files with 12 additions and 50 deletions

View file

@ -2,8 +2,4 @@ module.exports = {
extends: [
"@redhat-actions/eslint-config",
],
ignorePatterns: [
"dist/",
"out/",
]
};

View file

@ -79,6 +79,7 @@ jobs:
with:
image: ${{ env.IMAGE_NAME }}
tags: 'latest v2'
base-image: 'registry.access.redhat.com/openjdk/openjdk-11-rhel7'
# To avoid hardcoding a particular version of the binary.
content: |
./spring-petclinic/target/spring-petclinic-*.BUILD-SNAPSHOT.jar

View file

@ -42,7 +42,7 @@ After building your image, use [push-to-registry](https://github.com/redhat-acti
<tr>
<td>base-image</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>
@ -153,6 +153,7 @@ jobs:
with:
image: my-new-image
tags: v1
base-image: some_image
dockerfiles: |
./Dockerfile
build-args: |

View file

@ -14,7 +14,7 @@ inputs:
default: latest
base-image:
description: 'The base image to use to create a new container image'
required: false
required: true
dockerfiles:
description: 'List of Dockerfile paths (eg: ./Dockerfile)'
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

@ -1,3 +0,0 @@
{
"java": "docker.io/fabric8/java-alpine-openjdk11-jre"
}

View file

@ -1,6 +1,7 @@
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import * as path from "path";
import CommandResult from "./types";
export interface BuildahConfigSettings {
entrypoint?: string[];

View file

@ -1,9 +1,6 @@
import * as core from "@actions/core";
import * as io from "@actions/io";
import * as recognizer from "language-recognizer";
import { promises as fs } from "fs";
import * as path from "path";
import { Language } from "language-recognizer/lib/types";
import { BuildahCli, BuildahConfigSettings } from "./buildah";
export async function run(): Promise<void> {
@ -27,7 +24,7 @@ export async function run(): Promise<void> {
await doBuildUsingDockerFiles(cli, newImage, workspace, dockerFiles, useOCI);
}
else {
await doBuildFromScratch(cli, newImage, workspace, useOCI);
await doBuildFromScratch(cli, newImage, useOCI);
}
if (tagsList.length > 1) {
@ -54,32 +51,17 @@ async function doBuildUsingDockerFiles(
}
async function doBuildFromScratch(
cli: BuildahCli, newImage: string, workspace: string, useOCI: boolean,
cli: BuildahCli, newImage: string, useOCI: boolean,
): Promise<void> {
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 entrypoint = getInputList("entrypoint");
const port = core.getInput("port");
const workingDir = core.getInput("workdir");
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 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);

View file

@ -3,3 +3,5 @@ type CommandResult = {
output: string
error: string
};
export default CommandResult;