refs #5101 Select port when multiple ports are published for an HTTP service
gitea/docker-discover/pipeline/head This commit looks good
Details
gitea/docker-discover/pipeline/head This commit looks good
Details
This commit is contained in:
parent
a437b28cb0
commit
f221dead2b
|
@ -54,4 +54,7 @@ domains:
|
|||
- /bar
|
||||
https: false
|
||||
zone: dmz
|
||||
foo_bar:
|
||||
bar:
|
||||
port: 443
|
||||
bar_baz:
|
||||
|
|
35
index.js
35
index.js
|
@ -15,7 +15,7 @@ const isProduction = process.env.NODE_ENV === 'production';
|
|||
const tmpDir = isProduction ? `/tmp/${appName}` : `${__dirname}/tmp`;
|
||||
const hashFile = `${tmpDir}/config.hash`;
|
||||
const confDir = conf.rproxy.confDir;
|
||||
const httpServices = new Set();
|
||||
const httpServices = new Map();
|
||||
|
||||
async function updateProxy(firstRun) {
|
||||
console.log('Updating reverse proxy configuration.');
|
||||
|
@ -61,17 +61,30 @@ async function updateProxy(firstRun) {
|
|||
const match = name.match(/^(.+)_main$/);
|
||||
if (match) name = match[1];
|
||||
|
||||
let httpPortIndex = null;
|
||||
|
||||
if (httpServices.has(name)) {
|
||||
if (ports.length > 1) {
|
||||
const httpPort = httpServices.get(name) || 80;
|
||||
const index = ports.findIndex(
|
||||
p => p.TargetPort == httpPort && p.Protocol === 'tcp');
|
||||
if (index !== -1) httpPortIndex = index;
|
||||
}
|
||||
if (httpPortIndex === null) {
|
||||
const index = ports.findIndex(p => p.Protocol === 'tcp');
|
||||
if (index !== -1) httpPortIndex = index;
|
||||
}
|
||||
}
|
||||
|
||||
for (let i = 0; i < ports.length; i++) {
|
||||
const port = ports[i];
|
||||
const protocol = port.Protocol;
|
||||
|
||||
let backends;
|
||||
if (protocol == 'tcp') {
|
||||
if (i == 0 && httpServices.has(name))
|
||||
backends = http;
|
||||
else
|
||||
backends = tcp;
|
||||
} else
|
||||
|
||||
if (i === httpPortIndex)
|
||||
backends = http;
|
||||
else if (port.Protocol === 'tcp')
|
||||
backends = tcp;
|
||||
else
|
||||
backends = udp;
|
||||
|
||||
backends.push({
|
||||
|
@ -188,8 +201,6 @@ async function updateProxy(firstRun) {
|
|||
}
|
||||
|
||||
function addService(service, serviceConf, mainDomain) {
|
||||
httpServices.add(service);
|
||||
|
||||
let rules;
|
||||
if (typeof serviceConf == 'string') {
|
||||
rules = serviceConf;
|
||||
|
@ -201,6 +212,8 @@ async function updateProxy(firstRun) {
|
|||
serviceConf
|
||||
);
|
||||
|
||||
httpServices.set(service, serviceConf.port);
|
||||
|
||||
if (serviceConf.https)
|
||||
https.push(service);
|
||||
if (serviceConf.zone) {
|
||||
|
|
29
test.json
29
test.json
|
@ -6,6 +6,22 @@
|
|||
"Ports": [
|
||||
{
|
||||
"PublishedPort": 10001,
|
||||
"TargetPort": 80,
|
||||
"Protocol": "tcp"
|
||||
}, {
|
||||
"PublishedPort": 10002,
|
||||
"TargetPort": 3306,
|
||||
"Protocol": "tcp"
|
||||
}
|
||||
]
|
||||
}
|
||||
}, {
|
||||
"Spec": {"Name": "foo_bar"},
|
||||
"Endpoint": {
|
||||
"Ports": [
|
||||
{
|
||||
"PublishedPort": 10003,
|
||||
"TargetPort": 443,
|
||||
"Protocol": "tcp"
|
||||
}
|
||||
]
|
||||
|
@ -15,10 +31,12 @@
|
|||
"Endpoint": {
|
||||
"Ports": [
|
||||
{
|
||||
"PublishedPort": 10003,
|
||||
"PublishedPort": 10004,
|
||||
"TargetPort": 3584,
|
||||
"Protocol": "tcp"
|
||||
}, {
|
||||
"PublishedPort": 10004,
|
||||
"PublishedPort": 10005,
|
||||
"TargetPort": 443,
|
||||
"Protocol": "tcp"
|
||||
}
|
||||
]
|
||||
|
@ -28,10 +46,12 @@
|
|||
"Endpoint": {
|
||||
"Ports": [
|
||||
{
|
||||
"PublishedPort": 10005,
|
||||
"PublishedPort": 10006,
|
||||
"TargetPort": 101,
|
||||
"Protocol": "tcp"
|
||||
}, {
|
||||
"PublishedPort": 10006,
|
||||
"PublishedPort": 10007,
|
||||
"TargetPort": 80,
|
||||
"Protocol": "tcp"
|
||||
}
|
||||
]
|
||||
|
@ -42,6 +62,7 @@
|
|||
"Ports": [
|
||||
{
|
||||
"PublishedPort": 10001,
|
||||
"TargetPort": 100,
|
||||
"Protocol": "udp"
|
||||
}
|
||||
]
|
||||
|
|
Reference in New Issue