mirror of
https://gitlab.com/openstapps/openstapps.git
synced 2026-01-20 00:23:03 +00:00
fix: handle patch & duplicate versions correctly
This commit is contained in:
31
src/main.ts
31
src/main.ts
@@ -17,6 +17,7 @@ import {Logger} from '@openstapps/logger';
|
||||
import Dockerode from 'dockerode';
|
||||
import {render} from 'mustache';
|
||||
import {join} from 'path';
|
||||
import * as semver from 'semver';
|
||||
import {
|
||||
asyncReadFile,
|
||||
configFile,
|
||||
@@ -86,26 +87,36 @@ export async function generateUpstreamMap(
|
||||
.map(async (activeVersionRegex) => {
|
||||
const upstreamName = activeVersionRegex.replace(/[\\|.+]/g, '_');
|
||||
|
||||
const activeBackends = containers.filter((container) => {
|
||||
let activeBackends = containers.filter((container) => {
|
||||
return containerMatchesRegex('backend', new RegExp(activeVersionRegex), container);
|
||||
});
|
||||
|
||||
// .Labels['stapps.version'] is available
|
||||
if (activeBackends.length > 0) {
|
||||
foundMatchingContainer = true;
|
||||
|
||||
if (activeBackends.length > 1) {
|
||||
throw new Error('Multiple backends for one version found.');
|
||||
activeBackends = activeBackends.sort((a, b) => semver.rcompare(a.Labels['stapps.version'],b.Labels['stapps.version']));
|
||||
const activeBackendsVersions = activeBackends.map((container) => container.Labels['stapps.version'])
|
||||
// tslint:disable-next-line: strict-boolean-expressions
|
||||
.reduce((map, e) => map.set(e, (map.get(e) || 0) + 1), new Map<string, number>());
|
||||
for (const [version, occurrences] of activeBackendsVersions) {
|
||||
if (occurrences > 1) {
|
||||
await Logger.error(`Omitting running version ${version} ! Multiple backends with this exact version are running`);
|
||||
activeBackends = activeBackends.filter((container) => container.Labels['stapps.version'] !== version);
|
||||
}
|
||||
}
|
||||
|
||||
const gateWayOfContainer = await getGatewayOfStAppsBackend(activeBackends[0]);
|
||||
if (activeBackends.length !== 0) {
|
||||
// not only dublicates
|
||||
foundMatchingContainer = true;
|
||||
|
||||
if (gateWayOfContainer.length !== 0) {
|
||||
upstreams += `\nupstream ${upstreamName} {\n server ${gateWayOfContainer};\n}`;
|
||||
const gateWayOfContainer = await getGatewayOfStAppsBackend(activeBackends[0]);
|
||||
|
||||
return ` \"~${activeVersionRegex}\" ${upstreamName};\n`;
|
||||
if (gateWayOfContainer.length !== 0) {
|
||||
upstreams += `\nupstream ${upstreamName} {\n server ${gateWayOfContainer};\n}`;
|
||||
|
||||
return ` \"~${activeVersionRegex}\" ${upstreamName};\n`;
|
||||
}
|
||||
}
|
||||
|
||||
return ` \"~${activeVersionRegex}\" unavailable;\n`;
|
||||
}
|
||||
await Logger.error('No backend for version', activeVersionRegex, 'found');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user