mirror of
https://github.com/redhat-actions/buildah-build.git
synced 2025-04-20 09:01:23 +00:00
Remove out/, add badges
Signed-off-by: Tim Etchells <tetchell@redhat.com>
This commit is contained in:
parent
1196e988b8
commit
329be0a470
3 changed files with 7 additions and 218 deletions
12
README.md
12
README.md
|
@ -1,5 +1,9 @@
|
|||
# buildah-action
|
||||
|
||||
[](https://github.com/redhat-actions/buildah-action/tags)
|
||||
[](./LICENSE)
|
||||
[](./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.
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
108
out/src/index.js
108
out/src/index.js
|
@ -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);
|
Loading…
Reference in a new issue