-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathgenerateEnvsFactory.js
95 lines (81 loc) · 3.11 KB
/
generateEnvsFactory.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import os from 'os';
import convertObjectToEnvs from './convertObjectToEnvs.js';
import { DASHMATE_HELPER_DOCKER_IMAGE } from '../constants.js';
/**
* @param {ConfigFile} configFile
* @param {HomeDir} homeDir
* @param {getConfigProfiles} getConfigProfiles
* @return {generateEnvs}
*/
export default function generateEnvsFactory(configFile, homeDir, getConfigProfiles) {
/**
* @typedef {function} generateEnvs
* @param {Config} config
* @returns {{
* COMPOSE_DOCKER_CLI_BUILD: number,
* CONFIG_NAME: string,
* DOCKER_BUILDKIT: number,
* COMPOSE_PROJECT_NAME: string,
* COMPOSE_FILE: string,
* COMPOSE_PATH_SEPARATOR: string,
* }}
*/
function generateEnvs(config) {
const dynamicComposePath = homeDir.joinPath(
config.getName(),
'dynamic-compose.yml',
);
const dockerComposeFiles = ['docker-compose.yml', dynamicComposePath];
const profiles = getConfigProfiles(config);
if (config.get('dashmate.helper.docker.build.enabled')) {
dockerComposeFiles.push('docker-compose.build.dashmate_helper.yml');
}
if (config.get('platform.enable')) {
if (config.get('platform.drive.abci.docker.build.enabled')) {
dockerComposeFiles.push('docker-compose.build.drive_abci.yml');
}
if (config.get('platform.dapi.api.docker.build.enabled')) {
dockerComposeFiles.push('docker-compose.build.dapi_api.yml');
dockerComposeFiles.push('docker-compose.build.dapi_core_streams.yml');
}
}
if (config.get('core.insight.enabled')) {
let insightComposeFile = 'docker-compose.insight_api.yml';
if (config.get('core.insight.ui.enabled')) {
insightComposeFile = 'docker-compose.insight_ui.yml';
}
dockerComposeFiles.push(insightComposeFile);
}
if (config.get('platform.gateway.rateLimiter.enabled')) {
dockerComposeFiles.push('docker-compose.rate_limiter.yml');
if (config.get('platform.gateway.rateLimiter.metrics.enabled')) {
dockerComposeFiles.push('docker-compose.rate_limiter.metrics.yml');
}
}
// we need this for compatibility with old configs
const projectIdWithPrefix = configFile.getProjectId() ? `_${configFile.getProjectId()}` : '';
const { uid, gid } = os.userInfo();
let driveAbciMetricsUrl = '';
if (config.get('platform.drive.abci.metrics.enabled')) {
// IP and port inside container
driveAbciMetricsUrl = 'http://0.0.0.0:29090';
}
return {
DASHMATE_HOME_DIR: homeDir.getPath(),
LOCAL_UID: uid,
LOCAL_GID: gid,
COMPOSE_PROJECT_NAME: `dashmate${projectIdWithPrefix}_${config.getName()}`,
CONFIG_NAME: config.getName(),
COMPOSE_FILE: dockerComposeFiles.join(':'),
COMPOSE_PROFILES: profiles.join(','),
COMPOSE_PATH_SEPARATOR: ':',
DOCKER_BUILDKIT: 1,
COMPOSE_DOCKER_CLI_BUILD: 1,
DASHMATE_HELPER_DOCKER_IMAGE,
PLATFORM_GATEWAY_RATE_LIMITER_METRICS_DISABLED: !config.get('platform.gateway.rateLimiter.metrics.enabled'),
PLATFORM_DRIVE_ABCI_METRICS_URL: driveAbciMetricsUrl,
...convertObjectToEnvs(config.getOptions()),
};
}
return generateEnvs;
}