forked from crosbymichael/skydock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.js
39 lines (37 loc) · 1.14 KB
/
default.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
function createService(container) {
var port = getDefaultPort(container);
return {
Port: port,
Environment: defaultEnvironment,
TTL: defaultTTL,
Service: cleanImageName(container.Image),
Instance: removeSlash(container.Name),
Host: container.NetworkSettings.IpAddress
};
}
function getDefaultPort(container) {
// if we have any exposed ports use those
var port = 0;
var ports = container.NetworkSettings.Ports;
if (Object.keys(ports).length > 0) {
for (var key in ports) {
var value = ports[key];
if (value !== null && value.length > 0) {
for (var i = 0; i < value.length; i++) {
var hp = parseInt(value[i].HostPort);
if (port === 0 || hp < port) {
port = hp;
}
}
} else if (port === 0) {
// just grab the key value
var expose = parseInt(key.split("/")[0]);
port = expose;
}
}
}
if (port === 0) {
port = 80;
}
return port;
}