Merge pull request #116 from useblacksmith/bump-buildkitd

*: allow users to pass in a buildx version
This commit is contained in:
Aditya Maru 2025-05-30 13:07:26 -04:00 committed by GitHub
commit 68105fca60
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 23 additions and 3 deletions

2
dist/index.js generated vendored

File diff suppressed because one or more lines are too long

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -59,6 +59,7 @@ export interface Inputs {
'github-token': string;
nofallback: boolean;
setupOnly: boolean;
'buildx-version': string;
}
export async function getInputs(): Promise<Inputs> {
@ -98,6 +99,7 @@ export async function getInputs(): Promise<Inputs> {
'github-token': core.getInput('github-token'),
nofallback: core.getBooleanInput('nofallback'),
setupOnly: core.getBooleanInput('setup-only'),
'buildx-version': core.getInput('buildx-version')
};
}

View File

@ -23,7 +23,8 @@ import * as reporter from './reporter';
import {setupStickyDisk, startAndConfigureBuildkitd, getNumCPUs, leaveTailnet, pruneBuildkitCache} from './setup_builder';
import {Metric_MetricType} from '@buf/blacksmith_vm-agent.bufbuild_es/stickydisk/v1/stickydisk_pb';
const buildxVersion = 'v0.17.0';
const DEFAULT_BUILDX_VERSION = 'v0.23.0';
const mountPoint = '/var/lib/buildkit';
const execAsync = promisify(exec);
@ -73,6 +74,12 @@ async function setupBuildx(version: string, toolkit: Toolkit): Promise<void> {
});
}
// Validates the version string to ensure it matches a basic expected pattern.
// Accepts versions of the form `v<MAJOR>.<MINOR>.<PATCH>` (e.g., v0.20.0) or the literal string `latest`.
function isValidBuildxVersion(version: string): boolean {
return version === 'latest' || /^v\d+\.\d+\.\d+$/.test(version);
}
/**
* Attempts to set up a Blacksmith builder for Docker builds.
*
@ -159,6 +166,17 @@ actionsToolkit.run(
}
});
// Determine which Buildx version to install. If the user provided an input, validate it;
// otherwise, fall back to the default.
let buildxVersion = DEFAULT_BUILDX_VERSION;
if (inputs['buildx-version'] && inputs['buildx-version'].trim() !== '') {
if (isValidBuildxVersion(inputs['buildx-version'])) {
buildxVersion = inputs['buildx-version'];
} else {
core.warning(`Invalid buildx-version '${inputs['buildx-version']}'. ` + `Expected 'latest' or a version in the form v<MAJOR>.<MINOR>.<PATCH>. ` + `Falling back to default ${DEFAULT_BUILDX_VERSION}.`);
}
}
await core.group(`Setup buildx`, async () => {
await setupBuildx(buildxVersion, toolkit);