mirror of
https://github.com/pawelmalak/flame.git
synced 2025-08-05 10:55:17 +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:
parent
750891cffa
commit
f4c4ba98be
1 changed files with 14 additions and 21 deletions
|
@ -11,33 +11,26 @@ const useDocker = async (apps) => {
|
|||
dockerHost: host,
|
||||
} = await loadConfig();
|
||||
|
||||
let containers = null;
|
||||
let containers = []
|
||||
const hosts = host.split(';');
|
||||
|
||||
// Get list of containers
|
||||
try {
|
||||
if (host.includes('localhost')) {
|
||||
// Use default host
|
||||
let { data } = await axios.get(
|
||||
// Get list of containers
|
||||
containers = (await Promise.all(hosts.reduce((acc, host) => {
|
||||
const isLocalhost = host.includes('localhost');
|
||||
acc.push(axios.get(
|
||||
`http://${host}/containers/json?{"status":["running"]}`,
|
||||
{
|
||||
isLocalhost ? {
|
||||
socketPath: '/var/run/docker.sock',
|
||||
}
|
||||
);
|
||||
|
||||
containers = data;
|
||||
} else {
|
||||
// Use custom host
|
||||
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');
|
||||
} : {}
|
||||
))
|
||||
return acc;
|
||||
}, []))).flatMap(({ data }) => data)
|
||||
} catch (err) {
|
||||
logger.log(`Can't connect to the Docker API on one of the hosts: ${hosts.join(', ')}`, 'ERROR');
|
||||
}
|
||||
|
||||
if (containers) {
|
||||
if (containers.length > 0) {
|
||||
apps = await App.findAll({
|
||||
order: [[orderType, 'ASC']],
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue