Skip to content

Commit

Permalink
feat(binary-builder)!: support optional distro (#355)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: distro no longer falls back to `focal`
  • Loading branch information
viceice authored Oct 11, 2023
1 parent c04b24f commit 062cb0f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 15 deletions.
13 changes: 5 additions & 8 deletions src/commands/binary/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,12 @@ export async function createBuilderImage(
{ buildArgs }: BinaryBuilderConfig
): Promise<void> {
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]);
}
Expand Down
4 changes: 1 addition & 3 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean> {
try {
await which(command, true);
Expand Down Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions src/utils/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
}
2 changes: 1 addition & 1 deletion test/commands/binary/__snapshots__/utils.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions test/commands/binary/utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<BinaryBuilderConfig>({ buildArgs: ['FLAVOR=focal'] })
Expand Down
2 changes: 1 addition & 1 deletion test/util.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ describe('util', () => {
});

it('getDistro', () => {
expect(util.getDistro()).toBe('focal');
expect(util.getDistro()).toBe('');
});

it('getArch', () => {
Expand Down

0 comments on commit 062cb0f

Please sign in to comment.