@leverege/build-tools 2.16.2 → 2.17.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/server/firebaseDeploy.js +116 -0
- package/lib/server/firebaseServe.js +116 -0
- package/lib/server/repo-init/config.tgz +0 -0
- package/lib/web/firebaseDeploy.js +116 -0
- package/lib/web/firebaseServe.js +116 -0
- package/package.json +13 -7
- package/src/bash-funcs +3 -1
- package/src/firebaseDeploy.mjs +118 -0
- package/src/firebaseServe.mjs +118 -0
- package/src/helmup +5 -16
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// https://github.com/google/zx
|
|
3
|
+
|
|
4
|
+
/* eslint-disable max-len */
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
var _enquirer = _interopRequireDefault(require("enquirer"));
|
|
8
|
+
|
|
9
|
+
var _zx = require("zx");
|
|
10
|
+
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
prompt
|
|
15
|
+
} = _enquirer.default; // This will preserve coloration from spawned child processes
|
|
16
|
+
|
|
17
|
+
process.env.FORCE_COLORS = 3;
|
|
18
|
+
process.env.FORCE_COLOR = '1';
|
|
19
|
+
let TARGET = _zx.argv._[0];
|
|
20
|
+
let exited = false;
|
|
21
|
+
const SECRETS_DIR = 'secrets';
|
|
22
|
+
const EXIT_EVENTS = ['SIGINT', 'exit', 'uncaughException', 'unhandledRejection'];
|
|
23
|
+
const [firebaserc, firebaseJson] = await Promise.all([_zx.fs.exists(_zx.path.join(process.cwd(), '.firebaserc')), _zx.fs.exists(_zx.path.join(process.cwd(), 'firebase.json'))]);
|
|
24
|
+
|
|
25
|
+
if (!firebaserc) {
|
|
26
|
+
console.log(_zx.chalk.red('No .firebaserc file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!firebaseJson) {
|
|
30
|
+
console.log(_zx.chalk.red('No firebase.json file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!firebaserc || !firebaseJson) {
|
|
34
|
+
process.exit();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const firebasercContent = JSON.parse(await _zx.fs.readFile(_zx.path.join(process.cwd(), '.firebaserc'), {
|
|
38
|
+
encoding: 'utf-8'
|
|
39
|
+
}));
|
|
40
|
+
const targets = Object.entries(firebasercContent.targets).reduce((prev, [projectId, config]) => {
|
|
41
|
+
Object.entries(config.hosting).forEach(([siteId, aliases]) => {
|
|
42
|
+
aliases.forEach(alias => {
|
|
43
|
+
prev[alias] = {
|
|
44
|
+
projectId,
|
|
45
|
+
siteId,
|
|
46
|
+
alias
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
return prev;
|
|
51
|
+
}, {});
|
|
52
|
+
|
|
53
|
+
if (!TARGET) {
|
|
54
|
+
const {
|
|
55
|
+
targetEnv
|
|
56
|
+
} = await prompt({
|
|
57
|
+
type: 'autocomplete',
|
|
58
|
+
name: 'targetEnv',
|
|
59
|
+
message: 'To which environment would you like to deploy?',
|
|
60
|
+
choices: Object.keys(targets).map(t => ({
|
|
61
|
+
name: t,
|
|
62
|
+
value: t
|
|
63
|
+
}))
|
|
64
|
+
});
|
|
65
|
+
TARGET = targets[targetEnv];
|
|
66
|
+
} else {
|
|
67
|
+
TARGET = targets[TARGET];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!TARGET) {
|
|
71
|
+
console.log(_zx.chalk.red('No such target exists in .firebaserc config.'));
|
|
72
|
+
process.exit();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const [aliasFileExists, siteIdFileExists, sharedFileExists] = await Promise.all([_zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`)), _zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env`)), _zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'))]);
|
|
76
|
+
|
|
77
|
+
if (!aliasFileExists && !siteIdFileExists) {
|
|
78
|
+
console.log(_zx.chalk.red(`No env file for ${TARGET.alias} exists. Check your secrets directory and try again`));
|
|
79
|
+
process.exit();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const exec = [];
|
|
83
|
+
|
|
84
|
+
if (sharedFileExists) {
|
|
85
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'), {
|
|
86
|
+
encoding: 'utf-8'
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (aliasFileExists) {
|
|
91
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`), {
|
|
92
|
+
encoding: 'utf-8'
|
|
93
|
+
}));
|
|
94
|
+
} else {
|
|
95
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env`), {
|
|
96
|
+
encoding: 'utf-8'
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const envFileContent = (await Promise.all(exec)).join('\n');
|
|
101
|
+
EXIT_EVENTS.forEach(event => {
|
|
102
|
+
process.on(event, () => {
|
|
103
|
+
if (!exited) {
|
|
104
|
+
exited = true;
|
|
105
|
+
|
|
106
|
+
_zx.fs.removeSync(_zx.path.join(process.cwd(), '.env.temp'));
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
await _zx.fs.writeFile(_zx.path.join(process.cwd(), '.env.temp'), envFileContent);
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
await (0, _zx.$)`npm run clean && DOTENV_CONFIG_PATH=${_zx.path.join(process.cwd(), '.env.temp')} npm run build && firebase use ${TARGET.projectId} && firebase deploy --only hosting:${TARGET.siteId}`;
|
|
114
|
+
} catch (err) {
|
|
115
|
+
console.error(err);
|
|
116
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// https://github.com/google/zx
|
|
3
|
+
|
|
4
|
+
/* eslint-disable max-len */
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
var _enquirer = _interopRequireDefault(require("enquirer"));
|
|
8
|
+
|
|
9
|
+
var _zx = require("zx");
|
|
10
|
+
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
prompt
|
|
15
|
+
} = _enquirer.default; // This will preserve coloration from spawned child processes
|
|
16
|
+
|
|
17
|
+
process.env.FORCE_COLORS = 3;
|
|
18
|
+
process.env.FORCE_COLOR = '1';
|
|
19
|
+
let TARGET = _zx.argv._[0];
|
|
20
|
+
let exited = false;
|
|
21
|
+
const SECRETS_DIR = 'secrets';
|
|
22
|
+
const EXIT_EVENTS = ['SIGINT', 'exit', 'uncaughtException', 'unhandledRejection'];
|
|
23
|
+
const [firebaserc, firebaseJson] = await Promise.all([_zx.fs.exists(_zx.path.join(process.cwd(), '.firebaserc')), _zx.fs.exists(_zx.path.join(process.cwd(), 'firebase.json'))]);
|
|
24
|
+
|
|
25
|
+
if (!firebaserc) {
|
|
26
|
+
console.log(_zx.chalk.red('No .firebaserc file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!firebaseJson) {
|
|
30
|
+
console.log(_zx.chalk.red('No firebase.json file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!firebaserc || !firebaseJson) {
|
|
34
|
+
process.exit();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const firebasercContent = JSON.parse(await _zx.fs.readFile(_zx.path.join(process.cwd(), '.firebaserc'), {
|
|
38
|
+
encoding: 'utf-8'
|
|
39
|
+
}));
|
|
40
|
+
const targets = Object.entries(firebasercContent.targets).reduce((prev, [projectId, config]) => {
|
|
41
|
+
Object.entries(config.hosting).forEach(([siteId, aliases]) => {
|
|
42
|
+
aliases.forEach(alias => {
|
|
43
|
+
prev[alias] = {
|
|
44
|
+
projectId,
|
|
45
|
+
siteId,
|
|
46
|
+
alias
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
return prev;
|
|
51
|
+
}, {});
|
|
52
|
+
|
|
53
|
+
if (!TARGET) {
|
|
54
|
+
const {
|
|
55
|
+
targetEnv
|
|
56
|
+
} = await prompt({
|
|
57
|
+
type: 'autocomplete',
|
|
58
|
+
name: 'targetEnv',
|
|
59
|
+
message: 'Which environment would you like to serve?',
|
|
60
|
+
choices: Object.keys(targets).map(t => ({
|
|
61
|
+
name: t,
|
|
62
|
+
value: t
|
|
63
|
+
}))
|
|
64
|
+
});
|
|
65
|
+
TARGET = targets[targetEnv];
|
|
66
|
+
} else {
|
|
67
|
+
TARGET = targets[TARGET];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!TARGET) {
|
|
71
|
+
console.log(_zx.chalk.red('No such target exists in .firebaserc config.'));
|
|
72
|
+
process.exit();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const [aliasFileExists, siteIdFileExists, sharedFileExists] = await Promise.all([_zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`)), _zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env`)), _zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'))]);
|
|
76
|
+
|
|
77
|
+
if (!aliasFileExists && !siteIdFileExists) {
|
|
78
|
+
console.log(_zx.chalk.red(`No env file for ${TARGET.alias} exists. Check your secrets directory and try again`));
|
|
79
|
+
process.exit();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const exec = [];
|
|
83
|
+
|
|
84
|
+
if (sharedFileExists) {
|
|
85
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'), {
|
|
86
|
+
encoding: 'utf-8'
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (aliasFileExists) {
|
|
91
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`), {
|
|
92
|
+
encoding: 'utf-8'
|
|
93
|
+
}));
|
|
94
|
+
} else {
|
|
95
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env`), {
|
|
96
|
+
encoding: 'utf-8'
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const envFileContent = (await Promise.all(exec)).join('\n');
|
|
101
|
+
EXIT_EVENTS.forEach(event => {
|
|
102
|
+
process.on(event, () => {
|
|
103
|
+
if (!exited) {
|
|
104
|
+
exited = true;
|
|
105
|
+
|
|
106
|
+
_zx.fs.removeSync(_zx.path.join(process.cwd(), '.env.temp'));
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
await _zx.fs.writeFile(_zx.path.join(process.cwd(), '.env.temp'), envFileContent);
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
await (0, _zx.$)`DOTENV_CONFIG_PATH=${_zx.path.join(process.cwd(), '.env.temp')} npm run serve --colors`;
|
|
114
|
+
} catch (err) {
|
|
115
|
+
console.error(err);
|
|
116
|
+
}
|
|
Binary file
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// https://github.com/google/zx
|
|
3
|
+
|
|
4
|
+
/* eslint-disable max-len */
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
var _enquirer = _interopRequireDefault(require("enquirer"));
|
|
8
|
+
|
|
9
|
+
var _zx = require("zx");
|
|
10
|
+
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
prompt
|
|
15
|
+
} = _enquirer.default; // This will preserve coloration from spawned child processes
|
|
16
|
+
|
|
17
|
+
process.env.FORCE_COLORS = 3;
|
|
18
|
+
process.env.FORCE_COLOR = '1';
|
|
19
|
+
let TARGET = _zx.argv._[0];
|
|
20
|
+
let exited = false;
|
|
21
|
+
const SECRETS_DIR = 'secrets';
|
|
22
|
+
const EXIT_EVENTS = ['SIGINT', 'exit', 'uncaughException', 'unhandledRejection'];
|
|
23
|
+
const [firebaserc, firebaseJson] = await Promise.all([_zx.fs.exists(_zx.path.join(process.cwd(), '.firebaserc')), _zx.fs.exists(_zx.path.join(process.cwd(), 'firebase.json'))]);
|
|
24
|
+
|
|
25
|
+
if (!firebaserc) {
|
|
26
|
+
console.log(_zx.chalk.red('No .firebaserc file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!firebaseJson) {
|
|
30
|
+
console.log(_zx.chalk.red('No firebase.json file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!firebaserc || !firebaseJson) {
|
|
34
|
+
process.exit();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const firebasercContent = JSON.parse(await _zx.fs.readFile(_zx.path.join(process.cwd(), '.firebaserc'), {
|
|
38
|
+
encoding: 'utf-8'
|
|
39
|
+
}));
|
|
40
|
+
const targets = Object.entries(firebasercContent.targets).reduce((prev, [projectId, config]) => {
|
|
41
|
+
Object.entries(config.hosting).forEach(([siteId, aliases]) => {
|
|
42
|
+
aliases.forEach(alias => {
|
|
43
|
+
prev[alias] = {
|
|
44
|
+
projectId,
|
|
45
|
+
siteId,
|
|
46
|
+
alias
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
return prev;
|
|
51
|
+
}, {});
|
|
52
|
+
|
|
53
|
+
if (!TARGET) {
|
|
54
|
+
const {
|
|
55
|
+
targetEnv
|
|
56
|
+
} = await prompt({
|
|
57
|
+
type: 'autocomplete',
|
|
58
|
+
name: 'targetEnv',
|
|
59
|
+
message: 'To which environment would you like to deploy?',
|
|
60
|
+
choices: Object.keys(targets).map(t => ({
|
|
61
|
+
name: t,
|
|
62
|
+
value: t
|
|
63
|
+
}))
|
|
64
|
+
});
|
|
65
|
+
TARGET = targets[targetEnv];
|
|
66
|
+
} else {
|
|
67
|
+
TARGET = targets[TARGET];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!TARGET) {
|
|
71
|
+
console.log(_zx.chalk.red('No such target exists in .firebaserc config.'));
|
|
72
|
+
process.exit();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const [aliasFileExists, siteIdFileExists, sharedFileExists] = await Promise.all([_zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`)), _zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env`)), _zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'))]);
|
|
76
|
+
|
|
77
|
+
if (!aliasFileExists && !siteIdFileExists) {
|
|
78
|
+
console.log(_zx.chalk.red(`No env file for ${TARGET.alias} exists. Check your secrets directory and try again`));
|
|
79
|
+
process.exit();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const exec = [];
|
|
83
|
+
|
|
84
|
+
if (sharedFileExists) {
|
|
85
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'), {
|
|
86
|
+
encoding: 'utf-8'
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (aliasFileExists) {
|
|
91
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`), {
|
|
92
|
+
encoding: 'utf-8'
|
|
93
|
+
}));
|
|
94
|
+
} else {
|
|
95
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env`), {
|
|
96
|
+
encoding: 'utf-8'
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const envFileContent = (await Promise.all(exec)).join('\n');
|
|
101
|
+
EXIT_EVENTS.forEach(event => {
|
|
102
|
+
process.on(event, () => {
|
|
103
|
+
if (!exited) {
|
|
104
|
+
exited = true;
|
|
105
|
+
|
|
106
|
+
_zx.fs.removeSync(_zx.path.join(process.cwd(), '.env.temp'));
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
await _zx.fs.writeFile(_zx.path.join(process.cwd(), '.env.temp'), envFileContent);
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
await (0, _zx.$)`npm run clean && DOTENV_CONFIG_PATH=${_zx.path.join(process.cwd(), '.env.temp')} npm run build && firebase use ${TARGET.projectId} && firebase deploy --only hosting:${TARGET.siteId}`;
|
|
114
|
+
} catch (err) {
|
|
115
|
+
console.error(err);
|
|
116
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// https://github.com/google/zx
|
|
3
|
+
|
|
4
|
+
/* eslint-disable max-len */
|
|
5
|
+
"use strict";
|
|
6
|
+
|
|
7
|
+
var _enquirer = _interopRequireDefault(require("enquirer"));
|
|
8
|
+
|
|
9
|
+
var _zx = require("zx");
|
|
10
|
+
|
|
11
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
12
|
+
|
|
13
|
+
const {
|
|
14
|
+
prompt
|
|
15
|
+
} = _enquirer.default; // This will preserve coloration from spawned child processes
|
|
16
|
+
|
|
17
|
+
process.env.FORCE_COLORS = 3;
|
|
18
|
+
process.env.FORCE_COLOR = '1';
|
|
19
|
+
let TARGET = _zx.argv._[0];
|
|
20
|
+
let exited = false;
|
|
21
|
+
const SECRETS_DIR = 'secrets';
|
|
22
|
+
const EXIT_EVENTS = ['SIGINT', 'exit', 'uncaughtException', 'unhandledRejection'];
|
|
23
|
+
const [firebaserc, firebaseJson] = await Promise.all([_zx.fs.exists(_zx.path.join(process.cwd(), '.firebaserc')), _zx.fs.exists(_zx.path.join(process.cwd(), 'firebase.json'))]);
|
|
24
|
+
|
|
25
|
+
if (!firebaserc) {
|
|
26
|
+
console.log(_zx.chalk.red('No .firebaserc file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (!firebaseJson) {
|
|
30
|
+
console.log(_zx.chalk.red('No firebase.json file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (!firebaserc || !firebaseJson) {
|
|
34
|
+
process.exit();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const firebasercContent = JSON.parse(await _zx.fs.readFile(_zx.path.join(process.cwd(), '.firebaserc'), {
|
|
38
|
+
encoding: 'utf-8'
|
|
39
|
+
}));
|
|
40
|
+
const targets = Object.entries(firebasercContent.targets).reduce((prev, [projectId, config]) => {
|
|
41
|
+
Object.entries(config.hosting).forEach(([siteId, aliases]) => {
|
|
42
|
+
aliases.forEach(alias => {
|
|
43
|
+
prev[alias] = {
|
|
44
|
+
projectId,
|
|
45
|
+
siteId,
|
|
46
|
+
alias
|
|
47
|
+
};
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
return prev;
|
|
51
|
+
}, {});
|
|
52
|
+
|
|
53
|
+
if (!TARGET) {
|
|
54
|
+
const {
|
|
55
|
+
targetEnv
|
|
56
|
+
} = await prompt({
|
|
57
|
+
type: 'autocomplete',
|
|
58
|
+
name: 'targetEnv',
|
|
59
|
+
message: 'Which environment would you like to serve?',
|
|
60
|
+
choices: Object.keys(targets).map(t => ({
|
|
61
|
+
name: t,
|
|
62
|
+
value: t
|
|
63
|
+
}))
|
|
64
|
+
});
|
|
65
|
+
TARGET = targets[targetEnv];
|
|
66
|
+
} else {
|
|
67
|
+
TARGET = targets[TARGET];
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (!TARGET) {
|
|
71
|
+
console.log(_zx.chalk.red('No such target exists in .firebaserc config.'));
|
|
72
|
+
process.exit();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const [aliasFileExists, siteIdFileExists, sharedFileExists] = await Promise.all([_zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`)), _zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env`)), _zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'))]);
|
|
76
|
+
|
|
77
|
+
if (!aliasFileExists && !siteIdFileExists) {
|
|
78
|
+
console.log(_zx.chalk.red(`No env file for ${TARGET.alias} exists. Check your secrets directory and try again`));
|
|
79
|
+
process.exit();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const exec = [];
|
|
83
|
+
|
|
84
|
+
if (sharedFileExists) {
|
|
85
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'), {
|
|
86
|
+
encoding: 'utf-8'
|
|
87
|
+
}));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (aliasFileExists) {
|
|
91
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`), {
|
|
92
|
+
encoding: 'utf-8'
|
|
93
|
+
}));
|
|
94
|
+
} else {
|
|
95
|
+
exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env`), {
|
|
96
|
+
encoding: 'utf-8'
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const envFileContent = (await Promise.all(exec)).join('\n');
|
|
101
|
+
EXIT_EVENTS.forEach(event => {
|
|
102
|
+
process.on(event, () => {
|
|
103
|
+
if (!exited) {
|
|
104
|
+
exited = true;
|
|
105
|
+
|
|
106
|
+
_zx.fs.removeSync(_zx.path.join(process.cwd(), '.env.temp'));
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
await _zx.fs.writeFile(_zx.path.join(process.cwd(), '.env.temp'), envFileContent);
|
|
111
|
+
|
|
112
|
+
try {
|
|
113
|
+
await (0, _zx.$)`DOTENV_CONFIG_PATH=${_zx.path.join(process.cwd(), '.env.temp')} npm run serve --colors`;
|
|
114
|
+
} catch (err) {
|
|
115
|
+
console.error(err);
|
|
116
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@leverege/build-tools",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.17.0",
|
|
4
4
|
"description": "A collection of build / support tools for Leverege developers",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"repository": {
|
|
@@ -44,7 +44,9 @@
|
|
|
44
44
|
"pull-git": "src/pull-git",
|
|
45
45
|
"push-my-chart": "src/push-my-chart",
|
|
46
46
|
"repo-init": "lib/server/repo-init/index.js",
|
|
47
|
-
"unleash": "src/unleash.js"
|
|
47
|
+
"unleash": "src/unleash.js",
|
|
48
|
+
"firebaseDeploy": "src/firebaseDeploy.mjs",
|
|
49
|
+
"firebaseServe": "src/firebaseServe.mjs"
|
|
48
50
|
},
|
|
49
51
|
"author": "Leverege Devs",
|
|
50
52
|
"license": "SEE LICENSE IN LICENSE.md",
|
|
@@ -54,26 +56,30 @@
|
|
|
54
56
|
"command-line-args": "^5.2.1",
|
|
55
57
|
"command-line-usage": "^6.1.3",
|
|
56
58
|
"deepmerge": "^4.2.2",
|
|
59
|
+
"dotenv": "^16.0.1",
|
|
60
|
+
"enquirer": "^2.3.6",
|
|
57
61
|
"execa": "^5.1.1",
|
|
58
62
|
"figlet": "^1.5.2",
|
|
59
63
|
"glob": "^7.2.3",
|
|
60
64
|
"inquirer": "^8.2.4",
|
|
61
65
|
"js-yaml": "^4.1.0",
|
|
62
66
|
"ncp": "^2.0.0",
|
|
67
|
+
"npm-check-updates": "^13.1.2",
|
|
63
68
|
"npm-registry-fetch": "^11.0.0",
|
|
64
69
|
"open": "^8.4.0",
|
|
65
70
|
"ora": "^5.4.1",
|
|
66
71
|
"parse-gitignore": "^1.0.1",
|
|
67
72
|
"readline-sync": "^1.4.10",
|
|
68
73
|
"semver": "^7.3.7",
|
|
69
|
-
"simple-git": "^3.
|
|
74
|
+
"simple-git": "^3.7.1",
|
|
75
|
+
"zx": "^7.0.2"
|
|
70
76
|
},
|
|
71
77
|
"devDependencies": {
|
|
72
|
-
"@babel/cli": "^7.
|
|
73
|
-
"@babel/core": "^7.18.
|
|
74
|
-
"@babel/node": "^7.18.
|
|
78
|
+
"@babel/cli": "^7.17.10",
|
|
79
|
+
"@babel/core": "^7.18.5",
|
|
80
|
+
"@babel/node": "^7.18.5",
|
|
75
81
|
"@leverege/babel-preset-leverege-node": "^2.0.0",
|
|
76
82
|
"@leverege/eslint-config-leverege": "^3.0.1",
|
|
77
|
-
"npm": "^8.13.
|
|
83
|
+
"npm": "^8.13.1"
|
|
78
84
|
}
|
|
79
85
|
}
|
package/src/bash-funcs
CHANGED
|
@@ -95,6 +95,8 @@ INSTALLING
|
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
function addHelmRepo() {
|
|
98
|
+
[ ! -z "$HELM_REPO_SKIP" ] && return
|
|
99
|
+
|
|
98
100
|
local chart=$1
|
|
99
101
|
local url=$2
|
|
100
102
|
|
|
@@ -107,6 +109,6 @@ REPOADD
|
|
|
107
109
|
}
|
|
108
110
|
|
|
109
111
|
function removeHelmRepo(){
|
|
110
|
-
[ ! -z "$
|
|
112
|
+
[ ! -z "$HELM_REPO_SKIP" ] && return
|
|
111
113
|
helm repo remove $1 &>/dev/null
|
|
112
114
|
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// https://github.com/google/zx
|
|
3
|
+
/* eslint-disable max-len */
|
|
4
|
+
import pkg from 'enquirer'
|
|
5
|
+
import { $, fs, argv, path, chalk } from 'zx'
|
|
6
|
+
|
|
7
|
+
const { prompt } = pkg
|
|
8
|
+
|
|
9
|
+
// This will preserve coloration from spawned child processes
|
|
10
|
+
process.env.FORCE_COLORS = 3
|
|
11
|
+
process.env.FORCE_COLOR = '1'
|
|
12
|
+
|
|
13
|
+
let TARGET = argv._[0]
|
|
14
|
+
let exited = false
|
|
15
|
+
|
|
16
|
+
const SECRETS_DIR = 'secrets'
|
|
17
|
+
const EXIT_EVENTS = [ 'SIGINT', 'exit', 'uncaughException', 'unhandledRejection' ]
|
|
18
|
+
|
|
19
|
+
const [
|
|
20
|
+
firebaserc,
|
|
21
|
+
firebaseJson
|
|
22
|
+
] = await Promise.all( [
|
|
23
|
+
fs.exists( path.join( process.cwd(), '.firebaserc' ) ),
|
|
24
|
+
fs.exists( path.join( process.cwd(), 'firebase.json' ) )
|
|
25
|
+
] )
|
|
26
|
+
|
|
27
|
+
if ( !firebaserc ) {
|
|
28
|
+
console.log( chalk.red( 'No .firebaserc file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.' ) )
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if ( !firebaseJson ) {
|
|
32
|
+
console.log( chalk.red( 'No firebase.json file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.' ) )
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if ( !firebaserc || !firebaseJson ) {
|
|
36
|
+
process.exit()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const firebasercContent = JSON.parse( await fs.readFile( path.join( process.cwd(), '.firebaserc' ), { encoding : 'utf-8' } ) )
|
|
40
|
+
|
|
41
|
+
const targets = Object
|
|
42
|
+
.entries( firebasercContent.targets )
|
|
43
|
+
.reduce( ( prev, [ projectId, config ] ) => {
|
|
44
|
+
Object
|
|
45
|
+
.entries( config.hosting )
|
|
46
|
+
.forEach( ( [ siteId, aliases ] ) => {
|
|
47
|
+
aliases.forEach( ( alias ) => {
|
|
48
|
+
prev[alias] = {
|
|
49
|
+
projectId,
|
|
50
|
+
siteId,
|
|
51
|
+
alias
|
|
52
|
+
}
|
|
53
|
+
} )
|
|
54
|
+
} )
|
|
55
|
+
|
|
56
|
+
return prev
|
|
57
|
+
}, {} )
|
|
58
|
+
|
|
59
|
+
if ( !TARGET ) {
|
|
60
|
+
const { targetEnv } = await prompt( {
|
|
61
|
+
type : 'autocomplete',
|
|
62
|
+
name : 'targetEnv',
|
|
63
|
+
message : 'To which environment would you like to deploy?',
|
|
64
|
+
choices : Object.keys( targets ).map( t => ( { name : t, value : t } ) )
|
|
65
|
+
} )
|
|
66
|
+
|
|
67
|
+
TARGET = targets[targetEnv]
|
|
68
|
+
} else {
|
|
69
|
+
TARGET = targets[TARGET]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if ( !TARGET ) {
|
|
73
|
+
console.log( chalk.red( 'No such target exists in .firebaserc config.' ) )
|
|
74
|
+
process.exit()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const [ aliasFileExists, siteIdFileExists, sharedFileExists ] = await Promise.all( [
|
|
78
|
+
fs.exists( path.join( process.cwd(), SECRETS_DIR, `${TARGET.alias}.env` ) ),
|
|
79
|
+
fs.exists( path.join( process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env` ) ),
|
|
80
|
+
fs.exists( path.join( process.cwd(), SECRETS_DIR, 'shared.env' ) )
|
|
81
|
+
] )
|
|
82
|
+
|
|
83
|
+
if ( !aliasFileExists && !siteIdFileExists ) {
|
|
84
|
+
console.log( chalk.red( `No env file for ${TARGET.alias} exists. Check your secrets directory and try again` ) )
|
|
85
|
+
process.exit()
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const exec = []
|
|
89
|
+
|
|
90
|
+
if ( sharedFileExists ) {
|
|
91
|
+
exec.push( fs.readFile( path.join( process.cwd(), SECRETS_DIR, 'shared.env' ), { encoding : 'utf-8' } ) )
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if ( aliasFileExists ) {
|
|
95
|
+
exec.push( fs.readFile( path.join( process.cwd(), SECRETS_DIR, `${TARGET.alias}.env` ), { encoding : 'utf-8' } ) )
|
|
96
|
+
} else {
|
|
97
|
+
exec.push( fs.readFile( path.join( process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env` ), { encoding : 'utf-8' } ) )
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const envFileContent = ( await Promise.all( exec ) ).join( '\n' )
|
|
101
|
+
|
|
102
|
+
EXIT_EVENTS
|
|
103
|
+
.forEach( ( event ) => {
|
|
104
|
+
process.on( event, () => {
|
|
105
|
+
if ( !exited ) {
|
|
106
|
+
exited = true
|
|
107
|
+
fs.removeSync( path.join( process.cwd(), '.env.temp' ) )
|
|
108
|
+
}
|
|
109
|
+
} )
|
|
110
|
+
} )
|
|
111
|
+
|
|
112
|
+
await fs.writeFile( path.join( process.cwd(), '.env.temp' ), envFileContent )
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
await $`npm run clean && DOTENV_CONFIG_PATH=${path.join( process.cwd(), '.env.temp' )} npm run build && firebase use ${TARGET.projectId} && firebase deploy --only hosting:${TARGET.siteId}`
|
|
116
|
+
} catch ( err ) {
|
|
117
|
+
console.error( err )
|
|
118
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// https://github.com/google/zx
|
|
3
|
+
/* eslint-disable max-len */
|
|
4
|
+
import pkg from 'enquirer'
|
|
5
|
+
import { $, fs, argv, path, chalk } from 'zx'
|
|
6
|
+
|
|
7
|
+
const { prompt } = pkg
|
|
8
|
+
|
|
9
|
+
// This will preserve coloration from spawned child processes
|
|
10
|
+
process.env.FORCE_COLORS = 3
|
|
11
|
+
process.env.FORCE_COLOR = '1'
|
|
12
|
+
|
|
13
|
+
let TARGET = argv._[0]
|
|
14
|
+
let exited = false
|
|
15
|
+
|
|
16
|
+
const SECRETS_DIR = 'secrets'
|
|
17
|
+
const EXIT_EVENTS = [ 'SIGINT', 'exit', 'uncaughtException', 'unhandledRejection' ]
|
|
18
|
+
|
|
19
|
+
const [
|
|
20
|
+
firebaserc,
|
|
21
|
+
firebaseJson
|
|
22
|
+
] = await Promise.all( [
|
|
23
|
+
fs.exists( path.join( process.cwd(), '.firebaserc' ) ),
|
|
24
|
+
fs.exists( path.join( process.cwd(), 'firebase.json' ) )
|
|
25
|
+
] )
|
|
26
|
+
|
|
27
|
+
if ( !firebaserc ) {
|
|
28
|
+
console.log( chalk.red( 'No .firebaserc file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.' ) )
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if ( !firebaseJson ) {
|
|
32
|
+
console.log( chalk.red( 'No firebase.json file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.' ) )
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if ( !firebaserc || !firebaseJson ) {
|
|
36
|
+
process.exit()
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const firebasercContent = JSON.parse( await fs.readFile( path.join( process.cwd(), '.firebaserc' ), { encoding : 'utf-8' } ) )
|
|
40
|
+
|
|
41
|
+
const targets = Object
|
|
42
|
+
.entries( firebasercContent.targets )
|
|
43
|
+
.reduce( ( prev, [ projectId, config ] ) => {
|
|
44
|
+
Object
|
|
45
|
+
.entries( config.hosting )
|
|
46
|
+
.forEach( ( [ siteId, aliases ] ) => {
|
|
47
|
+
aliases.forEach( ( alias ) => {
|
|
48
|
+
prev[alias] = {
|
|
49
|
+
projectId,
|
|
50
|
+
siteId,
|
|
51
|
+
alias
|
|
52
|
+
}
|
|
53
|
+
} )
|
|
54
|
+
} )
|
|
55
|
+
|
|
56
|
+
return prev
|
|
57
|
+
}, {} )
|
|
58
|
+
|
|
59
|
+
if ( !TARGET ) {
|
|
60
|
+
const { targetEnv } = await prompt( {
|
|
61
|
+
type : 'autocomplete',
|
|
62
|
+
name : 'targetEnv',
|
|
63
|
+
message : 'Which environment would you like to serve?',
|
|
64
|
+
choices : Object.keys( targets ).map( t => ( { name : t, value : t } ) )
|
|
65
|
+
} )
|
|
66
|
+
|
|
67
|
+
TARGET = targets[targetEnv]
|
|
68
|
+
} else {
|
|
69
|
+
TARGET = targets[TARGET]
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if ( !TARGET ) {
|
|
73
|
+
console.log( chalk.red( 'No such target exists in .firebaserc config.' ) )
|
|
74
|
+
process.exit()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const [ aliasFileExists, siteIdFileExists, sharedFileExists ] = await Promise.all( [
|
|
78
|
+
fs.exists( path.join( process.cwd(), SECRETS_DIR, `${TARGET.alias}.env` ) ),
|
|
79
|
+
fs.exists( path.join( process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env` ) ),
|
|
80
|
+
fs.exists( path.join( process.cwd(), SECRETS_DIR, 'shared.env' ) )
|
|
81
|
+
] )
|
|
82
|
+
|
|
83
|
+
if ( !aliasFileExists && !siteIdFileExists ) {
|
|
84
|
+
console.log( chalk.red( `No env file for ${TARGET.alias} exists. Check your secrets directory and try again` ) )
|
|
85
|
+
process.exit()
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const exec = []
|
|
89
|
+
|
|
90
|
+
if ( sharedFileExists ) {
|
|
91
|
+
exec.push( fs.readFile( path.join( process.cwd(), SECRETS_DIR, 'shared.env' ), { encoding : 'utf-8' } ) )
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if ( aliasFileExists ) {
|
|
95
|
+
exec.push( fs.readFile( path.join( process.cwd(), SECRETS_DIR, `${TARGET.alias}.env` ), { encoding : 'utf-8' } ) )
|
|
96
|
+
} else {
|
|
97
|
+
exec.push( fs.readFile( path.join( process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env` ), { encoding : 'utf-8' } ) )
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const envFileContent = ( await Promise.all( exec ) ).join( '\n' )
|
|
101
|
+
|
|
102
|
+
EXIT_EVENTS
|
|
103
|
+
.forEach( ( event ) => {
|
|
104
|
+
process.on( event, () => {
|
|
105
|
+
if ( !exited ) {
|
|
106
|
+
exited = true
|
|
107
|
+
fs.removeSync( path.join( process.cwd(), '.env.temp' ) )
|
|
108
|
+
}
|
|
109
|
+
} )
|
|
110
|
+
} )
|
|
111
|
+
|
|
112
|
+
await fs.writeFile( path.join( process.cwd(), '.env.temp' ), envFileContent )
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
await $`DOTENV_CONFIG_PATH=${path.join( process.cwd(), '.env.temp' )} npm run serve --colors`
|
|
116
|
+
} catch ( err ) {
|
|
117
|
+
console.error( err )
|
|
118
|
+
}
|
package/src/helmup
CHANGED
|
@@ -140,13 +140,13 @@ function createNamespaceIfNeeded(){
|
|
|
140
140
|
function installPrometheus() {
|
|
141
141
|
# Add the community helm repositories
|
|
142
142
|
addHelmRepo prometheus-community https://prometheus-community.github.io/helm-charts
|
|
143
|
-
|
|
143
|
+
|
|
144
144
|
helm upgrade --install prometheus prometheus-community/prometheus \
|
|
145
145
|
--namespace monitoring \
|
|
146
146
|
--values prometheus/values.yaml \
|
|
147
|
-
--version
|
|
147
|
+
--version 13
|
|
148
148
|
|
|
149
|
-
|
|
149
|
+
# removeHelmRepo prometheus-community
|
|
150
150
|
}
|
|
151
151
|
|
|
152
152
|
function installRedis() {
|
|
@@ -208,17 +208,6 @@ replica:
|
|
|
208
208
|
values:
|
|
209
209
|
- database
|
|
210
210
|
REDIS_CHART_MODS
|
|
211
|
-
if [[ $? -ne 0 ]];
|
|
212
|
-
then
|
|
213
|
-
clearlyWarn noclear
|
|
214
|
-
cat<<OLDER_REDIS
|
|
215
|
-
The redis upgrade failed which may mean that the versions are different
|
|
216
|
-
enough that k8s cannot gracefully upgrade from one version to the next.
|
|
217
|
-
Try removing the existing deployment and redeploying redis:
|
|
218
|
-
|
|
219
|
-
$ `color r "helmdn redis && sleep 5 && helmup redis"`
|
|
220
|
-
OLDER_REDIS
|
|
221
|
-
fi
|
|
222
211
|
printf "\n\nTo start a specific version => `color g 'REDIS_HELM_CHART="13.0.1" helmup redis'`\n\n"
|
|
223
212
|
removeHelmRepo bitnami
|
|
224
213
|
}
|
|
@@ -389,7 +378,7 @@ function getManagedSecret() {
|
|
|
389
378
|
|
|
390
379
|
# https://github.com/estafette/estafette-gke-preemptible-killer
|
|
391
380
|
function installPreemptibleKiller() {
|
|
392
|
-
showInstalling "Preemptible Node Killing
|
|
381
|
+
showInstalling "Preemptible Node Killing Adjusticator"
|
|
393
382
|
NAMESPACE="estafette"
|
|
394
383
|
PROJECT_ID="$(getProjectIdFromK8sContext)"
|
|
395
384
|
SVC_ACCT="preemptible-killer"
|
|
@@ -726,7 +715,7 @@ function installVelero() {
|
|
|
726
715
|
## Helpful debugging link => https://github.com/vmware-tanzu/helm-charts/issues/351
|
|
727
716
|
addHelmRepo vmware-tanzu https://vmware-tanzu.github.io/helm-charts
|
|
728
717
|
helm upgrade --install velero vmware-tanzu/velero \
|
|
729
|
-
--version 2 \
|
|
718
|
+
--version 2.29 \
|
|
730
719
|
--namespace velero \
|
|
731
720
|
--set credentials.useSecret="false" \
|
|
732
721
|
--set configuration.provider="gcp" \
|