Merge pull request #719 from benphelps/docker-server-failovers

Fix: Handle docker server failures if others succeed
pull/749/head v0.5.8
shamoon 2 years ago committed by GitHub
commit 0e1aeaf54c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -52,7 +52,7 @@ export async function servicesResponse() {
discoveredServices = cleanServiceGroups(await servicesFromDocker());
} catch (e) {
console.error("Failed to discover services, please check docker.yaml for errors or remove example entries.");
if (e) console.error(e);
if (e) console.error(e.toString());
discoveredServices = [];
}
@ -60,7 +60,7 @@ export async function servicesResponse() {
configuredServices = cleanServiceGroups(await servicesFromConfig());
} catch (e) {
console.error("Failed to load services.yaml, please check for errors");
if (e) console.error(e);
if (e) console.error(e.toString());
configuredServices = [];
}
@ -68,7 +68,7 @@ export async function servicesResponse() {
initialSettings = await getSettings();
} catch (e) {
console.error("Failed to load settings.yaml, please check for errors");
if (e) console.error(e);
if (e) console.error(e.toString());
initialSettings = {};
}

@ -44,39 +44,48 @@ export async function servicesFromDocker() {
const serviceServers = await Promise.all(
Object.keys(servers).map(async (serverName) => {
const docker = new Docker(getDockerArguments(serverName).conn);
const containers = await docker.listContainers({
all: true,
});
// bad docker connections can result in a <Buffer ...> object?
// in any case, this ensures the result is the expected array
if (!Array.isArray(containers)) {
return [];
}
try {
const docker = new Docker(getDockerArguments(serverName).conn);
const containers = await docker.listContainers({
all: true,
});
const discovered = containers.map((container) => {
let constructedService = null;
// bad docker connections can result in a <Buffer ...> object?
// in any case, this ensures the result is the expected array
if (!Array.isArray(containers)) {
return [];
}
Object.keys(container.Labels).forEach((label) => {
if (label.startsWith("homepage.")) {
if (!constructedService) {
constructedService = {
container: container.Names[0].replace(/^\//, ""),
server: serverName,
};
const discovered = containers.map((container) => {
let constructedService = null;
Object.keys(container.Labels).forEach((label) => {
if (label.startsWith("homepage.")) {
if (!constructedService) {
constructedService = {
container: container.Names[0].replace(/^\//, ""),
server: serverName,
};
}
shvl.set(constructedService, label.replace("homepage.", ""), container.Labels[label]);
}
shvl.set(constructedService, label.replace("homepage.", ""), container.Labels[label]);
}
});
});
return constructedService;
});
return constructedService;
});
return { server: serverName, services: discovered.filter((filteredService) => filteredService) };
return { server: serverName, services: discovered.filter((filteredService) => filteredService) };
} catch (e) {
// a server failed, but others may succeed
return { server: serverName, services: [] };
}
})
);
if (serviceServers.every(server => server.services.length === 0)) {
throw new Error('All docker servers failed to connect or returned no containers');
}
const mappedServiceGroups = [];
serviceServers.forEach((server) => {

Loading…
Cancel
Save