Skip to content

Commit

Permalink
fix: add optional param with builder image
Browse files Browse the repository at this point in the history
When renovate creates lots of PRs docker buildx is rate limited
because it tries to pull its image from Docker Hub.
This commit allows us to configure our own image from ECR.
  • Loading branch information
arminioa committed Nov 4, 2024
1 parent 846f08f commit a17f344
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 13 deletions.
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

0 comments on commit a17f344

Please sign in to comment.