From 73958b53e8a3d573b5bb63efe4aee0371bb3c384 Mon Sep 17 00:00:00 2001 From: Florent BENOIT Date: Fri, 12 Jan 2024 11:27:21 -0500 Subject: [PATCH] feat: add a way to choose platform when building image (#5503) * feat: add a way to choose platform when building image fixes https://github.com/containers/podman-desktop/issues/5492 Signed-off-by: Florent Benoit --- .../image/BuildImageFromContainerfile.spec.ts | 1 + .../image/BuildImageFromContainerfile.svelte | 6 + .../BuildImageFromContainerfileCard.spec.ts | 109 +++++++++++ .../BuildImageFromContainerfileCard.svelte | 113 +++++++++++ .../BuildImageFromContainerfileCards.spec.ts | 65 +++++++ .../BuildImageFromContainerfileCards.svelte | 182 ++++++++++++++++++ 6 files changed, 476 insertions(+) create mode 100644 packages/renderer/src/lib/image/BuildImageFromContainerfileCard.spec.ts create mode 100644 packages/renderer/src/lib/image/BuildImageFromContainerfileCard.svelte create mode 100644 packages/renderer/src/lib/image/BuildImageFromContainerfileCards.spec.ts create mode 100644 packages/renderer/src/lib/image/BuildImageFromContainerfileCards.svelte diff --git a/packages/renderer/src/lib/image/BuildImageFromContainerfile.spec.ts b/packages/renderer/src/lib/image/BuildImageFromContainerfile.spec.ts index 7758c19941578..c1722ca50dbf7 100644 --- a/packages/renderer/src/lib/image/BuildImageFromContainerfile.spec.ts +++ b/packages/renderer/src/lib/image/BuildImageFromContainerfile.spec.ts @@ -42,6 +42,7 @@ beforeAll(() => { }); (window as any).openFileDialog = vi.fn().mockResolvedValue({ canceled: false, filePaths: ['Containerfile'] }); (window as any).telemetryPage = vi.fn().mockResolvedValue(undefined); + (window as any).getOsArch = vi.fn(); }); // the build image page expects to have a valid provider connection, so let's mock one diff --git a/packages/renderer/src/lib/image/BuildImageFromContainerfile.svelte b/packages/renderer/src/lib/image/BuildImageFromContainerfile.svelte index a6c459ecce6f5..7a2e01bbc615c 100644 --- a/packages/renderer/src/lib/image/BuildImageFromContainerfile.svelte +++ b/packages/renderer/src/lib/image/BuildImageFromContainerfile.svelte @@ -22,6 +22,7 @@ import TerminalWindow from '../ui/TerminalWindow.svelte'; import type { Terminal } from 'xterm'; import Button from '../ui/Button.svelte'; import { faCube } from '@fortawesome/free-solid-svg-icons'; +import BuildImageFromContainerfileCards from './BuildImageFromContainerfileCards.svelte'; let buildFinished = false; let containerImageName = 'my-custom-image'; @@ -216,6 +217,11 @@ async function abortBuild() { {/if} + +
{#if !buildImageInfo?.buildRunning} diff --git a/packages/renderer/src/lib/image/BuildImageFromContainerfileCards.spec.ts b/packages/renderer/src/lib/image/BuildImageFromContainerfileCards.spec.ts new file mode 100644 index 0000000000000..7af4d92fcd2c6 --- /dev/null +++ b/packages/renderer/src/lib/image/BuildImageFromContainerfileCards.spec.ts @@ -0,0 +1,65 @@ +/********************************************************************** + * Copyright (C) 2024 Red Hat, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + ***********************************************************************/ + +/* eslint-disable @typescript-eslint/no-explicit-any */ + +import '@testing-library/jest-dom/vitest'; +import { test, expect, beforeAll, vi } from 'vitest'; +import { render } from '@testing-library/svelte'; +import BuildImageFromContainerfileCards from './BuildImageFromContainerfileCards.svelte'; + +// fake the window.events object +beforeAll(() => { + (window.events as unknown) = { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + receive: (_channel: string, func: any) => { + func(); + }, + }; + (window as any).getOsArch = vi.fn(); +}); + +test('check default on arm64', async () => { + vi.mocked(window.getOsArch).mockResolvedValue('arm64'); + + const platforms = ''; + const rendered = render(BuildImageFromContainerfileCards, { + platforms, + }); + + // wait a little with setTimeout + await new Promise(resolve => setTimeout(resolve, 100)); + + // check we have a platform + expect(rendered.component.$$.ctx[5]).toEqual('linux/arm64'); +}); + +test('check default on amd64', async () => { + vi.mocked(window.getOsArch).mockResolvedValue('x64'); + + const platforms = ''; + const rendered = render(BuildImageFromContainerfileCards, { + platforms, + }); + + // wait a little with setTimeout + await new Promise(resolve => setTimeout(resolve, 100)); + + // check we have a platform + expect(rendered.component.$$.ctx[5]).toEqual('linux/amd64'); +}); diff --git a/packages/renderer/src/lib/image/BuildImageFromContainerfileCards.svelte b/packages/renderer/src/lib/image/BuildImageFromContainerfileCards.svelte new file mode 100644 index 0000000000000..af0e65f783e6c --- /dev/null +++ b/packages/renderer/src/lib/image/BuildImageFromContainerfileCards.svelte @@ -0,0 +1,182 @@ + + +
+
+ {#each sortedCards as card} + + {/each} +
+ + {#if !showMoreOptions} + + {:else} +
+
+ {#each advancedCards as card} + + {/each} + +
+
+ + {/if} +