diff --git a/src/commands/binary/utils.ts b/src/commands/binary/utils.ts index e373df3e5..1fdb2c99b 100644 --- a/src/commands/binary/utils.ts +++ b/src/commands/binary/utils.ts @@ -45,15 +45,12 @@ export async function createBuilderImage( { buildArgs }: BinaryBuilderConfig ): Promise { log('Creating builder image'); - const args = [ - 'build', - '--load', - '-t', - 'builder', - '--build-arg', - `DISTRO=${getDistro()}`, - ]; + const args = ['build', '--load', '-t', 'builder']; + const distro = getDistro(); const arch = getArch(); + if (is.nonEmptyString(distro)) { + args.push('--build-arg', `DISTRO=${distro}`); + } if (is.nonEmptyString(arch)) { args.push('--platform', DockerPlatform[arch]); } diff --git a/src/util.ts b/src/util.ts index 5bbbf53e3..b428ab95f 100644 --- a/src/util.ts +++ b/src/util.ts @@ -11,8 +11,6 @@ import * as findUp from 'find-up'; export type ExecOptions = _ExecOptions; -const DEFAULT_DISTRO = 'focal'; - export async function exists(command: string): Promise { try { await which(command, true); @@ -79,7 +77,7 @@ export function getWorkspace(): string { } export function getDistro(): string { - return getEnv('DISTRO') || getEnv('FLAVOR') || DEFAULT_DISTRO; + return getEnv('DISTRO') || getEnv('FLAVOR'); } export function getArch(): DockerArch { diff --git a/src/utils/config.ts b/src/utils/config.ts index 85bc9b7c9..c9ad13eb6 100644 --- a/src/utils/config.ts +++ b/src/utils/config.ts @@ -42,10 +42,15 @@ export function getBinaryName( version: string, sum?: boolean | undefined ): string { + const distro = getDistro(); const arch = getArch(); const ext = sum ? `.${sumType}` : ''; + let image = `${cfg.image}-${version}`; + if (is.nonEmptyString(distro)) { + image += `-${distro}`; + } if (is.nonEmptyString(arch)) { - return `${cfg.image}-${version}-${getDistro()}-${arch}.tar.xz${ext}`; + image += `-${arch}`; } - return `${cfg.image}-${version}-${getDistro()}.tar.xz${ext}`; + return `${image}.tar.xz${ext}`; } diff --git a/test/commands/binary/__snapshots__/utils.spec.ts.snap b/test/commands/binary/__snapshots__/utils.spec.ts.snap index 17581a1f5..a29ecc59e 100644 --- a/test/commands/binary/__snapshots__/utils.spec.ts.snap +++ b/test/commands/binary/__snapshots__/utils.spec.ts.snap @@ -8,7 +8,7 @@ exports[`commands/binary/utils createBuilderImage works with build args 1`] = ` "-t", "builder", "--build-arg", - "DISTRO=undefined", + "DISTRO=focal", "--platform", "linux/arm64", "--build-arg=FLAVOR=focal", diff --git a/test/commands/binary/utils.spec.ts b/test/commands/binary/utils.spec.ts index 348376495..1c4501659 100644 --- a/test/commands/binary/utils.spec.ts +++ b/test/commands/binary/utils.spec.ts @@ -64,6 +64,7 @@ describe('commands/binary/utils', () => { it('works with build args', async () => { utils.getArch.mockReturnValueOnce('aarch64'); + utils.getDistro.mockReturnValueOnce('focal'); await createBuilderImage( '', partial({ buildArgs: ['FLAVOR=focal'] }) diff --git a/test/util.spec.ts b/test/util.spec.ts index 7da09fc8f..2bcdf4456 100644 --- a/test/util.spec.ts +++ b/test/util.spec.ts @@ -100,7 +100,7 @@ describe('util', () => { }); it('getDistro', () => { - expect(util.getDistro()).toBe('focal'); + expect(util.getDistro()).toBe(''); }); it('getArch', () => {