CreateImageWizard: initialize on-prem with host arch

Initialize the create image wizard with the host arch for the
on-prem frontend.
This commit is contained in:
Gianluca Zuccarelli 2025-01-23 18:39:20 +00:00 committed by Sanne Raymaekers
parent 44af2f278b
commit 45b83bd4fb
4 changed files with 29 additions and 4 deletions

View file

@ -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.

View file

@ -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(
<SelectOption key={arch} value={arch}>
{arch}

View file

@ -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;
};

View file

@ -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';