1
0
Fork 0
mirror of https://github.com/pawelmalak/flame.git synced 2025-08-06 11:25:16 +02:00

Add support for multiple docker hosts

Add hosts split by a semi-colon and they will all be fetched
This commit is contained in:
Aaron Williams 2022-02-27 17:27:19 +10:00
parent 750891cffa
commit f4c4ba98be

View file

@ -11,33 +11,26 @@ const useDocker = async (apps) => {
dockerHost: host, dockerHost: host,
} = await loadConfig(); } = await loadConfig();
let containers = null; let containers = []
const hosts = host.split(';');
// Get list of containers
try { try {
if (host.includes('localhost')) { // Get list of containers
// Use default host containers = (await Promise.all(hosts.reduce((acc, host) => {
let { data } = await axios.get( const isLocalhost = host.includes('localhost');
acc.push(axios.get(
`http://${host}/containers/json?{"status":["running"]}`, `http://${host}/containers/json?{"status":["running"]}`,
{ isLocalhost ? {
socketPath: '/var/run/docker.sock', socketPath: '/var/run/docker.sock',
} } : {}
); ))
return acc;
containers = data; }, []))).flatMap(({ data }) => data)
} else { } catch (err) {
// Use custom host logger.log(`Can't connect to the Docker API on one of the hosts: ${hosts.join(', ')}`, 'ERROR');
let { data } = await axios.get(
`http://${host}/containers/json?{"status":["running"]}`
);
containers = data;
}
} catch {
logger.log(`Can't connect to the Docker API on ${host}`, 'ERROR');
} }
if (containers) { if (containers.length > 0) {
apps = await App.findAll({ apps = await App.findAll({
order: [[orderType, 'ASC']], order: [[orderType, 'ASC']],
}); });