Skip to content

Commit

Permalink
feat: multi-arch support
Browse files Browse the repository at this point in the history
Step up to the latest image builder, and adds support for the new
--target-arch parameter, which supports building arm64 and amd64
disk images.

Fixes containers#28.

Signed-off-by: Tim deBoer <git@tdeboer.ca>
  • Loading branch information
deboer-tim committed Feb 15, 2024
1 parent f3f2e3f commit cfbb1bd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/build-disk-image.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,17 @@ beforeEach(() => {
test('check image builder options', async () => {
const image = 'test-image';
const type = 'iso';
const arch = 'amd';
const name = 'my-image';
const outputFolder = '/output-folder';
const imagePath = '/output-folder/image-path';
const options = createBuilderImageOptions(name, image, type, outputFolder, imagePath);
const options = createBuilderImageOptions(name, image, type, arch, outputFolder, imagePath);

expect(options).toBeDefined();
expect(options.name).toEqual(name);
expect(options.Image).toEqual(bootcImageBuilderName);
expect(options.HostConfig.Binds[0]).toEqual(outputFolder + ':/output/');
expect(options.Cmd).toEqual([image, '--type', type, '--output', '/output/']);
expect(options.Cmd).toEqual([image, '--type', type, '--target-arch', arch, '--output', '/output/']);
});

test('check we pick unused container name', async () => {
Expand Down
21 changes: 20 additions & 1 deletion src/build-disk-image.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,23 @@ export async function buildDiskImage(imageData: unknown, history: History) {
const selectedType = selection.format;
telemetryData.imageType = selectedType;

const selectionArch = await extensionApi.window.showQuickPick(
[
{ label: 'ARM®', detail: 'ARM® 64 / aarch64 (arm64)', format: 'arm64' },
{ label: 'AMD64', detail: 'AMD 64 / x86-64 (amd64)', format: 'amd64' },
],
{
title: 'Select the architecture',
},
);
if (!selectionArch) {
telemetryData.canceled = true;
telemetryLogger.logUsage('buildDiskImage', telemetryData);
return;
}
const selectedArch = selectionArch.format;
telemetryData.arch = selectedArch;

const location = history.getLastLocation() || os.homedir();
const selectedFolder = await extensionApi.window.showInputBox({
prompt: 'Select the folder to generate disk' + selectedType + ' into',
Expand Down Expand Up @@ -135,6 +152,7 @@ export async function buildDiskImage(imageData: unknown, history: History) {
containerName,
image.name + ':' + image.tag,
selectedType,
selectedArch,
selectedFolder,
imagePath,
);
Expand Down Expand Up @@ -264,6 +282,7 @@ export function createBuilderImageOptions(
name: string,
image: string,
type: string,
arch: string,
folder: string,
imagePath: string,
): ContainerCreateOptions {
Expand All @@ -284,7 +303,7 @@ export function createBuilderImageOptions(
'bootc.build.image.location': imagePath,
'bootc.build.type': type,
},
Cmd: [image, '--type', type, '--output', '/output/'],
Cmd: [image, '--type', type, '--target-arch', arch, '--output', '/output/'],
};

return options;
Expand Down
2 changes: 1 addition & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@

// Image related
export const bootcImageBuilderContainerName = '-bootc-image-builder';
export const bootcImageBuilderName = 'quay.io/centos-bootc/bootc-image-builder:latest-1706124830';
export const bootcImageBuilderName = 'quay.io/centos-bootc/bootc-image-builder:latest-1708009307';

0 comments on commit cfbb1bd

Please sign in to comment.