mirror of
https://github.com/redhat-actions/buildah-build.git
synced 2025-04-19 16:51:23 +00:00
Default to docker image format
Signed-off-by: Tim Etchells <tetchell@redhat.com>
This commit is contained in:
parent
a65863e0db
commit
59d340ffaf
6 changed files with 34 additions and 14 deletions
|
@ -49,6 +49,15 @@ After building your image, use [push-to-registry](https://github.com/redhat-acti
|
|||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>oci</td>
|
||||
<td>No</td>
|
||||
<td>
|
||||
Build the image using the OCI format, instead of the Docker format.<br>
|
||||
By default, this is <code>false</code>, because images built using the OCI format have <a href="https://github.com/docker/hub-feedback/issues/1871">issues</a> when published to Dockerhub.
|
||||
</td>
|
||||
</tr>
|
||||
|
||||
<tr>
|
||||
<td>context</td>
|
||||
<td>No</td>
|
||||
|
|
|
@ -40,6 +40,10 @@ inputs:
|
|||
build-args:
|
||||
description: 'List of --build-args to pass to buildah.'
|
||||
required: false
|
||||
oci:
|
||||
description: 'Set to true to build using the OCI image format instead of the Docker image format.'
|
||||
default: 'false'
|
||||
required: false
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'dist/index.js'
|
||||
|
|
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
|
@ -2,11 +2,11 @@ import * as core from "@actions/core";
|
|||
import * as exec from "@actions/exec";
|
||||
|
||||
interface Buildah {
|
||||
buildUsingDocker(image: string, context: string, dockerFiles: string[], buildArgs: string[]): Promise<CommandResult>;
|
||||
buildUsingDocker(image: string, context: string, dockerFiles: string[], buildArgs: string[], useOCI: boolean): Promise<CommandResult>;
|
||||
from(baseImage: string): Promise<CommandResult>;
|
||||
copy(container: string, contentToCopy: string[]): Promise<CommandResult>;
|
||||
config(container: string, setting: {}): Promise<CommandResult>;
|
||||
commit(container: string, newImageName: string, flags?: string[]): Promise<CommandResult>;
|
||||
commit(container: string, newImageName: string, useOCI: boolean): Promise<CommandResult>;
|
||||
}
|
||||
|
||||
export interface BuildahConfigSettings {
|
||||
|
@ -24,7 +24,11 @@ export class BuildahCli implements Buildah {
|
|||
this.executable = executable;
|
||||
}
|
||||
|
||||
async buildUsingDocker(image: string, context: string, dockerFiles: string[], buildArgs: string[]): Promise<CommandResult> {
|
||||
private getImageFormatOption(useOCI: boolean): string[] {
|
||||
return [ '--format', useOCI ? 'oci' : 'docker' ];
|
||||
}
|
||||
|
||||
async buildUsingDocker(image: string, context: string, dockerFiles: string[], buildArgs: string[], useOCI: boolean): Promise<CommandResult> {
|
||||
const args: string[] = ['bud'];
|
||||
dockerFiles.forEach(file => {
|
||||
args.push('-f');
|
||||
|
@ -33,7 +37,8 @@ export class BuildahCli implements Buildah {
|
|||
buildArgs.forEach((buildArg) => {
|
||||
args.push('--build-arg');
|
||||
args.push(buildArg);
|
||||
})
|
||||
});
|
||||
args.push(...this.getImageFormatOption(useOCI));
|
||||
args.push('-t');
|
||||
args.push(image);
|
||||
args.push(context);
|
||||
|
@ -82,11 +87,11 @@ export class BuildahCli implements Buildah {
|
|||
return this.execute(args);
|
||||
}
|
||||
|
||||
async commit(container: string, newImageName: string, flags: string[] = []): Promise<CommandResult> {
|
||||
async commit(container: string, newImageName: string, useOCI: boolean): Promise<CommandResult> {
|
||||
core.debug('commit');
|
||||
core.debug(container);
|
||||
core.debug(newImageName);
|
||||
const args: string[] = ["commit", ...flags, container, newImageName];
|
||||
const args: string[] = [ 'commit', ...this.getImageFormatOption(useOCI), '--squash', container, newImageName ];
|
||||
return this.execute(args);
|
||||
}
|
||||
|
||||
|
|
14
src/index.ts
14
src/index.ts
|
@ -20,16 +20,18 @@ export async function run(): Promise<void> {
|
|||
let dockerFiles = getInputList('dockerfiles');
|
||||
const newImage = `${core.getInput('image', { required: true })}:${core.getInput('tag', { required: true })}`;
|
||||
|
||||
const useOCI = core.getInput("useOCI") === "true";
|
||||
|
||||
if (dockerFiles.length !== 0) {
|
||||
await doBuildUsingDockerFiles(cli, newImage, workspace, dockerFiles);
|
||||
await doBuildUsingDockerFiles(cli, newImage, workspace, dockerFiles, useOCI);
|
||||
} else {
|
||||
await doBuildFromScratch(cli, newImage, workspace);
|
||||
await doBuildFromScratch(cli, newImage, workspace, useOCI);
|
||||
}
|
||||
|
||||
core.setOutput("image", newImage);
|
||||
}
|
||||
|
||||
async function doBuildUsingDockerFiles(cli: BuildahCli, newImage: string, workspace: string, dockerFiles: string[]): Promise<void> {
|
||||
async function doBuildUsingDockerFiles(cli: BuildahCli, newImage: string, workspace: string, dockerFiles: string[], useOCI: boolean): Promise<void> {
|
||||
if (dockerFiles.length === 1) {
|
||||
core.info(`Performing build from Dockerfile`);
|
||||
}
|
||||
|
@ -40,10 +42,10 @@ async function doBuildUsingDockerFiles(cli: BuildahCli, newImage: string, worksp
|
|||
const context = path.join(workspace, core.getInput('context'));
|
||||
const buildArgs = getInputList('build-args');
|
||||
dockerFiles = dockerFiles.map(file => path.join(workspace, file));
|
||||
await cli.buildUsingDocker(newImage, context, dockerFiles, buildArgs);
|
||||
await cli.buildUsingDocker(newImage, context, dockerFiles, buildArgs, useOCI);
|
||||
}
|
||||
|
||||
async function doBuildFromScratch(cli: BuildahCli, newImage: string, workspace: string): Promise<void> {
|
||||
async function doBuildFromScratch(cli: BuildahCli, newImage: string, workspace: string, useOCI: boolean): Promise<void> {
|
||||
core.info(`Performing build from scratch`)
|
||||
|
||||
let baseImage = core.getInput('base-image');
|
||||
|
@ -79,7 +81,7 @@ async function doBuildFromScratch(cli: BuildahCli, newImage: string, workspace:
|
|||
envs: envs
|
||||
};
|
||||
await cli.config(containerId, newImageConfig);
|
||||
await cli.commit(containerId, newImage, ['--squash']);
|
||||
await cli.commit(containerId, newImage, useOCI);
|
||||
}
|
||||
|
||||
function getInputList(name: string): string[] {
|
||||
|
|
Loading…
Reference in a new issue