@leverege/build-tools 2.38.2 → 2.39.0-beta.2

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.
Files changed (45) hide show
  1. package/package.json +12 -16
  2. package/src/Utils.mjs +30 -0
  3. package/src/{build-tools.js → build-tools.mjs} +28 -12
  4. package/src/circle-lib.yml +150 -0
  5. package/src/circle-srv.yml +213 -0
  6. package/src/firebaseDeploy.mjs +2 -1
  7. package/src/firebaseServe.mjs +2 -1
  8. package/src/getjson.mjs +3 -3
  9. package/src/helm-charts/firebase-rules/.nohelm +0 -0
  10. package/src/helm-charts/firebase-rules/firebase.json +5 -0
  11. package/src/helm-charts/firebase-rules/firebaserc.ovh +24 -0
  12. package/src/helm-charts/firebase-rules/gitignore +2 -0
  13. package/src/helm-charts/firebase-rules/helmup.plugin +14 -0
  14. package/src/helm-charts/firebase-rules/leverege.rules.json +65 -0
  15. package/src/helm-charts/geotile-server/.nohelm +0 -0
  16. package/src/helm-charts/geotile-server/gitignore +1 -0
  17. package/src/helm-charts/geotile-server/helmup.plugin +6 -0
  18. package/src/helm-charts/velero/helmup.plugin +16 -0
  19. package/src/helmup.sh +47 -1
  20. package/src/overwhelm.mjs +55 -63
  21. package/src/push-my-chart.mjs +7 -6
  22. package/src/refresh-npm-token.mjs +142 -40
  23. package/src/unleash.mjs +4 -2
  24. package/leverege-build-tools-2.21.13.tgz +0 -0
  25. package/lib/server/build-tools.js +0 -138
  26. package/lib/server/firebaseDeploy.js +0 -195
  27. package/lib/server/firebaseServe.js +0 -116
  28. package/lib/server/getfbcfg.js +0 -25
  29. package/lib/server/getjson.js +0 -70
  30. package/lib/server/overwhelm.js +0 -447
  31. package/lib/server/push-my-chart.js +0 -18
  32. package/lib/server/refresh-npm-token.js +0 -135
  33. package/lib/server/tag-release.js +0 -681
  34. package/lib/server/unleash.js +0 -50
  35. package/lib/web/build-tools.js +0 -138
  36. package/lib/web/firebaseDeploy.js +0 -195
  37. package/lib/web/firebaseServe.js +0 -116
  38. package/lib/web/getfbcfg.js +0 -25
  39. package/lib/web/getjson.js +0 -70
  40. package/lib/web/overwhelm.js +0 -447
  41. package/lib/web/push-my-chart.js +0 -18
  42. package/lib/web/refresh-npm-token.js +0 -135
  43. package/lib/web/tag-release.js +0 -681
  44. package/lib/web/unleash.js +0 -50
  45. package/src/overwhelm.js +0 -396
