Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add optional param with builder image #617

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ inputs:
builder:
required: false
description: buildx builder to use
builder-image:
required: false
description: buildx image to use
context:
required: false
description: docker context
Expand Down
16 changes: 10 additions & 6 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

18 changes: 13 additions & 5 deletions src/buildx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import {debug, endGroup, info, startGroup, warning} from '@actions/core';
import {HttpClient} from '@actions/http-client';
import {exec, getExecOutput} from '@actions/exec';

export async function setup(builderName: string): Promise<void> {
export async function setup(
builderName: string,
builderImage: string
): Promise<void> {
if (!(await isAvailable())) {
await install();
}
Expand All @@ -22,7 +25,7 @@ export async function setup(builderName: string): Promise<void> {
if (!builderName) {
builderName = `builder-${uuid.v4()}`;
state.setBuilder(builderName);
await createBuilder(builderName);
await createBuilder(builderName, builderImage);
await bootBuilder(builderName);
}
outputs.setBuilder(builderName);
Expand All @@ -44,7 +47,7 @@ export async function stop(builderName: string): Promise<void> {
endGroup();
}

async function createBuilder(name: string): Promise<void> {
async function createBuilder(name: string, image: string): Promise<void> {
startGroup(`🔨 Creating a new builder instance`);

const context = 'builders';
Expand All @@ -56,9 +59,14 @@ async function createBuilder(name: string): Promise<void> {
'--name',
name,
'--driver',
'docker-container',
context
'docker-container'
];

if (image) {
args.push('--driver-opt', `image=${image}`);
}

args.push(context);
await exec('docker', args);

endGroup();
Expand Down
2 changes: 2 additions & 0 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {getInput, getMultilineInput} from '@actions/core';
export interface Inputs {
buildArgs: string[];
builder: string;
builderImage: string;
context: string;
file: string;
labels: string[];
Expand Down Expand Up @@ -36,6 +37,7 @@ export async function getInputs(): Promise<Inputs> {
const inputs: Inputs = {
buildArgs: await getInputList('build-args'),
builder: getInput('builder'),
builderImage: getInput('builder-image'),
context: getInput('context'),
file: getInput('file'),
labels: await getInputList('labels'),
Expand Down
2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ async function run(): Promise<void> {
}

await cache.restore(inputs);
await buildx.setup(inputs.builder);
await buildx.setup(inputs.builder, inputs.builderImage);
const tag = await docker.build(inputs);
if (inputs.push) {
await buildx.inspect(tag);
Expand Down