Skip to content

Commit 4730e77

Browse files
Extract out common code, remove hardcoded arch
1 parent bd21d63 commit 4730e77

File tree

4 files changed

+30
-25
lines changed

4 files changed

+30
-25
lines changed

ZelBack/src/services/appLifecycle/appInstaller.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const upnpService = require('../upnpService');
2828
const globalState = require('../utils/globalState');
2929
const { checkAndDecryptAppSpecs } = require('../utils/enterpriseHelper');
3030
const { specificationFormatter } = require('../utils/appSpecHelpers');
31+
const { findCommonArchitectures } = require('../utils/appUtilities');
3132
const log = require('../../lib/log');
3233
const { appsFolder, localAppsInformation, scannedHeightCollection } = require('../utils/appConstants');
3334
const { checkAppTemporaryMessageExistence, checkAppMessageExistence } = require('../appMessaging/messageVerifier');
@@ -1102,15 +1103,6 @@ async function testAppInstall(req, res) {
11021103
}
11031104

11041105
// Calculate common architectures across all components
1105-
const findCommonArchitectures = (compArchs) => {
1106-
if (compArchs.length === 0) return [];
1107-
if (compArchs.length === 1) return compArchs[0].architectures;
1108-
1109-
return compArchs[0].architectures.filter((arch) =>
1110-
compArchs.every((comp) => comp.architectures.includes(arch)),
1111-
);
1112-
};
1113-
11141106
const commonArchitectures = findCommonArchitectures(componentArchitectures);
11151107

11161108
// If local architecture is not in common architectures, skip Docker operations

ZelBack/src/services/appRequirements/appValidator.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const imageManager = require('../appSecurity/imageManager');
1212
// const advancedWorkflows = require('../appLifecycle/advancedWorkflows'); // Moved to dynamic require to avoid circular dependency
1313
// eslint-disable-next-line no-unused-vars
1414
const { supportedArchitectures, enterpriseRequiredArchitectures } = require('../utils/appConstants');
15-
const { specificationFormatter } = require('../utils/appUtilities');
15+
const { specificationFormatter, findCommonArchitectures } = require('../utils/appUtilities');
1616
const { checkAndDecryptAppSpecs } = require('../utils/enterpriseHelper');
1717
const portManager = require('../appNetwork/portManager');
1818
const {
@@ -1285,30 +1285,21 @@ async function verifyAppSpecifications(appSpecifications, height, checkDockerAnd
12851285
const isEnterpriseArcane = appSpecifications.version >= 8 && appSpecifications.enterprise;
12861286

12871287
if (isEnterpriseArcane) {
1288-
// Enterprise Arcane apps (v8+) must support amd64 on ALL components (Arcane nodes are amd64-only)
1289-
const componentsWithoutAmd64 = componentArchitectures.filter(
1290-
(comp) => !comp.architectures.includes('amd64'),
1288+
// Enterprise Arcane apps (v8+) must support required architectures on ALL components (Arcane nodes are amd64-only)
1289+
const componentsWithoutRequiredArchs = componentArchitectures.filter(
1290+
(comp) => !enterpriseRequiredArchitectures.every((arch) => comp.architectures.includes(arch)),
12911291
);
12921292

1293-
if (componentsWithoutAmd64.length > 0) {
1294-
const componentNames = componentsWithoutAmd64.map((c) => `${c.name} (${c.repotag})`).join(', ');
1293+
if (componentsWithoutRequiredArchs.length > 0) {
1294+
const componentNames = componentsWithoutRequiredArchs.map((c) => `${c.name} (${c.repotag})`).join(', ');
12951295
throw new Error(
12961296
`Enterprise application '${appSpecifications.name}' must support ${enterpriseRequiredArchitectures.join(', ')} `
1297-
+ `architecture on ALL components. The following components do not support amd64: ${componentNames}. `
1297+
+ `architecture on ALL components. The following components do not support ${enterpriseRequiredArchitectures.join(', ')}: ${componentNames}. `
12981298
+ `Arcane nodes are amd64-only.`,
12991299
);
13001300
}
13011301
} else {
13021302
// Non-enterprise apps: must have at least ONE common architecture across all components
1303-
const findCommonArchitectures = (compArchs) => {
1304-
if (compArchs.length === 0) return [];
1305-
if (compArchs.length === 1) return compArchs[0].architectures;
1306-
1307-
return compArchs[0].architectures.filter((arch) =>
1308-
compArchs.every((comp) => comp.architectures.includes(arch)),
1309-
);
1310-
};
1311-
13121303
const commonArchitectures = findCommonArchitectures(componentArchitectures);
13131304

13141305
if (commonArchitectures.length === 0) {

ZelBack/src/services/utils/appUtilities.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,6 +1052,20 @@ function updateToLatestAppSpecifications(appSpec) {
10521052
throw new Error('Original application version not recognized');
10531053
}
10541054

1055+
/**
1056+
* Find common architectures across all app components
1057+
* @param {Array<{name: string, architectures: string[]}>} componentArchitectures - Array of component architecture info
1058+
* @returns {string[]} Array of architecture strings common to all components
1059+
*/
1060+
function findCommonArchitectures(componentArchitectures) {
1061+
if (componentArchitectures.length === 0) return [];
1062+
if (componentArchitectures.length === 1) return componentArchitectures[0].architectures;
1063+
1064+
return componentArchitectures[0].architectures.filter((arch) =>
1065+
componentArchitectures.every((comp) => comp.architectures.includes(arch)),
1066+
);
1067+
}
1068+
10551069
module.exports = {
10561070
appPricePerMonth,
10571071
nodeFullGeolocation,
@@ -1060,4 +1074,5 @@ module.exports = {
10601074
getAppPorts,
10611075
specificationFormatter,
10621076
updateToLatestAppSpecifications,
1077+
findCommonArchitectures,
10631078
};

tests/unit/appValidator.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,13 @@ describe('appValidator tests', () => {
103103
},
104104
'../utils/appUtilities': {
105105
specificationFormatter: sinon.stub().returnsArg(0),
106+
findCommonArchitectures: (componentArchitectures) => {
107+
if (componentArchitectures.length === 0) return [];
108+
if (componentArchitectures.length === 1) return componentArchitectures[0].architectures;
109+
return componentArchitectures[0].architectures.filter((arch) =>
110+
componentArchitectures.every((comp) => comp.architectures.includes(arch)),
111+
);
112+
},
106113
},
107114
'../utils/enterpriseHelper': {
108115
checkAndDecryptAppSpecs: sinon.stub().returnsArg(0),

0 commit comments

Comments
 (0)