mirror of
https://github.com/redhat-actions/buildah-build.git
synced 2025-04-20 09:01:23 +00:00
Add IO generator and CI checks
Signed-off-by: divyansh42 <diagrawa@redhat.com>
This commit is contained in:
parent
46cc120d66
commit
f6079a53f7
9 changed files with 188 additions and 34 deletions
48
.github/workflows/ci.yml
vendored
Normal file
48
.github/workflows/ci.yml
vendored
Normal file
|
@ -0,0 +1,48 @@
|
|||
name: CI checks
|
||||
on:
|
||||
push:
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
name: Run ESLint
|
||||
runs-on: ubuntu-20.04
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: npm ci
|
||||
- run: npm run lint
|
||||
|
||||
check-dist:
|
||||
name: Check Distribution
|
||||
runs-on: ubuntu-20.04
|
||||
env:
|
||||
BUNDLE_FILE: "dist/index.js"
|
||||
BUNDLE_COMMAND: "npm run bundle"
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Install
|
||||
run: npm ci
|
||||
|
||||
- name: Verify Latest Bundle
|
||||
uses: redhat-actions/common/bundle-verifier@v1
|
||||
with:
|
||||
bundle_file: ${{ env.BUNDLE_FILE }}
|
||||
bundle_command: ${{ env.BUNDLE_COMMAND }}
|
||||
|
||||
check-inputs-outputs:
|
||||
name: Check Input and Output enums
|
||||
runs-on: ubuntu-20.04
|
||||
env:
|
||||
IO_FILE: ./src/generated/inputs-outputs.ts
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Verify Input and Output enums
|
||||
uses: redhat-actions/common/action-io-generator@main
|
||||
with:
|
||||
io_file: ${{ env.IO_FILE }}
|
18
.github/workflows/verify-bundle.yml
vendored
18
.github/workflows/verify-bundle.yml
vendored
|
@ -1,18 +0,0 @@
|
|||
name: Verify Bundle
|
||||
on: [ push, pull_request ]
|
||||
|
||||
jobs:
|
||||
verify-bundle:
|
||||
name: Verify Distribution Bundle
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Check Distribution
|
||||
uses: tetchel/bundle-verifier-action@v0.0.2
|
||||
with:
|
||||
bundle_file: dist/index.js
|
||||
bundle_command: "npm run bundle"
|
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
10
git-hooks/pre-commit
Normal file
10
git-hooks/pre-commit
Normal file
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
### Copy this into .git/hooks and overwrite the empty one.
|
||||
### This will ensure the bundle and ins-outs verification checks won't fail for you.
|
||||
|
||||
echo "----- Pre-commit -----"
|
||||
set -ex
|
||||
npx action-io-generator -o src/generated/inputs-outputs.ts
|
||||
npm run bundle
|
||||
git add -v dist/ src/generated
|
22
package-lock.json
generated
22
package-lock.json
generated
|
@ -128,6 +128,28 @@
|
|||
"fastq": "^1.6.0"
|
||||
}
|
||||
},
|
||||
"@redhat-actions/action-io-generator": {
|
||||
"version": "1.5.0",
|
||||
"resolved": "https://registry.npmjs.org/@redhat-actions/action-io-generator/-/action-io-generator-1.5.0.tgz",
|
||||
"integrity": "sha512-zaBZyP0ev5c36j0h8EyvqbD+fhUjDOeme2qzVa+CSWjeGVAsgdZREzE8smE3QA6xXpMHPU5keT+q2iN8/hq5uA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"js-yaml": "^3.14.1",
|
||||
"minimist": "^1.2.5"
|
||||
},
|
||||
"dependencies": {
|
||||
"js-yaml": {
|
||||
"version": "3.14.1",
|
||||
"resolved": "https://registry.npmjs.org/js-yaml/-/js-yaml-3.14.1.tgz",
|
||||
"integrity": "sha512-okMH7OXXJ7YrN9Ok3/SXrnu4iX9yOk+25nqX4imS2npuvTYDmo/QEZoqwZkYaIDk3jVvBOTOIEgEhaLOynBS9g==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"argparse": "^1.0.7",
|
||||
"esprima": "^4.0.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"@redhat-actions/eslint-config": {
|
||||
"version": "1.2.11",
|
||||
"resolved": "https://registry.npmjs.org/@redhat-actions/eslint-config/-/eslint-config-1.2.11.tgz",
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
"language-recognizer": "0.0.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@redhat-actions/action-io-generator": "^1.5.0",
|
||||
"@redhat-actions/eslint-config": "^1.2.11",
|
||||
"@redhat-actions/tsconfig": "^1.1.1",
|
||||
"@types/node": "^12",
|
||||
|
|
90
src/generated/inputs-outputs.ts
Normal file
90
src/generated/inputs-outputs.ts
Normal file
|
@ -0,0 +1,90 @@
|
|||
// This file was auto-generated by action-io-generator. Do not edit by hand!
|
||||
export enum Inputs {
|
||||
/**
|
||||
* The base image to use to create a new container image
|
||||
* Required: true
|
||||
* Default: None.
|
||||
*/
|
||||
BASE_IMAGE = "base-image",
|
||||
/**
|
||||
* List of --build-args to pass to buildah
|
||||
* Required: false
|
||||
* Default: None.
|
||||
*/
|
||||
BUILD_ARGS = "build-args",
|
||||
/**
|
||||
* List of files/directories to copy inside the base image
|
||||
* Required: false
|
||||
* Default: None.
|
||||
*/
|
||||
CONTENT = "content",
|
||||
/**
|
||||
* Path of the directory to use as context (default: .)
|
||||
* Required: false
|
||||
* Default: "."
|
||||
*/
|
||||
CONTEXT = "context",
|
||||
/**
|
||||
* List of Dockerfile paths (eg: ./Dockerfile)
|
||||
* Required: false
|
||||
* Default: None.
|
||||
*/
|
||||
DOCKERFILES = "dockerfiles",
|
||||
/**
|
||||
* The entry point to set for containers based on image
|
||||
* Required: false
|
||||
* Default: None.
|
||||
*/
|
||||
ENTRYPOINT = "entrypoint",
|
||||
/**
|
||||
* List of environment variables to be set when running containers based on image
|
||||
* Required: false
|
||||
* Default: None.
|
||||
*/
|
||||
ENVS = "envs",
|
||||
/**
|
||||
* The name (reference) of the image to build
|
||||
* Required: true
|
||||
* Default: None.
|
||||
*/
|
||||
IMAGE = "image",
|
||||
/**
|
||||
* Set to true to build using the OCI image format instead of the Docker image format
|
||||
* Required: false
|
||||
* Default: "false"
|
||||
*/
|
||||
OCI = "oci",
|
||||
/**
|
||||
* The port to expose when running containers based on image
|
||||
* Required: false
|
||||
* Default: None.
|
||||
*/
|
||||
PORT = "port",
|
||||
/**
|
||||
* The tags of the image to build. For multiple tags, seperate by a space. For example, "latest v1".
|
||||
* Required: false
|
||||
* Default: "latest"
|
||||
*/
|
||||
TAGS = "tags",
|
||||
/**
|
||||
* The working directory to use within the container
|
||||
* Required: false
|
||||
* Default: None.
|
||||
*/
|
||||
WORKDIR = "workdir",
|
||||
}
|
||||
|
||||
export enum Outputs {
|
||||
/**
|
||||
* Name of the image built
|
||||
* Required: false
|
||||
* Default: None.
|
||||
*/
|
||||
IMAGE = "image",
|
||||
/**
|
||||
* List of the tags that were created, separated by spaces
|
||||
* Required: false
|
||||
* Default: None.
|
||||
*/
|
||||
TAGS = "tags",
|
||||
}
|
29
src/index.ts
29
src/index.ts
|
@ -1,6 +1,7 @@
|
|||
import * as core from "@actions/core";
|
||||
import * as io from "@actions/io";
|
||||
import * as path from "path";
|
||||
import { Inputs, Outputs } from "./generated/inputs-outputs";
|
||||
import { BuildahCli, BuildahConfigSettings } from "./buildah";
|
||||
|
||||
export async function run(): Promise<void> {
|
||||
|
@ -13,12 +14,12 @@ export async function run(): Promise<void> {
|
|||
const cli: BuildahCli = new BuildahCli(buildahPath);
|
||||
|
||||
const workspace = process.env.GITHUB_WORKSPACE || process.cwd();
|
||||
const dockerFiles = getInputList("dockerfiles");
|
||||
const image = core.getInput("image", { required: true });
|
||||
const tags = core.getInput("tags") || "latest";
|
||||
const dockerFiles = getInputList(Inputs.DOCKERFILES);
|
||||
const image = core.getInput(Inputs.IMAGE, { required: true });
|
||||
const tags = core.getInput(Inputs.TAGS) || "latest";
|
||||
const tagsList: string[] = tags.split(" ");
|
||||
const newImage = `${image}:${tagsList[0]}`;
|
||||
const useOCI = core.getInput("oci") === "true";
|
||||
const useOCI = core.getInput(Inputs.OCI) === "true";
|
||||
|
||||
if (dockerFiles.length !== 0) {
|
||||
await doBuildUsingDockerFiles(cli, newImage, workspace, dockerFiles, useOCI);
|
||||
|
@ -30,8 +31,8 @@ export async function run(): Promise<void> {
|
|||
if (tagsList.length > 1) {
|
||||
await cli.tag(image, tagsList);
|
||||
}
|
||||
core.setOutput("image", image);
|
||||
core.setOutput("tags", tags);
|
||||
core.setOutput(Outputs.IMAGE, image);
|
||||
core.setOutput(Outputs.TAGS, tags);
|
||||
}
|
||||
|
||||
async function doBuildUsingDockerFiles(
|
||||
|
@ -44,8 +45,8 @@ async function doBuildUsingDockerFiles(
|
|||
core.info(`Performing build from ${dockerFiles.length} Dockerfiles`);
|
||||
}
|
||||
|
||||
const context = path.join(workspace, core.getInput("context"));
|
||||
const buildArgs = getInputList("build-args");
|
||||
const context = path.join(workspace, core.getInput(Inputs.CONTEXT));
|
||||
const buildArgs = getInputList(Inputs.BUILD_ARGS);
|
||||
const dockerFileAbsPaths = dockerFiles.map((file) => path.join(workspace, file));
|
||||
await cli.buildUsingDocker(newImage, context, dockerFileAbsPaths, buildArgs, useOCI);
|
||||
}
|
||||
|
@ -55,12 +56,12 @@ async function doBuildFromScratch(
|
|||
): Promise<void> {
|
||||
core.info(`Performing build from scratch`);
|
||||
|
||||
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");
|
||||
const baseImage = core.getInput(Inputs.BASE_IMAGE, { required: true });
|
||||
const content = getInputList(Inputs.CONTENT);
|
||||
const entrypoint = getInputList(Inputs.ENTRYPOINT);
|
||||
const port = core.getInput(Inputs.PORT);
|
||||
const workingDir = core.getInput(Inputs.WORKDIR);
|
||||
const envs = getInputList(Inputs.ENVS);
|
||||
|
||||
const container = await cli.from(baseImage);
|
||||
const containerId = container.output.replace("\n", "");
|
||||
|
|
Loading…
Reference in a new issue