forked from Informatievlaanderen/ldes2service
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker_setup.js
31 lines (25 loc) · 1018 Bytes
/
docker_setup.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
//Create config.json.example from ENV VARS
const fs = require('fs/promises');
async function setup() {
try {
return await fs.access('./config.json', 4);
} catch {
const config = {
connectors: {},
replicator: {},
}
config.replicator.state = JSON.parse(process.env.STATE_CONFIG || '{"id":"replicator"}');
config.replicator.polling_interval = Number.parseInt(process.env.POLL_INTERVAL || '5000');
config.replicator.ldes = process.env.URLS.split(',').map(url => { return { url } });
const connectors = JSON.parse(process.env.CONNECTORS || '[]');
for (let con of connectors) {
config.connectors[con] = {
type: process.env[`CONNECTOR_${con}_TYPE`] || '@ldes/ldes-dummy-connector',
settings: JSON.parse(process.env[`CONNECTOR_${con}_CONFIG`] || '{}'),
}
}
console.log('Config file created:', config);
await fs.writeFile('./config.json', JSON.stringify(config, null, 2), 'utf8');
}
}
setup().catch(error => console.error(error));