@@ -1,116 +0,0 @@
1
- #!/usr/bin/env node
2
- // https://github.com/google/zx
3
- /* eslint-disable max-len */
4
- /* eslint-disable no-console */
5
- "use strict";
6
-
7
- var _enquirer = _interopRequireDefault(require("enquirer"));
8
- var _zx = require("zx");
9
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
- const {
11
- prompt
12
- } = _enquirer.default;
13
-
14
- // This will preserve coloration from spawned child processes
15
- process.env.FORCE_COLORS = 3;
16
- process.env.FORCE_COLOR = '1';
17
- let TARGET = _zx.argv._[0];
18
- let exited = false;
19
- const SECRETS_DIR = 'secrets';
20
- const EXIT_EVENTS = ['SIGINT', 'exit', 'uncaughtException', 'unhandledRejection'];
21
- const [firebaserc, firebaseJson, hasLocalConfig] = await Promise.all([_zx.fs.exists(_zx.path.join(process.cwd(), '.firebaserc')), _zx.fs.exists(_zx.path.join(process.cwd(), 'firebase.json')), _zx.fs.exists(_zx.path.join(process.cwd(), SECRETS_DIR, 'local.env'))]);
22
- if (!hasLocalConfig) {
23
- if (!firebaserc) {
24
- console.log(_zx.chalk.red('No .firebaserc file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
25
- }
26
- if (!firebaseJson) {
27
- console.log(_zx.chalk.red('No firebase.json file found. Make sure that you are executing firebaseDeploy from within a firebase project directory.'));
28
- }
29
- if (!firebaserc || !firebaseJson) {
30
- process.exit();
31
- }
32
- }
33
- const firebasercContent = firebaserc ? JSON.parse(await _zx.fs.readFile(_zx.path.join(process.cwd(), '.firebaserc'), {
34
- encoding: 'utf-8'
35
- })) : {
36
- targets: {}
37
- };
38
- const defaultTargets = {};
39
- if (hasLocalConfig) {
40
- defaultTargets.local = {
41
- siteId: 'local',
42
- alias: 'local'
43
- };
44
- }
45
- const targets = Object.entries(firebasercContent.targets).reduce((prev, [projectId, config]) => {
46
- Object.entries(config.hosting).forEach(([siteId, aliases]) => {
47
- aliases.forEach(alias => {
48
- prev[alias] = {
49
- projectId,
50
- siteId,
51
- alias
52
- };
53
- });
54
- });
55
- return prev;
56
- }, defaultTargets);
57
- if (!TARGET) {
58
- const choices = Object.keys(targets).map(t => ({
59
- name: t,
60
- value: t
61
- }));
62
- let targetEnv;
63
- if (choices.length > 1) {
64
- const res = await prompt({
65
- type: 'autocomplete',
66
- name: 'targetEnv',
67
- message: 'Which environment would you like to serve?',
68
- choices
69
- });
70
- targetEnv = res.targetEnv;
71
- } else {
72
- targetEnv = choices[0].value;
73
- }
74
- TARGET = targets[targetEnv];
75
- } else {
76
- TARGET = targets[TARGET];
77
- }
78
- if (!TARGET) {
79
- console.log(_zx.chalk.red('No such target exists in .firebaserc config.'));
80
- process.exit();
81
- }
82
- 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'))]);
83
- if (!aliasFileExists && !siteIdFileExists) {
84
- console.log(_zx.chalk.red(`No env file for ${TARGET.alias} exists. Check your secrets directory and try again`));
85
- process.exit();
86
- }
87
- const exec = [];
88
- if (sharedFileExists) {
89
- exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, 'shared.env'), {
90
- encoding: 'utf-8'
91
- }));
92
- }
93
- if (aliasFileExists) {
94
- exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.alias}.env`), {
95
- encoding: 'utf-8'
96
- }));
97
- } else {
98
- exec.push(_zx.fs.readFile(_zx.path.join(process.cwd(), SECRETS_DIR, `${TARGET.siteId}.env`), {
99
- encoding: 'utf-8'
100
- }));
101
- }
102
- const envFileContent = (await Promise.all(exec)).join('\n');
103
- EXIT_EVENTS.forEach(event => {
104
- process.on(event, () => {
105
- if (!exited) {
106
- exited = true;
107
- _zx.fs.removeSync(_zx.path.join(process.cwd(), '.env.temp'));
108
- }
109
- });
110
- });
111
- await _zx.fs.writeFile(_zx.path.join(process.cwd(), '.env.temp'), envFileContent);
112
- try {
113
- await (0, _zx.$)`DOTENV_CONFIG_PATH=${_zx.path.join(process.cwd(), '.env.temp')} DEPLOYMENT_TARGET=${TARGET.siteId} npm run serve --colors`;
114
- } catch (err) {
115
- console.error(err);
116
- }
@@ -1,25 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * This script parses a firebase config into something useful.
5
- *
6
- * firebase --project leverege-dev-john apps:sdkconfig | getfbcfg
7
- */
8
- "use strict";
9
-
10
- const stdbuf = [];
11
-
12
- /* eslint-disable no-console */
13
- process.stdin.on('data', d => {
14
- stdbuf.push(d);
15
- }).on('end', () => {
16
- const rawCfg = stdbuf.join('').replace(/["\n\r]/g, '');
17
- const keyVals = rawCfg.match(/\{(.*)\}/)[1].split(',');
18
- const lastLine = keyVals.length - 1;
19
- console.log('{');
20
- for (let i = 0; i <= lastLine; i++) {
21
- const kv = keyVals[i].trim().split(' ');
22
- console.log(` "${kv[0].replace(/:/, '')}": "${kv[1]}"${i < lastLine ? ',' : ''}`);
23
- }
24
- console.log('}');
25
- }).setEncoding('utf8');
@@ -1,70 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * This script will allow the user to grab a value from a JSON file and
5
- * optionally apply a regular expression to it. Given this test.json file:
6
- *
7
- * {
8
- * "name": "@leverege/packagename",
9
- * "main": "lib/index.js"
10
- * }
11
- *
12
- * and invoking as:
13
- * ./getjson --file ./test.json --key name --regex "^@\w{3}"
14
- *
15
- * will yield an output of: @lev
16
- */
17
-
18
- /**
19
- * Get a command line switch parser.
20
- */
21
- "use strict";
22
-
23
- var _fs = _interopRequireDefault(require("fs"));
24
- var _commandLineArgs = _interopRequireDefault(require("command-line-args"));
25
- var _commandLineUsage = _interopRequireDefault(require("command-line-usage"));
26
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
- /* eslint-disable no-console */
28
- const optionList = [
29
- // Use optionList to tie into the Usage statements
30
- {
31
- name: 'file',
32
- type: String,
33
- alias: 'f',
34
- description: 'file to parse JSON from'
35
- }, {
36
- name: 'key',
37
- type: String,
38
- alias: 'k',
39
- description: 'JSON key whose value to grab'
40
- }, {
41
- name: 'regex',
42
- type: String,
43
- alias: 'r',
44
- description: 'regular expression to apply to the value'
45
- }];
46
- const sections = [{
47
- header: 'JSON variable fetching script',
48
- content: ` This script is intended to give shell scripts a simple JSON
49
- parsing capability.`
50
- }, {
51
- header: 'Options',
52
- optionList
53
- }];
54
- const args = (0, _commandLineArgs.default)(optionList, {
55
- partial: true
56
- });
57
- const help = (0, _commandLineUsage.default)(sections);
58
- if (!args.file) {
59
- console.error('\n***ERROR: Missing a --file param\n');
60
- console.log(help);
61
- process.exit(1);
62
- }
63
- try {
64
- const json = JSON.parse(_fs.default.readFileSync(args.file, 'utf8'));
65
- const value = json[args.key];
66
- const match = new RegExp(args.regex || '.*').exec(value);
67
- console.log(match ? match[match.length - 1] : '');
68
- } catch (e) {
69
- console.log(e);
70
- }
@@ -1,447 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // XXX console.log( `TOP=>[${process.cwd()}] PWD=[${process.env.PWD}]` )
4
- /* eslint-disable no-console */
5
- /* eslint-disable security/detect-non-literal-fs-filename */
6
- "use strict";
7
-
8
- var _nodePath = _interopRequireDefault(require("node:path"));
9
- var _nodeChild_process = require("node:child_process");
10
- var _nodeFs = _interopRequireDefault(require("node:fs"));
11
- var _chalk = _interopRequireDefault(require("chalk"));
12
- var _commandLineArgs = _interopRequireDefault(require("command-line-args"));
13
- var _deepmerge = _interopRequireDefault(require("deepmerge"));
14
- var _glob = _interopRequireDefault(require("glob"));
15
- var _parseGitignore = _interopRequireDefault(require("parse-gitignore"));
16
- var _readlineSync = _interopRequireDefault(require("readline-sync"));
17
- var _jsYaml = _interopRequireDefault(require("js-yaml"));
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
- // const cliHelp = require( 'command-line-usage' )
20
- const optionsDefinitions = [/* eslint-disable no-multi-spaces */
21
- {
22
- name: 'context',
23
- alias: 'x',
24
- type: String,
25
- default: ''
26
- }, {
27
- name: 'section',
28
- alias: 's',
29
- type: String,
30
- default: 'default'
31
- }, {
32
- name: 'key',
33
- alias: 'k',
34
- type: String
35
- }, {
36
- name: 'export',
37
- alias: 'e',
38
- type: Boolean,
39
- default: false
40
- }, {
41
- name: 'continue',
42
- alias: 'c',
43
- type: Boolean,
44
- default: false
45
- }, {
46
- name: 'checkctx',
47
- alias: 't',
48
- type: Boolean,
49
- default: false
50
- },
51
- // checks overwhelm context
52
- {
53
- name: 'fetchctx',
54
- alias: 'f',
55
- type: Boolean,
56
- default: false
57
- },
58
- // fetch and set k8s context
59
- {
60
- name: 'genvals',
61
- alias: 'g',
62
- type: Boolean,
63
- default: false
64
- },
65
- // only generates values.yaml
66
- {
67
- name: 'matchk8s',
68
- alias: 'm',
69
- type: Boolean,
70
- default: false
71
- },
72
- // checks k8s context
73
- {
74
- name: 'verbose',
75
- alias: 'v',
76
- type: Boolean,
77
- default: false
78
- }
79
- /* eslint-enable no-multi-spaces */];
80
-
81
- const args = (0, _commandLineArgs.default)(optionsDefinitions);
82
-
83
- // See if we are in a monorepo, which changes some of the rules.
84
- const gitTop = (0, _nodeChild_process.execSync)('git rev-parse --show-toplevel', {
85
- stdio: [undefined]
86
- }).toString().trim();
87
- let monoTop;
88
- if (_nodeFs.default.existsSync(`${gitTop}/packages`)) {
89
- monoTop = _nodePath.default.basename(_nodePath.default.resolve()); // process.env.PWD
90
- console.log(`MONO=[${monoTop}]`);
91
- }
92
-
93
- // The kubernetes context is equal to the git branch name.
94
- const gitBranch = (0, _nodeChild_process.execSync)('git rev-parse --abbrev-ref HEAD', {
95
- stdio: [undefined]
96
- }).toString().trim();
97
- const context = args.context || monoTop || gitBranch;
98
- if (context === 'master') {
99
- console.log('***ERROR: master context is forbidden; change to a different branch\n\n');
100
- process.exit(1);
101
- }
102
- if (!_nodeFs.default.existsSync('overwhelm.yaml')) {
103
- console.log(_chalk.default.red.bold(`
104
-
105
- ***ERROR overwhelm => missing the overwhelm.yaml file - this command expects
106
- to execute from within a platform-k8s branch
107
- `));
108
- process.exit(1);
109
- }
110
-
111
- // Load the default values and then overlay with the project specific yaml
112
- // values. This supports the notion of this type of approach in the
113
- // overwhelm yaml settings:
114
- // default:
115
- // GCE_MACHINE : "n1-standard-2"
116
- //
117
- // my-project:
118
- // GCE_MACHINE : "n1-highcpu-8"
119
- //
120
- // fashion, but it is advised not to set a default region with this
121
- // approach in order to keep us cognizant of exactly where a cluster is
122
- // being formed.
123
- //
124
- const yaml = _jsYaml.default.load(_nodeFs.default.readFileSync('overwhelm.yaml', 'utf-8'));
125
- const over = yaml.default;
126
- if (process.env.OVERWHELM_DEBUG) {
127
- console.log({
128
- over,
129
- yaml
130
- }, '<==Contents of the over and yaml structs');
131
- }
132
- let cfgs = yaml[context];
133
-
134
- // If we just need to check context return 0 if cfgs exists, else error.
135
- if (args.checkctx) {
136
- process.exit(!cfgs);
137
- }
138
- if (!cfgs) {
139
- console.log(`***ERROR: Unknown context => [${context}]\n`);
140
- console.log(' Known k8s contexts are:');
141
- Object.keys(yaml).forEach(key => {
142
- if (key !== 'default') {
143
- console.log(` ${key}`);
144
- }
145
- });
146
- console.log(`Add a section into overwhelm.yaml for ${context}\n\n`);
147
- process.exit(1);
148
- }
149
-
150
- // Check to see if we are deriving from another configuration.
151
- if (cfgs.PROJECT_BASE) {
152
- const baseName = cfgs.PROJECT_BASE;
153
- const tempCfgs = cfgs;
154
- cfgs = yaml[baseName];
155
- Object.keys(tempCfgs).forEach(key => {
156
- cfgs[key] = tempCfgs[key];
157
- });
158
- console.log('PROJECT_BASE still under evaluation');
159
- console.log('\n cfgs=', cfgs);
160
- process.exit(1); // XXX HERE
161
- }
162
-
163
- Object.keys(cfgs).forEach(key => {
164
- over[key] = cfgs[key] || over[key];
165
- });
166
-
167
- // Expand any variables that reference other variable settings. A perfect
168
- // example of where this is useful is in the setting of a PROJECT_NAME and
169
- // a PROJECT_ID. Most of the time these values are identical, which is why
170
- // this setting exists in the default section:
171
- // default:
172
- // PROJECT_ID : ${PROJECT_NAME}
173
- //
174
- // However, in the case of projects like Siren Marine, this is the more
175
- // likely setup due to legacy naming schemes:
176
- // sire-marine:
177
- // PROJECT_NAME : siren-marine
178
- // PROJECT_ID : prod-rt-data
179
- //
180
- const varErrors = [];
181
- Object.keys(over).forEach(key => {
182
- if (!over[key]) return; // no value to work with - skip it
183
-
184
- // Look for something in the form of "thing-${VAR1}-${VAR2}-${VARn}-stuff"
185
- const matches = over[key].match(/\$\{\w+\}/g);
186
- if (!matches) return;
187
- matches.forEach(replaceThis => {
188
- // The matched variable names will be in the form of ${VARNAME} so drop
189
- // the ${} characters before using the VARNAME to map into the
190
- // overwhelm map containing the desired replacement value.
191
- const withThat = over[replaceThis.replace(/\W+/g, '')];
192
- if (!withThat) {
193
- varErrors.push(`${key} : ${over[key]}`);
194
- return;
195
- }
196
- // Store the replaced string back in the overwhelm value map.
197
- over[key] = over[key].replace(replaceThis, withThat);
198
- });
199
- });
200
- if (varErrors.length > 0) {
201
- console.log('***ERROR: unkown variable reference(s) in overwhelm.yaml:\n');
202
- varErrors.forEach(error => {
203
- console.log(` ${error}`);
204
- });
205
- console.log('');
206
- process.exit(1);
207
- }
208
-
209
- // Grab a list of the existing yaml templates.
210
- const yams = _glob.default.sync('values-*.yaml');
211
-
212
- // A function to apply the replacements to all of the matching yaml which
213
- // will error out if it runs into an unknown OVH<tag>.
214
- const doReplacements = (yamls, replacements) => {
215
- let replYaml = yamls;
216
-
217
- // wrap special chars with quotes if needed, like "#---incident-alerts---"
218
- const quoteSpecials = raw => {
219
- return /[#$?*]/g.test(raw) ? `"${raw}"` : raw;
220
- };
221
- Object.keys(replacements).forEach(repl => {
222
- const replaceThis = new RegExp(`OVH:<${repl}>`, 'g');
223
- const withThat = quoteSpecials(`${replacements[repl]}`);
224
- replYaml = replYaml.replace(replaceThis, withThat);
225
- });
226
-
227
- // Verify all replaceables have been handled, or error out.
228
- const missed = replYaml.match(/OVH:<(.*)>/g);
229
- if (missed) {
230
- console.log('\n***ERROR: missing replacements in overwhelm.yaml for these tags:\n');
231
- missed.forEach(miss => {
232
- console.log(` TAG: ${miss.match(/OVH:<(.*)>/)[1]}`);
233
- });
234
- console.log('');
235
- process.exit(1);
236
- }
237
- return replYaml;
238
- };
239
-
240
- // Collect all of the yaml from the yams...
241
- const buildYaml = (yamls, replacements) => {
242
- const always = ['values-default.yaml'];
243
- const values = [...always, ...yamls];
244
- const loaded = [];
245
- let allYamls = '';
246
- values.forEach(yaml => {
247
- if (!_nodeFs.default.existsSync(yaml)) {
248
- console.log(`\n***ERROR: yaml file missing => ${yaml}\n`);
249
- process.exit(1);
250
- }
251
- if (!loaded.includes(yaml)) {
252
- allYamls += `\n# AHOY => ${yaml}\n\n`;
253
- allYamls += _nodeFs.default.readFileSync(yaml, {
254
- encoding: 'utf-8'
255
- });
256
- loaded.push(yaml);
257
- }
258
- });
259
-
260
- // Now apply all of the replacements from the overwhelm file.
261
- return doReplacements(allYamls, replacements);
262
- };
263
-
264
- // Call buildYaml to replace the OVH strings in the yaml files.
265
- const values = buildYaml(yams, over);
266
-
267
- // Check to see if someone is requesting a value from the yaml.
268
- if (args.key) {
269
- const section = args.section || 'default';
270
- const keys = yaml[section];
271
- if (args.verbose) {
272
- console.log('replacements');
273
- console.log(keys);
274
- }
275
- if (args.export) {
276
- console.log(`export ${args.key}=${keys[args.key]}`);
277
- } else {
278
- console.log(keys[args.key]);
279
- }
280
- if (!args.continue) process.exit();
281
- }
282
-
283
- // Find all of the potential target dirs. Utilize .gitignore to ignore files
284
- const gitignore = (0, _parseGitignore.default)(_nodeFs.default.readFileSync('.gitignore'));
285
- const opt = {
286
- ignore: gitignore.patterns
287
- };
288
- const ahoy = _glob.default.sync('*/', opt);
289
-
290
- // .noahoy = skips generation of values.yaml but allows helmup to run
291
- // .nohelm = overwhelm and helmup will skip the deployment entirely
292
- ahoy.forEach(dir => {
293
- if (_nodeFs.default.existsSync(`${dir}/.noahoy`)) {
294
- !args.fetchctx && console.log(_chalk.default.yellow(`***WARNING: .noahoy detected, not regenerating ${dir}values.yaml`));
295
- } else if (!_nodeFs.default.existsSync(`${dir}/.nohelm`)) {
296
- args.verbose && console.log(`Generating values in ${dir}`); // eslint-disable-line no-unused-expressions
297
-
298
- let valuesOut = []; // An accumulator for all of the output values.
299
-
300
- // Add support for localized values for things like keel (or whatever)
301
- const valuesLocal = `${dir}values-local.yaml`;
302
- if (_nodeFs.default.existsSync(valuesLocal)) {
303
- args.verbose && console.log(` Local values in ${valuesLocal}`); // eslint-disable-line no-unused-expressions
304
- valuesOut += '\n# AHOY => values-local.yaml\n\n';
305
- valuesOut += _nodeFs.default.readFileSync(valuesLocal, {
306
- encoding: 'utf-8'
307
- });
308
- }
309
- valuesOut += `\n${values}`;
310
-
311
- // Augment the default service section of the YAML with settings that
312
- // usually come from the top level overwhelm.yaml file.
313
- //
314
- const valuesAll = _jsYaml.default.load(valuesOut) || {};
315
- const valuesSvc = {
316
- service: {
317
- project_id: 'OVH:<PROJECT_ID>',
318
- project_name: 'OVH:<PROJECT_NAME>',
319
- host: 'OVH:<HOST>',
320
- ingress: 'OVH:<INGRESS>'
321
- }
322
- };
323
- const valuesMerged = _jsYaml.default.dump((0, _deepmerge.default)(valuesSvc, valuesAll), {
324
- quotingType: '"'
325
- });
326
- valuesOut = doReplacements(valuesMerged, over);
327
-
328
- // DEPRECATED once siren and manheim are platform 4.0
329
- // If we are going to override then we need to convert it to YAML and
330
- // do a deepmerge to combine the values.
331
- const valuesOverride = `${dir}/values-override.yaml`;
332
- if (_nodeFs.default.existsSync(valuesOverride)) {
333
- console.log(`===>Applying Overrides=> ${valuesOverride}`);
334
- const overrides = _jsYaml.default.load(_nodeFs.default.readFileSync(valuesOverride, {
335
- encofind: 'utf-8'
336
- }));
337
- const allValues = _jsYaml.default.load(valuesOut);
338
- valuesOut = _jsYaml.default.dump((0, _deepmerge.default)(allValues, overrides), {
339
- quotingType: '"'
340
- });
341
- }
342
- // DEPRECATED
343
-
344
- _nodeFs.default.writeFileSync(`${dir}/values.yaml`, valuesOut);
345
- }
346
- });
347
-
348
- // we can also apply replaceables to any top level .ovh files to support top level config maps
349
- _glob.default.sync('**/*.ovh').forEach(cfgmap => {
350
- const target = cfgmap.replace(/.ovh$/, '');
351
- let valuesOut = _nodeFs.default.readFileSync(cfgmap, {
352
- encoding: 'utf-8'
353
- });
354
- valuesOut = doReplacements(valuesOut, over);
355
- _nodeFs.default.writeFileSync(target, valuesOut);
356
- });
357
- if (args.genvals) {
358
- process.exit(0);
359
- }
360
-
361
- // Set the GCP context for safety!
362
- const clusterName = over.CLUSTER_NAME;
363
- if (over.PROJECT_NAME === 'minikube') {
364
- process.exit(0);
365
- }
366
- const projectId = over.PROJECT_ID;
367
- const zone = over.GCE_REGION + (over.GCE_ZONE ? `-${over.GCE_ZONE}` : '');
368
- if (!clusterName) {
369
- console.log(_chalk.default.yellow(`
370
-
371
- The overwhelm.yaml file in this branch is missing a CLUSTER_NAME setting,
372
- which was added to support cluster names that do not match the project
373
- name. Since the mismatch is rare, you can probably get by with simply
374
- adding this line following PROJECT_NAME in the default section of
375
- overwhelm.yaml:
376
-
377
- ${_chalk.default.bold.green('CLUSTER_NAME : \'${PROJECT_NAME}\'')}
378
-
379
- However, if the CLUSTER_NAME is not the same as the PROJECT_NAME then go
380
- ahead and add the CLUSTER_NAME setting to the ${_chalk.default.bold.green(projectId)} section of the
381
- overwhelm.yaml file.
382
-
383
- `));
384
- process.exit(1);
385
- }
386
- let kubeout = '_no_current_context_';
387
- try {
388
- kubeout = (0, _nodeChild_process.execSync)('kubectl config current-context', {
389
- stdio: [undefined]
390
- });
391
- } catch (err) {
392
- // err && console.log( `Caught Error =>[${err}]` )
393
- }
394
- const currentCtx = kubeout.toString().trim();
395
- const desiredCtx = `gke_${projectId}_${zone}_${clusterName}`;
396
- const cmd = `gcloud container clusters get-credentials ${clusterName} --zone ${zone} --project ${projectId}`;
397
- const matchedCtx = currentCtx === desiredCtx;
398
- if (args.matchk8s) {
399
- process.exit(matchedCtx ? 0 : 1);
400
- }
401
-
402
- // just fetch the context and exit if -f is specified
403
- if (args.fetchctx) {
404
- if (!matchedCtx) {
405
- try {
406
- (0, _nodeChild_process.execSync)(`${cmd}`, {
407
- stdio: [undefined]
408
- });
409
- } catch (err) {
410
- process.exit(61); // ECONNREFUSED
411
- }
412
- }
413
-
414
- process.exit(0);
415
- }
416
- if (matchedCtx) {
417
- console.log(`
418
-
419
- Current context matches => ${_chalk.default.bold.green(currentCtx)}
420
-
421
- `);
422
- } else {
423
- console.log(`
424
- You are about to change your Kubernetes context to:
425
- CLUSTER_NAME => ${_chalk.default.bold.green(clusterName)}
426
- PROJECT_ID => ${_chalk.default.bold.green(projectId)}
427
- REGION => ${_chalk.default.bold.green(zone)}
428
-
429
- `);
430
- }
431
- const operation = matchedCtx ? 'refetch the credentials' : 'switch your context';
432
- const ans = _readlineSync.default.question(`Enter "${_chalk.default.bold.green('yes')}" if you wish to ${operation} => `);
433
- if (ans !== 'yes') {
434
- if (matchedCtx) {
435
- console.log(_chalk.default.bold.yellow('\n\nSkipping a refetch of your Kubernetes context and credentials\n\n'));
436
- process.exit(0);
437
- }
438
- console.log(_chalk.default.bold.red('\n\nYour Kubernetes context and credentials do NOT match - this could be bad!\n\n'));
439
- process.exit(1);
440
- }
441
- console.log(`\n\nExecuting: ${_chalk.default.bold.yellow(cmd)}\n\n`);
442
- (0, _nodeChild_process.execSync)(`${cmd}`, (error, out) => {
443
- if (error) {
444
- console.log(`\n\n***ERROR ${error}\n\n`);
445
- process.exit(1);
446
- }
447
- });
@@ -1,18 +0,0 @@
1
- #!/usr/bin/env node
2
- "use strict";
3
-
4
- var _execa = _interopRequireDefault(require("execa"));
5
- var _semver = require("semver");
6
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
- const pushItGood = async () => {
8
- const version = await (0, _execa.default)('helm', ['version', '--short']);
9
- const pusher = (0, _semver.lt)(version.stdout, '3.7.0') ? 'push' : 'cm-push';
10
- try {
11
- const museum = await (0, _execa.default)('helm', [pusher, 'helm', 'leverege']);
12
- console.log(museum.stdout); // eslint-disable-line no-console
13
- } catch (ex) {
14
- console.log(ex.stderr); // eslint-disable-line no-console
15
- process.exit(1);
16
- }
17
- };
18
- pushItGood();