From 329be0a47072579efa0e7e566c3f033217baa02a Mon Sep 17 00:00:00 2001 From: Tim Etchells Date: Mon, 16 Nov 2020 23:29:58 -0500 Subject: [PATCH] Remove out/, add badges Signed-off-by: Tim Etchells --- README.md | 12 ++--- out/src/buildah.js | 105 ------------------------------------------- out/src/index.js | 108 --------------------------------------------- 3 files changed, 7 insertions(+), 218 deletions(-) delete mode 100644 out/src/buildah.js delete mode 100644 out/src/index.js diff --git a/README.md b/README.md index 91661ef..8d14ec3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,9 @@ # buildah-action +[![tag badge](https://img.shields.io/github/v/tag/redhat-actions/buildah-action?sort=semver)](https://github.com/redhat-actions/buildah-action/tags) +[![license badge](https://img.shields.io/github/license/redhat-actions/buildah-action)](./LICENSE) +[![size badge](https://img.shields.io/github/size/redhat-actions/buildah-action/dist/index.js)](./dist) + Buildah is a GitHub Action for building OCI-compatible (Docker- and Kubernetes-compatible) images quickly and easily. Buildah action works only on Linux distributions, and it is not supported on Windows or Mac platforms at this time. @@ -54,8 +58,8 @@ Note that GitHub's [Ubuntu Environments](https://github.com/actions/virtual-envi ## Examples -``` -name: CI +```yaml +name: Build Image on: [push] jobs: @@ -78,7 +82,7 @@ jobs: content: | target/spring-petclinic-2.3.0.BUILD-SNAPSHOT.jar entrypoint: | - java + java -jar spring-petclinic-2.3.0.BUILD-SNAPSHOT.jar port: 8080 @@ -95,5 +99,3 @@ If you discover an issue please file a bug in [GitHub issues](https://github.com ## License MIT, See [LICENSE](https://github.com/redhat-actions/buildah/blob/main/LICENSE.md) for more information. - - diff --git a/out/src/buildah.js b/out/src/buildah.js deleted file mode 100644 index 4138231..0000000 --- a/out/src/buildah.js +++ /dev/null @@ -1,105 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.BuildahCli = void 0; -const core = require("@actions/core"); -const exec = require("@actions/exec"); -class BuildahCli { - constructor(executable) { - this.executable = executable; - } - from(baseImage) { - return __awaiter(this, void 0, void 0, function* () { - return yield this.execute(['from', baseImage]); - }); - } - copy(container, contentToCopy, path) { - return __awaiter(this, void 0, void 0, function* () { - core.debug('copy'); - core.debug(container); - let result; - for (const content of contentToCopy) { - const args = ["copy", container, content]; - if (path) { - args.push(path); - } - result = yield this.execute(args); - if (result.succeeded === false) { - return result; - } - } - return result; - }); - } - config(container, settings) { - return __awaiter(this, void 0, void 0, function* () { - core.debug('config'); - core.debug(container); - const args = ['config']; - if (settings.entrypoint) { - args.push('--entrypoint'); - args.push(this.convertArrayToStringArg(settings.entrypoint)); - } - if (settings.port) { - args.push('--port'); - args.push(settings.port); - } - if (settings.envs) { - settings.envs.forEach((env) => { - args.push('--env'); - args.push(env); - }); - } - args.push(container); - return yield this.execute(args); - }); - } - commit(container, newImageName, flags = []) { - return __awaiter(this, void 0, void 0, function* () { - core.debug('commit'); - core.debug(container); - core.debug(newImageName); - const args = ["commit", ...flags, container, newImageName]; - return yield this.execute(args); - }); - } - convertArrayToStringArg(args) { - let arrayAsString = '['; - args.forEach(arg => { - arrayAsString += `"${arg}",`; - }); - return `${arrayAsString.slice(0, -1)}]`; - } - execute(args) { - return __awaiter(this, void 0, void 0, function* () { - if (!this.executable) { - return Promise.reject(new Error('Unable to call buildah executable')); - } - let output = ''; - let error = ''; - const options = {}; - options.listeners = { - stdout: (data) => { - output += data.toString(); - }, - stderr: (data) => { - error += data.toString(); - } - }; - const exitCode = yield exec.exec(this.executable, args, options); - if (exitCode === 1) { - return Promise.resolve({ succeeded: false, error: error }); - } - return Promise.resolve({ succeeded: true, output: output }); - }); - } -} -exports.BuildahCli = BuildahCli; diff --git a/out/src/index.js b/out/src/index.js deleted file mode 100644 index 8b92539..0000000 --- a/out/src/index.js +++ /dev/null @@ -1,108 +0,0 @@ -"use strict"; -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.run = void 0; -const core = require("@actions/core"); -const io = require("@actions/io"); -const buildah_1 = require("./buildah"); -const recognizer = require("language-recognizer"); -const fs_1 = require("fs"); -const path = require("path"); -function run() { - return __awaiter(this, void 0, void 0, function* () { - let baseImage = core.getInput('base-image'); - const content = getInputList('content'); - const newImageName = core.getInput('new-image-name'); - const entrypoint = getInputList('entrypoint'); - const port = core.getInput('port'); - const workingDir = core.getInput('working-dir'); - const envs = getInputList('envs'); - if (process.env.RUNNER_OS !== 'Linux') { - return Promise.reject(new Error('Only linux platform is supported at this time.')); - } - // get buildah cli - const buildahPath = yield io.which('buildah', true); - // if base-image is not specified by the user we need to pick one automatically - if (!baseImage) { - const workspace = process.env['GITHUB_WORKSPACE']; - if (workspace) { - // check language/framework used and pick base-image automatically - const languages = yield recognizer.detectLanguages(workspace); - baseImage = yield getSuggestedBaseImage(languages); - if (!baseImage) { - return Promise.reject(new Error('No base image found to create a new container')); - } - } - else { - return Promise.reject(new Error('No base image found to create a new container')); - } - } - // create the new image - const cli = new buildah_1.BuildahCli(buildahPath); - const container = yield cli.from(baseImage); - if (container.succeeded === false) { - return Promise.reject(new Error(container.reason)); - } - const containerId = container.output.replace('\n', ''); - const copyResult = yield cli.copy(containerId, content); - if (copyResult.succeeded === false) { - return Promise.reject(new Error(copyResult.reason)); - } - const newImageConfig = { - entrypoint: entrypoint, - port: port, - workingdir: workingDir, - envs: envs - }; - const configResult = yield cli.config(containerId, newImageConfig); - if (configResult.succeeded === false) { - return Promise.reject(new Error(configResult.reason)); - } - const commit = yield cli.commit(containerId, newImageName, ['--squash']); - if (commit.succeeded === false) { - return Promise.reject(new Error(commit.reason)); - } - }); -} -exports.run = run; -function getInputList(name) { - const items = core.getInput(name); - if (!items) { - return []; - } - return items - .split(/\r?\n/) - .filter(x => x) - .reduce((acc, line) => acc.concat(line).map(pat => pat.trim()), []); -} -function getSuggestedBaseImage(languages) { - return __awaiter(this, void 0, void 0, function* () { - if (!languages || languages.length === 0) { - return undefined; - } - for (const language of languages) { - const baseImage = yield getBaseImageByLanguage(language); - if (baseImage) { - return baseImage; - } - } - return undefined; - }); -} -function getBaseImageByLanguage(language) { - return __awaiter(this, void 0, void 0, function* () { - // eslint-disable-next-line no-undef - const rawData = yield fs_1.promises.readFile(path.join(__dirname, '..', 'language-image.json'), 'utf-8'); - const languageImageJSON = JSON.parse(rawData); - return languageImageJSON[language.name]; - }); -} -run().catch(core.setFailed);