mirror of
https://github.com/redhat-actions/buildah-build.git
synced 2025-04-20 09:01: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>
|
</td>
|
||||||
</tr>
|
</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>
|
<tr>
|
||||||
<td>context</td>
|
<td>context</td>
|
||||||
<td>No</td>
|
<td>No</td>
|
||||||
|
|
|
@ -40,6 +40,10 @@ inputs:
|
||||||
build-args:
|
build-args:
|
||||||
description: 'List of --build-args to pass to buildah.'
|
description: 'List of --build-args to pass to buildah.'
|
||||||
required: false
|
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:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'dist/index.js'
|
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";
|
import * as exec from "@actions/exec";
|
||||||
|
|
||||||
interface Buildah {
|
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>;
|
from(baseImage: string): Promise<CommandResult>;
|
||||||
copy(container: string, contentToCopy: string[]): Promise<CommandResult>;
|
copy(container: string, contentToCopy: string[]): Promise<CommandResult>;
|
||||||
config(container: string, setting: {}): 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 {
|
export interface BuildahConfigSettings {
|
||||||
|
@ -24,7 +24,11 @@ export class BuildahCli implements Buildah {
|
||||||
this.executable = executable;
|
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'];
|
const args: string[] = ['bud'];
|
||||||
dockerFiles.forEach(file => {
|
dockerFiles.forEach(file => {
|
||||||
args.push('-f');
|
args.push('-f');
|
||||||
|
@ -33,7 +37,8 @@ export class BuildahCli implements Buildah {
|
||||||
buildArgs.forEach((buildArg) => {
|
buildArgs.forEach((buildArg) => {
|
||||||
args.push('--build-arg');
|
args.push('--build-arg');
|
||||||
args.push(buildArg);
|
args.push(buildArg);
|
||||||
})
|
});
|
||||||
|
args.push(...this.getImageFormatOption(useOCI));
|
||||||
args.push('-t');
|
args.push('-t');
|
||||||
args.push(image);
|
args.push(image);
|
||||||
args.push(context);
|
args.push(context);
|
||||||
|
@ -82,11 +87,11 @@ export class BuildahCli implements Buildah {
|
||||||
return this.execute(args);
|
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('commit');
|
||||||
core.debug(container);
|
core.debug(container);
|
||||||
core.debug(newImageName);
|
core.debug(newImageName);
|
||||||
const args: string[] = ["commit", ...flags, container, newImageName];
|
const args: string[] = [ 'commit', ...this.getImageFormatOption(useOCI), '--squash', container, newImageName ];
|
||||||
return this.execute(args);
|
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');
|
let dockerFiles = getInputList('dockerfiles');
|
||||||
const newImage = `${core.getInput('image', { required: true })}:${core.getInput('tag', { required: true })}`;
|
const newImage = `${core.getInput('image', { required: true })}:${core.getInput('tag', { required: true })}`;
|
||||||
|
|
||||||
|
const useOCI = core.getInput("useOCI") === "true";
|
||||||
|
|
||||||
if (dockerFiles.length !== 0) {
|
if (dockerFiles.length !== 0) {
|
||||||
await doBuildUsingDockerFiles(cli, newImage, workspace, dockerFiles);
|
await doBuildUsingDockerFiles(cli, newImage, workspace, dockerFiles, useOCI);
|
||||||
} else {
|
} else {
|
||||||
await doBuildFromScratch(cli, newImage, workspace);
|
await doBuildFromScratch(cli, newImage, workspace, useOCI);
|
||||||
}
|
}
|
||||||
|
|
||||||
core.setOutput("image", newImage);
|
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) {
|
if (dockerFiles.length === 1) {
|
||||||
core.info(`Performing build from Dockerfile`);
|
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 context = path.join(workspace, core.getInput('context'));
|
||||||
const buildArgs = getInputList('build-args');
|
const buildArgs = getInputList('build-args');
|
||||||
dockerFiles = dockerFiles.map(file => path.join(workspace, file));
|
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`)
|
core.info(`Performing build from scratch`)
|
||||||
|
|
||||||
let baseImage = core.getInput('base-image');
|
let baseImage = core.getInput('base-image');
|
||||||
|
@ -79,7 +81,7 @@ async function doBuildFromScratch(cli: BuildahCli, newImage: string, workspace:
|
||||||
envs: envs
|
envs: envs
|
||||||
};
|
};
|
||||||
await cli.config(containerId, newImageConfig);
|
await cli.config(containerId, newImageConfig);
|
||||||
await cli.commit(containerId, newImage, ['--squash']);
|
await cli.commit(containerId, newImage, useOCI);
|
||||||
}
|
}
|
||||||
|
|
||||||
function getInputList(name: string): string[] {
|
function getInputList(name: string): string[] {
|
||||||
|
|
Loading…
Reference in a new issue