From 45b83bd4fb4392d1c816a42f5c12cdca7df0994e Mon Sep 17 00:00:00 2001 From: Gianluca Zuccarelli Date: Thu, 23 Jan 2025 18:39:20 +0000 Subject: [PATCH] CreateImageWizard: initialize on-prem with host arch Initialize the create image wizard with the host arch for the on-prem frontend. --- .../CreateImageWizard/CreateImageWizard.tsx | 9 ++++++++- .../steps/ImageOutput/ArchSelect.tsx | 12 ++++++++++-- .../CreateImageWizard/utilities/getHostInfo.ts | 10 ++++++++++ src/constants.ts | 2 +- 4 files changed, 29 insertions(+), 4 deletions(-) diff --git a/src/Components/CreateImageWizard/CreateImageWizard.tsx b/src/Components/CreateImageWizard/CreateImageWizard.tsx index cc8ca720..ceb80b97 100644 --- a/src/Components/CreateImageWizard/CreateImageWizard.tsx +++ b/src/Components/CreateImageWizard/CreateImageWizard.tsx @@ -34,7 +34,7 @@ import Azure from './steps/TargetEnvironment/Azure'; import Gcp from './steps/TargetEnvironment/Gcp'; import TimezoneStep from './steps/Timezone'; import UsersStep from './steps/Users'; -import { getHostDistro } from './utilities/getHostInfo'; +import { getHostArch, getHostDistro } from './utilities/getHostInfo'; import { useFilesystemValidation, useSnapshotValidation, @@ -199,10 +199,17 @@ const CreateImageWizard = ({ isEdit }: CreateImageWizardProps) => { dispatch(changeDistribution(distro)); }; + const initializeHostArch = async () => { + const arch = await getHostArch(); + dispatch(changeArchitecture(arch)); + }; + if (process.env.IS_ON_PREMISE) { if (!searchParams.get('release')) { initializeHostDistro(); } + + initializeHostArch(); } // This useEffect hook should run *only* on mount and therefore has an empty // dependency array. eslint's exhaustive-deps rule does not support this use. diff --git a/src/Components/CreateImageWizard/steps/ImageOutput/ArchSelect.tsx b/src/Components/CreateImageWizard/steps/ImageOutput/ArchSelect.tsx index 3e8669eb..32fe90c7 100644 --- a/src/Components/CreateImageWizard/steps/ImageOutput/ArchSelect.tsx +++ b/src/Components/CreateImageWizard/steps/ImageOutput/ArchSelect.tsx @@ -7,7 +7,7 @@ import { SelectVariant, } from '@patternfly/react-core/deprecated'; -import { ARCHS } from '../../../../constants'; +import { ARCHES } from '../../../../constants'; import { useAppDispatch, useAppSelector } from '../../../../store/hooks'; import { ImageRequest } from '../../../../store/imageBuilderApi'; import { @@ -30,7 +30,15 @@ const ArchSelect = () => { const setSelectOptions = () => { const options: ReactElement[] = []; - ARCHS.forEach((arch) => { + const arches = ARCHES.filter((a) => { + // we don't want to support cross-arch + // builds for on-prem for now + if (process.env.IS_ON_PREMISE) { + return a === arch; + } + return true; + }); + arches.forEach((arch) => { options.push( {arch} diff --git a/src/Components/CreateImageWizard/utilities/getHostInfo.ts b/src/Components/CreateImageWizard/utilities/getHostInfo.ts index ced5886a..beff5a85 100644 --- a/src/Components/CreateImageWizard/utilities/getHostInfo.ts +++ b/src/Components/CreateImageWizard/utilities/getHostInfo.ts @@ -1,3 +1,4 @@ +import cockpit from 'cockpit'; import { read_os_release } from 'os-release'; import { Distributions } from '../../../store/imageBuilderApi'; @@ -6,3 +7,12 @@ export const getHostDistro = async () => { const osRel = await read_os_release(); return `${osRel.ID}-${osRel.VERSION_ID}` as Distributions; }; + +type Architecture = 'x86_64' | 'aarch64'; +export const getHostArch = async () => { + const hostArch = await cockpit.spawn(['uname', '-m'], { + superuser: 'try', + }); + + return (hostArch as string).trim() as Architecture; +}; diff --git a/src/constants.ts b/src/constants.ts index 36bdb140..af41711c 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -106,7 +106,7 @@ export const RHEL_8_FULL_SUPPORT = ['2019-05-07', '2024-05-31']; export const RHEL_9_MAINTENANCE_SUPPORT = ['2027-05-31', '2032-05-31']; export const RHEL_8_MAINTENANCE_SUPPORT = ['2024-05-31', '2029-05-31']; -export const ARCHS = [X86_64, AARCH64]; +export const ARCHES = [X86_64, AARCH64]; export const DEFAULT_AWS_REGION = 'us-east-1';