-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
env.js
89 lines (81 loc) · 2.88 KB
/
env.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
'use strict';
// Modules
const _ = require('lodash');
const fs = require('fs');
const path = require('path');
const shell = require('shelljs');
/*
* Helper to get an executable
*/
const getDockerBin = (bin, base) => {
// Do platform appropriate things to get started
const join = (process.platform === 'win32') ? path.win32.join : path.posix.join;
let binPath = (process.platform === 'win32') ? join(base, `${bin}.exe`) : join(base, bin);
// Use PATH compose executable on posix if ours does not exist
if (process.platform !== 'win32' && (!fs.existsSync(binPath) || fs.statSync(binPath).isDirectory())) {
binPath = _.toString(shell.which(bin));
}
// If the binpath still does not exist then we should set to false and handle downstream
if (!fs.existsSync(binPath)) return false;
// Otherwise return a normalized binpath
switch (process.platform) {
case 'darwin': return path.posix.normalize(binPath);
case 'linux': return path.posix.normalize(binPath);
case 'win32': return path.win32.normalize(binPath);
}
};
/*
* Helper to get location of docker bin directory
*/
exports.getDockerBinPath = () => {
switch (process.platform) {
case 'darwin':
return '/Applications/Docker.app/Contents/Resources/bin';
case 'linux':
return '/usr/share/lando/bin';
case 'win32':
const programFiles = process.env.ProgramW6432 || process.env.ProgramFiles;
const programData = process.env.ProgramData;
// Check for Docker in 2.3.0.5+ first
if (fs.existsSync(path.win32.join(programData + '\\DockerDesktop\\version-bin\\docker.exe'))) {
return path.win32.join(programData + '\\DockerDesktop\\version-bin');
// Otherwise use the legacy path
} else {
return path.win32.join(programFiles + '\\Docker\\Docker\\resources\\bin');
}
}
};
/*
* Helper to get location of docker bin directory
*/
exports.getDockerComposeBinPath = () => {
switch (process.platform) {
case 'darwin':
return '/Applications/Docker.app/Contents/Resources/bin/docker-compose-v1';
case 'linux':
return exports.getDockerBinPath();
case 'win32':
const programFiles = process.env.ProgramW6432 || process.env.ProgramFiles;
return path.win32.join(programFiles + '\\Docker\\Docker\\resources\\bin');
}
};
/*
* Get docker compose binary path
*/
exports.getComposeExecutable = () => {
switch (process.platform) {
case 'darwin':
return getDockerBin('docker-compose', exports.getDockerComposeBinPath());
case 'linux':
return getDockerBin('docker-compose', exports.getDockerComposeBinPath());
case 'win32':
return getDockerBin('docker-compose-v1', exports.getDockerComposeBinPath());
}
};
/*
* This should only be needed for linux
*/
exports.getDockerExecutable = () => {
const base = (process.platform === 'linux') ? '/usr/bin' : exports.getDockerBinPath();
return getDockerBin('docker', base);
};