Skip to content

Commit

Permalink
support for r:
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTrunk committed Nov 23, 2023
1 parent 21c77e2 commit 1c7c210
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
32 changes: 31 additions & 1 deletion src/services/domainService.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ async function generateAndReplaceMainApplicationHaproxyConfig() {
}
}
// continue with appsOK
const configuredApps = []; // object of domain, port, ips for backend
const configuredApps = []; // object of domain, port, ips for backend and isRdata
for (const app of appsOK) {
log.info(`Configuring ${app.name}`);
// eslint-disable-next-line no-await-in-loop
Expand Down Expand Up @@ -248,6 +248,9 @@ async function generateAndReplaceMainApplicationHaproxyConfig() {
ips: appIps,
...customConfigs[i],
};
if (app.containerData.includes('r:')) {
configuredApp.isRdata = true;
}
configuredApps.push(configuredApp);
if (app.domains[i]) {
const portDomains = app.domains[i].split(',');
Expand Down Expand Up @@ -277,6 +280,9 @@ async function generateAndReplaceMainApplicationHaproxyConfig() {
ips: appIps,
...customConfigs[i],
};
if (app.containerData.includes('r:')) {
configuredAppCustom.isRdata = true;
}
configuredApps.push(configuredAppCustom);
}
const wwwAdjustedDomain = `www.${portDomain.toLowerCase()}`;
Expand All @@ -291,6 +297,9 @@ async function generateAndReplaceMainApplicationHaproxyConfig() {
ips: appIps,
...customConfigs[i],
};
if (app.containerData.includes('r:')) {
configuredAppCustom.isRdata = true;
}
configuredApps.push(configuredAppCustom);
}
}
Expand All @@ -307,6 +316,9 @@ async function generateAndReplaceMainApplicationHaproxyConfig() {
ips: appIps,
...customConfigs[i],
};
if (app.containerData.includes('r:')) {
configuredAppCustom.isRdata = true;
}
configuredApps.push(configuredAppCustom);
}
}
Expand All @@ -322,6 +334,9 @@ async function generateAndReplaceMainApplicationHaproxyConfig() {
ips: appIps,
...customConfigs[customConfigs.length - 1],
};
if (app.containerData.includes('r:')) {
mainApp.isRdata = true;
}
configuredApps.push(mainApp);
} else {
let j = 0;
Expand All @@ -335,6 +350,9 @@ async function generateAndReplaceMainApplicationHaproxyConfig() {
ips: appIps,
...customConfigs[j],
};
if (component.containerData.includes('r:')) {
configuredApp.isRdata = true;
}
configuredApps.push(configuredApp);
const portDomains = component.domains[i].split(',');
// eslint-disable-next-line no-loop-func
Expand Down Expand Up @@ -364,6 +382,9 @@ async function generateAndReplaceMainApplicationHaproxyConfig() {
ips: appIps,
...customConfigs[j],
};
if (component.containerData.includes('r:')) {
configuredAppCustom.isRdata = true;
}
configuredApps.push(configuredAppCustom);
}

Expand All @@ -379,6 +400,9 @@ async function generateAndReplaceMainApplicationHaproxyConfig() {
ips: appIps,
...customConfigs[j],
};
if (component.containerData.includes('r:')) {
configuredAppCustom.isRdata = true;
}
configuredApps.push(configuredAppCustom);
}
}
Expand All @@ -395,6 +419,9 @@ async function generateAndReplaceMainApplicationHaproxyConfig() {
ips: appIps,
...customConfigs[j],
};
if (component.containerData.includes('r:')) {
configuredAppCustom.isRdata = true;
}
configuredApps.push(configuredAppCustom);
}
}
Expand All @@ -417,6 +444,9 @@ async function generateAndReplaceMainApplicationHaproxyConfig() {
ips: appIps,
...customConfigs[customConfigs.length - 1],
};
if (app.compose[q].containerData.includes('r:')) {
mainApp.isRdata = true;
}
configuredApps.push(mainApp);
}
}
Expand Down
16 changes: 16 additions & 0 deletions src/services/haproxyTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ const log = require('../lib/log');
const { cmdAsync, TEMP_HAPROXY_CONFIG, HAPROXY_CONFIG } = require('./constants');
const { matchRule } = require('./serviceHelper');

const mapOfNamesIps = {};

const haproxyPrefix = `
global
maxconn 50000
Expand Down Expand Up @@ -219,6 +221,20 @@ backend ${domainUsed}backend
} else {
domainBackend += `\n server ${ip.split(':')[0]}:${apiPort} ${ip.split(':')[0]}:${app.port} check ${app.serverConfig}${cookieConfig}`;
}
if (app.isRdata) {
if (mapOfNamesIps[app.name] && app.ips.includse(mapOfNamesIps[app.name])) { // use this ip as a main
if (mapOfNamesIps[app.name] === ip) {
// for the main IP use
domainBackend += ' inter 10s fall 3 rise 99999999';
} else {
// for other IP configure them as backup
domainBackend += ' backup';
}
} else { // set new IP as main
mapOfNamesIps[app.name] = ip;
domainBackend += ' inter 10s fall 3 rise 99999999';
}
}
if (app.timeout) {
domainBackend += `\n timeout server ${app.timeout}`;
}
Expand Down

0 comments on commit 1c7c210

Please sign in to comment.