mirror of
https://github.com/docker/build-push-action.git
synced 2025-08-19 20:01:04 +00:00
fix: use correct platform when creating remote buildx builder
The remote builder was hardcoded to use --platform linux/amd64 regardless of user input or runner architecture. This caused performance issues on ARM runners and cache inefficiencies. Now properly uses the platforms input or detects host architecture to avoid unnecessary QEMU emulation and improve build performance. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
6fe3b1c366
commit
a7fa33c366
8 changed files with 594 additions and 488 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as handlebars from 'handlebars';
|
||||
import * as fs from 'fs';
|
||||
import * as os from 'os';
|
||||
|
||||
import {Build} from '@docker/actions-toolkit/lib/buildx/build';
|
||||
import {Context} from '@docker/actions-toolkit/lib/context';
|
||||
|
|
@ -336,12 +336,39 @@ export const tlsClientKeyPath = '/tmp/blacksmith_client_key.pem';
|
|||
export const tlsClientCaCertificatePath = '/tmp/blacksmith_client_ca_certificate.pem';
|
||||
export const tlsRootCaCertificatePath = '/tmp/blacksmith_root_ca_certificate.pem';
|
||||
|
||||
export async function getRemoteBuilderArgs(name: string, builderUrl: string): Promise<Array<string>> {
|
||||
/**
|
||||
* Resolve the platform list that should be passed to `docker buildx create`.
|
||||
*
|
||||
* Priority:
|
||||
* 1. Use the user-supplied platforms list (comma-joined) if provided.
|
||||
* 2. Fallback to the architecture of the host runner.
|
||||
*
|
||||
* The function is exported to allow isolated unit testing.
|
||||
*/
|
||||
export function resolveRemoteBuilderPlatforms(platforms?: string[]): string {
|
||||
// If user explicitly provided platforms, honour them verbatim.
|
||||
if (platforms && platforms.length > 0) {
|
||||
return platforms.join(',');
|
||||
}
|
||||
|
||||
// Otherwise derive from host architecture.
|
||||
const nodeArch = os.arch(); // e.g. 'x64', 'arm64', 'arm'
|
||||
const archMap: {[key: string]: string} = {
|
||||
x64: 'amd64',
|
||||
arm64: 'arm64',
|
||||
arm: 'arm'
|
||||
};
|
||||
const mappedArch = archMap[nodeArch] || nodeArch;
|
||||
return `linux/${mappedArch}`;
|
||||
}
|
||||
|
||||
export async function getRemoteBuilderArgs(name: string, builderUrl: string, platforms?: string[]): Promise<Array<string>> {
|
||||
const args: Array<string> = ['create', '--name', name, '--driver', 'remote'];
|
||||
|
||||
// TODO(aayush): Instead of hardcoding the platform, we should fail the build if the platform is
|
||||
// unsupported.
|
||||
args.push('--platform', 'linux/amd64');
|
||||
const platformFlag = resolveRemoteBuilderPlatforms(platforms);
|
||||
core.info(`Determined remote builder platform(s): ${platformFlag}`);
|
||||
args.push('--platform', platformFlag);
|
||||
|
||||
// Always use the remote builder, overriding whatever has been configured so far.
|
||||
args.push('--use');
|
||||
// Use the provided builder URL
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue