@opencrvs/toolkit 2.0.0-rc.ec87222 → 2.0.0-rc.ed0aa22

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 (93) hide show
  1. package/README.md +15 -0
  2. package/build.sh +3 -2
  3. package/dist/application-config/index.js +23 -6
  4. package/dist/cli.js +3253 -47
  5. package/dist/commons/api/router.d.ts +21 -2
  6. package/dist/commons/conditionals/conditionals.d.ts +3 -3
  7. package/dist/commons/events/ActionConfig.d.ts +35 -2
  8. package/dist/commons/events/AdvancedSearchConfig.d.ts +12 -0
  9. package/dist/commons/events/CountryConfigQueryInput.d.ts +42 -0
  10. package/dist/commons/events/EventConfig.d.ts +2 -0
  11. package/dist/commons/events/EventIndex.d.ts +25 -0
  12. package/dist/commons/events/EventMetadata.d.ts +26 -0
  13. package/dist/commons/events/FieldConfig.d.ts +11 -0
  14. package/dist/commons/events/FieldType.d.ts +1 -0
  15. package/dist/commons/events/FieldTypeMapping.d.ts +1 -1
  16. package/dist/commons/events/WorkqueueConfig.d.ts +39 -0
  17. package/dist/commons/events/locations.d.ts +1 -0
  18. package/dist/commons/events/state/index.d.ts +8 -0
  19. package/dist/commons/events/state/utils.d.ts +9 -0
  20. package/dist/commons/events/utils.d.ts +8 -0
  21. package/dist/conditionals/index.js +10 -5
  22. package/dist/environment/custom-types.d.ts +33 -0
  23. package/dist/environment/custom-types.d.ts.map +1 -0
  24. package/dist/environment/custom-types.js +12 -0
  25. package/dist/environment/derived-variables.d.ts +134 -0
  26. package/dist/environment/derived-variables.d.ts.map +1 -0
  27. package/dist/environment/derived-variables.js +169 -0
  28. package/dist/environment/editor-questions.d.ts +4 -0
  29. package/dist/environment/editor-questions.d.ts.map +1 -0
  30. package/dist/environment/editor-questions.js +67 -0
  31. package/dist/environment/git.d.ts +5 -0
  32. package/dist/environment/git.d.ts.map +1 -0
  33. package/dist/environment/git.js +38 -0
  34. package/dist/environment/github.d.ts +26 -0
  35. package/dist/environment/github.d.ts.map +1 -0
  36. package/dist/environment/github.js +247 -0
  37. package/dist/environment/index.d.ts +5 -0
  38. package/dist/environment/index.d.ts.map +1 -0
  39. package/dist/environment/index.js +71 -0
  40. package/dist/environment/logger.d.ts +15 -0
  41. package/dist/environment/logger.d.ts.map +1 -0
  42. package/dist/environment/logger.js +25 -0
  43. package/dist/environment/manage-users.d.ts +11 -0
  44. package/dist/environment/manage-users.d.ts.map +1 -0
  45. package/dist/environment/manage-users.js +497 -0
  46. package/dist/environment/questions-helper.d.ts +15 -0
  47. package/dist/environment/questions-helper.d.ts.map +1 -0
  48. package/dist/environment/questions-helper.js +70 -0
  49. package/dist/environment/questions.d.ts +199 -0
  50. package/dist/environment/questions.d.ts.map +1 -0
  51. package/dist/environment/questions.js +412 -0
  52. package/dist/environment/setup-environment.d.ts +2 -0
  53. package/dist/environment/setup-environment.d.ts.map +1 -0
  54. package/dist/environment/setup-environment.js +794 -0
  55. package/dist/environment/ssh-keygen.d.ts +5 -0
  56. package/dist/environment/ssh-keygen.d.ts.map +1 -0
  57. package/dist/environment/ssh-keygen.js +21 -0
  58. package/dist/environment/swarm-to-k8s.d.ts +2 -0
  59. package/dist/environment/swarm-to-k8s.d.ts.map +1 -0
  60. package/dist/environment/swarm-to-k8s.js +173 -0
  61. package/dist/environment/templates.d.ts +27 -0
  62. package/dist/environment/templates.d.ts.map +1 -0
  63. package/dist/environment/templates.js +163 -0
  64. package/dist/environment/update-workflows.d.ts +2 -0
  65. package/dist/environment/update-workflows.d.ts.map +1 -0
  66. package/dist/environment/update-workflows.js +169 -0
  67. package/dist/environment/users.d.ts +2 -0
  68. package/dist/environment/users.d.ts.map +1 -0
  69. package/dist/environment/users.js +112 -0
  70. package/dist/environment/utils.d.ts +18 -0
  71. package/dist/environment/utils.d.ts.map +1 -0
  72. package/dist/environment/utils.js +100 -0
  73. package/dist/events/index.js +226 -77
  74. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +1 -1
  75. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +1 -1
  76. package/dist/migrations/v2.0/checkout-upstream-files.js +1 -1
  77. package/dist/migrations/v2.0/index.js +11 -6
  78. package/dist/notification/index.js +132 -17
  79. package/dist/scopes/index.d.ts +89 -1
  80. package/dist/scopes/index.js +10 -5
  81. package/dist/templates/charts-values/dependencies/values.override.yaml +4 -0
  82. package/dist/templates/charts-values/dependencies/values.yaml +83 -0
  83. package/dist/templates/charts-values/opencrvs-services/values.override.yaml +4 -0
  84. package/dist/templates/charts-values/opencrvs-services/values.yaml +81 -0
  85. package/dist/templates/charts-values/traefik/values.override.yaml +4 -0
  86. package/dist/templates/charts-values/traefik/values.yaml +115 -0
  87. package/dist/templates/inventory/inventory.template.yml +100 -0
  88. package/dist/templates/inventory/production.example.yml +77 -0
  89. package/dist/templates/inventory/qa.example.yml +48 -0
  90. package/opencrvs-toolkit-2.0.0-rc.ed0aa22.tgz +0 -0
  91. package/package.json +15 -1
  92. package/tsconfig.tsbuildinfo +1 -1
  93. package/opencrvs-toolkit-2.0.0-rc.ec87222.tgz +0 -0
@@ -0,0 +1,794 @@
1
+ "use strict";
2
+ /*
3
+ * This Source Code Form is subject to the terms of the Mozilla Public
4
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
5
+ * file, You can obtain one at https://mozilla.org/MPL/2.0/.
6
+ *
7
+ * OpenCRVS is also distributed under the terms of the Civil Registration
8
+ * & Healthcare Disclaimer located at http://opencrvs.org/license.
9
+ *
10
+ * Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
11
+ */
12
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
14
+ return new (P || (P = Promise))(function (resolve, reject) {
15
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
18
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
19
+ });
20
+ };
21
+ var __rest = (this && this.__rest) || function (s, e) {
22
+ var t = {};
23
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
24
+ t[p] = s[p];
25
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
26
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
27
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
28
+ t[p[i]] = s[p[i]];
29
+ }
30
+ return t;
31
+ };
32
+ var __importDefault = (this && this.__importDefault) || function (mod) {
33
+ return (mod && mod.__esModule) ? mod : { "default": mod };
34
+ };
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ const core_1 = require("@octokit/core");
37
+ const dotenv_1 = __importDefault(require("dotenv"));
38
+ const kleur_1 = __importDefault(require("kleur"));
39
+ const prompts_1 = __importDefault(require("prompts"));
40
+ function confirm(options) {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ const inquirer = yield import('@inquirer/prompts');
43
+ return inquirer.confirm(options);
44
+ });
45
+ }
46
+ function select(options) {
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ const inquirer = yield import('@inquirer/prompts');
49
+ return inquirer.select(options);
50
+ });
51
+ }
52
+ const github_1 = require("./github");
53
+ const derived_variables_1 = require("./derived-variables");
54
+ const utils_1 = require("./utils");
55
+ const logger_1 = require("./logger");
56
+ const templates_1 = require("./templates");
57
+ const ssh_keygen_1 = require("./ssh-keygen");
58
+ const questions_1 = require("./questions");
59
+ const editor_questions_1 = require("./editor-questions");
60
+ const questions_helper_1 = require("./questions-helper");
61
+ const manage_users_1 = require("./manage-users");
62
+ function questionToPrompt(_a) {
63
+ var { valueType, valueLabel, scope } = _a, promptOptions = __rest(_a, ["valueType", "valueLabel", "scope"]);
64
+ return promptOptions;
65
+ }
66
+ const ALL_QUESTIONS = [];
67
+ const ALL_ANSWERS = [];
68
+ function getAnswers(existingValues) {
69
+ return ALL_ANSWERS.flatMap((answerObject) => {
70
+ const questionsThatAreSecretsOrVariables = Object.entries(answerObject).filter(([key, value]) => {
71
+ if (value === '') {
72
+ return false;
73
+ }
74
+ const existingQuestion = ALL_QUESTIONS.find((question) => question.name === key);
75
+ const valueType = existingQuestion === null || existingQuestion === void 0 ? void 0 : existingQuestion.valueType;
76
+ return valueType === 'VARIABLE' || valueType === 'SECRET';
77
+ });
78
+ return questionsThatAreSecretsOrVariables.map(([key, value]) => {
79
+ const existingQuestion = ALL_QUESTIONS.find((question) => question.name === key);
80
+ if (!(existingQuestion === null || existingQuestion === void 0 ? void 0 : existingQuestion.valueLabel) ||
81
+ (existingQuestion.valueType !== 'SECRET' &&
82
+ existingQuestion.valueType !== 'VARIABLE')) {
83
+ throw new Error(`No secret or variable question found for ${key}`);
84
+ }
85
+ const { valueLabel, valueType, scope } = existingQuestion;
86
+ if (valueType === 'SECRET') {
87
+ const existingSecret = (0, utils_1.findExistingValue)(valueLabel, 'SECRET', scope, existingValues);
88
+ return {
89
+ type: valueType,
90
+ name: valueLabel,
91
+ value: value.toString(),
92
+ didExist: existingSecret,
93
+ scope
94
+ };
95
+ }
96
+ const existingVariable = (0, utils_1.findExistingValue)(valueLabel, valueType, scope, existingValues);
97
+ return {
98
+ type: valueType,
99
+ name: valueLabel,
100
+ didExist: (0, utils_1.findExistingValue)(valueLabel, valueType, scope, existingValues),
101
+ value: value.toString() || (existingVariable === null || existingVariable === void 0 ? void 0 : existingVariable.value) || '',
102
+ scope
103
+ };
104
+ });
105
+ });
106
+ }
107
+ function promptAndStoreAnswer(environment, questions, existingValues) {
108
+ return __awaiter(this, void 0, void 0, function* () {
109
+ (0, logger_1.log)('');
110
+ const processedQuestions = questions.flatMap((question) => {
111
+ const questionWithVariableLabel = Object.assign(Object.assign({}, question), { message: `${kleur_1.default.cyan(question.valueLabel || '')}: ${question.message}` });
112
+ if (!questionWithVariableLabel.valueLabel) {
113
+ return questionWithVariableLabel;
114
+ }
115
+ if (questionWithVariableLabel.valueType === 'VARIABLE') {
116
+ const existingVariable = (0, utils_1.findExistingValue)(questionWithVariableLabel.valueLabel, 'VARIABLE', questionWithVariableLabel.scope, existingValues);
117
+ if (existingVariable) {
118
+ let initial_value = existingVariable.value;
119
+ // Get correct initial value for select questions
120
+ if (questionWithVariableLabel.type === 'select' &&
121
+ Array.isArray(questionWithVariableLabel.choices)) {
122
+ initial_value = (0, questions_helper_1.getIndexFromChoices)(questionWithVariableLabel.choices, existingVariable.value);
123
+ }
124
+ return [
125
+ {
126
+ name: 'overWrite' + questionWithVariableLabel.name,
127
+ type: 'confirm',
128
+ scope: questionWithVariableLabel.scope,
129
+ message: `${kleur_1.default.yellow(`Variable ${kleur_1.default.cyan(existingVariable.name)} already exists in Github. Do you want to update it?`)}`
130
+ },
131
+ Object.assign(Object.assign({}, questionWithVariableLabel), { type: ((prev) => prev ? questionWithVariableLabel.type : null), initial: initial_value })
132
+ ];
133
+ }
134
+ }
135
+ if (questionWithVariableLabel.valueType === 'SECRET') {
136
+ const existingSecret = (0, utils_1.findExistingValue)(questionWithVariableLabel.valueLabel, 'SECRET', questionWithVariableLabel.scope, existingValues);
137
+ if (existingSecret) {
138
+ return [
139
+ {
140
+ name: 'overWrite' + questionWithVariableLabel.name,
141
+ type: 'confirm',
142
+ scope: questionWithVariableLabel.scope,
143
+ message: `${kleur_1.default.yellow(`${existingSecret.scope === 'REPOSITORY'
144
+ ? 'Repository secret'
145
+ : 'Secret'} ${kleur_1.default.cyan(existingSecret.name)} already exists in Github. Do you want to update it?`)}`
146
+ },
147
+ Object.assign(Object.assign({}, questionWithVariableLabel), { type: ((prev) => prev ? questionWithVariableLabel.type : null) })
148
+ ];
149
+ }
150
+ }
151
+ return questionWithVariableLabel;
152
+ });
153
+ const promptQuestions = processedQuestions.map(questionToPrompt);
154
+ const result = yield (0, prompts_1.default)(promptQuestions, {
155
+ onCancel: () => {
156
+ process.exit(1);
157
+ }
158
+ });
159
+ ALL_ANSWERS.push(result);
160
+ (0, utils_1.storeSecrets)(environment, getAnswers(existingValues));
161
+ const existingValuesForQuestions = questions
162
+ // Only variables can have previous values we can use
163
+ .filter((question) => question.valueType === 'VARIABLE')
164
+ .map((question) => {
165
+ var _a;
166
+ return [
167
+ question.name,
168
+ (_a = (0, utils_1.findExistingValue)(question.valueLabel, 'VARIABLE', question.scope, existingValues)) === null || _a === void 0 ? void 0 : _a.value
169
+ ];
170
+ });
171
+ return Object.assign(Object.assign({}, Object.fromEntries(existingValuesForQuestions)), result);
172
+ });
173
+ }
174
+ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOtherQuestions, ...questions_1.dockerhubQuestions, ...questions_1.diskQuestions, ...questions_1.infrastructureQuestions, ...questions_1.backupQuestions, ...questions_1.countryQuestions, ...questions_1.databaseAndMonitoringQuestions, ...questions_1.emailQuestions, ...questions_1.sentryQuestions, ...derived_variables_1.derivedVariables, ...questions_1.metabaseAdminQuestions);
175
+ (() => __awaiter(void 0, void 0, void 0, function* () {
176
+ var _a, _b, _c;
177
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Github'), '\n');
178
+ const { githubOrganisation, githubRepository } = yield (0, prompts_1.default)(questions_1.githubQuestions.map(questionToPrompt), {
179
+ onCancel: () => {
180
+ process.exit(1);
181
+ }
182
+ });
183
+ const { githubToken } = yield promptAndStoreAnswer('', questions_1.githubTokenQuestion, []);
184
+ const octokit = new core_1.Octokit({
185
+ auth: githubToken
186
+ });
187
+ (0, logger_1.log)(kleur_1.default.green('\nSuccessfully logged in to Github\n'));
188
+ const existingEnvironments = yield (0, github_1.getRepositoryEnvironments)(octokit, githubOrganisation, githubRepository);
189
+ const defaultChoices = [
190
+ { name: 'Development', value: 'development' },
191
+ { name: 'Quality assurance (no PII data)', value: 'qa' },
192
+ {
193
+ name: 'Staging (hosts PII data, no backups)',
194
+ value: 'staging'
195
+ },
196
+ {
197
+ name: 'Production (hosts PII data, requires frequent backups)',
198
+ value: 'production'
199
+ }
200
+ ];
201
+ // Add only environments that are not already present
202
+ const choices = [
203
+ ...defaultChoices,
204
+ ...existingEnvironments
205
+ .filter((env) => !defaultChoices.some((choice) => choice.value === env))
206
+ .map((env) => ({
207
+ name: env,
208
+ value: env
209
+ }))
210
+ ];
211
+ const environment = yield (0, questions_helper_1.selectWithCustom)({
212
+ message: 'Choose a name and purpose for the environment?',
213
+ choices: choices
214
+ });
215
+ let environment_type = 'non-production';
216
+ if (['development', 'qa'].includes(environment)) {
217
+ environment_type = 'non-production';
218
+ }
219
+ else if (['staging', 'production'].includes(environment)) {
220
+ environment_type = 'production';
221
+ }
222
+ else {
223
+ environment_type = yield select({
224
+ message: 'Purpose for the environment?',
225
+ choices: [
226
+ {
227
+ name: 'Development/Quality assurance/Testing (no PII data)',
228
+ value: 'non-production'
229
+ },
230
+ {
231
+ name: 'Staging/Production (hosts PII data, requires frequent backups)',
232
+ value: 'production'
233
+ }
234
+ ]
235
+ });
236
+ }
237
+ const environment_exists = existingEnvironments
238
+ .map((e) => e.trim())
239
+ .includes(environment);
240
+ if (!environment) {
241
+ process.exit(1);
242
+ }
243
+ // Read users .env file based on the environment name they gave above, e.g. .env.production
244
+ dotenv_1.default.config({
245
+ path: `${process.cwd()}/.env.${environment}`
246
+ });
247
+ yield (0, github_1.createEnvironment)(octokit, environment, githubOrganisation, githubRepository);
248
+ const repositoryId = yield (0, github_1.getRepositoryId)(octokit, githubOrganisation, githubRepository);
249
+ const existingRepositorySecrets = yield (0, github_1.listRepositorySecrets)(octokit, githubOrganisation, githubRepository);
250
+ const existingRepositoryVariables = yield (0, github_1.listRepositoryVariables)(octokit, githubOrganisation, githubRepository);
251
+ const existingEnvironmentVariables = yield (0, github_1.listEnvironmentVariables)(octokit, repositoryId, environment);
252
+ const existingEnvironmentSecrets = yield (0, github_1.listEnvironmentSecrets)(octokit, githubOrganisation, repositoryId, environment);
253
+ const existingValues = [
254
+ ...existingEnvironmentVariables,
255
+ ...existingRepositoryVariables,
256
+ ...existingRepositorySecrets,
257
+ ...existingEnvironmentSecrets
258
+ ];
259
+ if (existingEnvironmentVariables.length > 0 ||
260
+ existingEnvironmentSecrets.length > 0) {
261
+ (0, logger_1.log)('\nEnvironment with the name', environment, 'already exists in Github.', '\nFound', existingEnvironmentVariables.length, 'existing variables and', existingEnvironmentSecrets.length, 'secrets');
262
+ }
263
+ if (environment_type === 'production') {
264
+ (0, logger_1.log)('\n', kleur_1.default
265
+ .yellow()
266
+ .bold('WARNING! You are setting up a production environment.\n Make sure you have read the deployment guide carefully before proceeding.\n'));
267
+ yield promptAndStoreAnswer(environment, questions_1.githubOtherQuestions, existingValues);
268
+ }
269
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Docker Hub'));
270
+ yield promptAndStoreAnswer(environment, questions_1.dockerhubQuestions, existingValues);
271
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Kubernetes & Runtime'));
272
+ const infrastructure = yield promptAndStoreAnswer(environment, questions_1.infrastructureQuestions, existingValues);
273
+ const kubeWorkerNodes = infrastructure.kubeWorkerNodes
274
+ ? infrastructure.kubeWorkerNodes.split(',').map((ip) => ip.trim())
275
+ : [];
276
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('SSH Users'), '\n');
277
+ const users = yield (0, manage_users_1.manageUsers)(`infrastructure/server-setup/inventory/${environment}.yml`);
278
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Traefik SSL Certificate'), '\n');
279
+ const sslCertExists = (0, utils_1.findExistingValue)('SSL_CRT', 'SECRET', 'ENVIRONMENT', existingValues);
280
+ let ssl_answers = [];
281
+ const traefikConfOption = (yield (0, prompts_1.default)([
282
+ {
283
+ name: 'traefikConfOption',
284
+ type: 'select',
285
+ message: 'Choose option to configure Traefik SSL Certificate',
286
+ choices: [
287
+ { title: "Let's Encrypt certificate", value: 'lets_encrypt' },
288
+ { title: 'Static SSL certificate', value: 'static_ssl' },
289
+ { title: 'Custom configuration', value: 'custom' }
290
+ ],
291
+ initial: sslCertExists ? 1 : 0
292
+ }
293
+ ])).traefikConfOption;
294
+ if (traefikConfOption === 'static_ssl') {
295
+ ssl_answers = yield (0, editor_questions_1.askQuestionWithEditor)(questions_1.staticSSLCertQuestions, existingEnvironmentSecrets);
296
+ }
297
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Storage'), '\n');
298
+ let enableEncryption = false;
299
+ const encryption_key_defined = (0, utils_1.findExistingValue)('ENCRYPTION_KEY', 'SECRET', 'ENVIRONMENT', existingValues);
300
+ if (!encryption_key_defined && !environment_exists) {
301
+ const answers_enable_encryption = yield (0, prompts_1.default)([
302
+ {
303
+ name: 'enableEncryption',
304
+ type: 'confirm',
305
+ message: 'Do you want to enable disk encryption?',
306
+ scope: 'ENVIRONMENT',
307
+ initial: Boolean(process.env.ENABLE_ENCRYPTION)
308
+ }
309
+ ].map(questionToPrompt));
310
+ enableEncryption = answers_enable_encryption.enableEncryption;
311
+ }
312
+ if (enableEncryption && !encryption_key_defined && !environment_exists) {
313
+ (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().yellow(' Disk encryption is enabled'));
314
+ yield promptAndStoreAnswer(environment, questions_1.diskQuestions, existingValues);
315
+ }
316
+ else {
317
+ if (!enableEncryption && !encryption_key_defined && environment_exists) {
318
+ (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default
319
+ .bold()
320
+ .grey(`Environment ${environment} is already configured, skipping disk encryption question`));
321
+ }
322
+ const DISK_SPACE = (0, utils_1.findExistingValue)('DISK_SPACE', 'VARIABLE', 'ENVIRONMENT', existingValues);
323
+ if (!DISK_SPACE) {
324
+ (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().grey('All available disk space at /data will be used'));
325
+ }
326
+ else {
327
+ (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default
328
+ .bold()
329
+ .yellow('Variable DISK_SPACE is read-only, allocated space:'), DISK_SPACE === null || DISK_SPACE === void 0 ? void 0 : DISK_SPACE.value);
330
+ }
331
+ }
332
+ // Backup and restore configuration
333
+ let backupHost = ((_a = (0, utils_1.findExistingValue)('BACKUP_HOST', 'VARIABLE', 'ENVIRONMENT', existingValues)) === null || _a === void 0 ? void 0 : _a.value) || '';
334
+ let backupType = '';
335
+ let restoreEnvironmentName = (_b = (0, utils_1.findExistingValue)('RESTORE_ENVIRONMENT_NAME', 'VARIABLE', 'ENVIRONMENT', existingValues)) === null || _b === void 0 ? void 0 : _b.value;
336
+ let restoreType = ((_c = (0, utils_1.findExistingValue)('RESTORE_ENVIRONMENT_MODE', 'VARIABLE', 'ENVIRONMENT', existingValues)) === null || _c === void 0 ? void 0 : _c.value) ||
337
+ process.env.RESTORE_ENVIRONMENT_MODE ||
338
+ 'dump';
339
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Backup'));
340
+ let configureBackup = backupHost ? true : false;
341
+ // Ask question only if backup and restore are not configured
342
+ if (!configureBackup && !restoreEnvironmentName) {
343
+ configureBackup = yield confirm({
344
+ message: 'Do you want to configure backup?',
345
+ default: Boolean(process.env.CONFIGURE_BACKUP)
346
+ });
347
+ }
348
+ let backupHostPrivateKey = '';
349
+ let backupHostPublicKey = '';
350
+ if (configureBackup) {
351
+ const backupAnswers = yield promptAndStoreAnswer(environment, questions_1.backupQuestions, existingValues);
352
+ const backupHostPrivateKeyExists = (0, utils_1.findExistingValue)('BACKUP_HOST_PRIVATE_KEY', 'SECRET', 'ENVIRONMENT', existingValues);
353
+ backupType = backupAnswers.backupType;
354
+ backupHost = backupAnswers.backupHost || backupHost;
355
+ if (!backupHostPrivateKeyExists) {
356
+ const { publicKey, privateKey } = (0, ssh_keygen_1.generateSSHKeyPair)();
357
+ backupHostPublicKey = publicKey;
358
+ backupHostPrivateKey = privateKey;
359
+ (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default
360
+ .bold()
361
+ .yellow(`Generated new SSH key pair for backup host: ${backupHost}`));
362
+ }
363
+ }
364
+ else {
365
+ (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().yellow('Backup is disabled'));
366
+ }
367
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Restore'));
368
+ let configureRestore = restoreEnvironmentName ? true : false;
369
+ if (!restoreEnvironmentName && !configureBackup) {
370
+ configureRestore = yield confirm({
371
+ message: 'Do you want to configure restore?',
372
+ default: Boolean(process.env.CONFIGURE_RESTORE)
373
+ });
374
+ }
375
+ if (configureRestore) {
376
+ const env_list_filtered = existingEnvironments.filter((env) => env !== environment);
377
+ restoreEnvironmentName = yield (0, questions_helper_1.selectWithCustom)({
378
+ message: 'What is the name of your environment to restore?',
379
+ choices: env_list_filtered.map((env) => ({
380
+ name: env,
381
+ value: env
382
+ })),
383
+ initial: restoreEnvironmentName
384
+ });
385
+ restoreType = yield select({
386
+ message: `Select ${kleur_1.default.yellow().bold(restoreEnvironmentName)} environment backup mode`,
387
+ choices: [
388
+ {
389
+ name: 'Full dump (daily full database backup)',
390
+ value: 'dump'
391
+ },
392
+ {
393
+ name: 'Differential (weekly full, daily diff backup)',
394
+ value: 'differential'
395
+ }
396
+ ]
397
+ });
398
+ }
399
+ else {
400
+ (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().yellow('Restore is disabled'));
401
+ }
402
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Monitoring'));
403
+ yield promptAndStoreAnswer(environment, questions_1.databaseAndMonitoringQuestions, existingValues);
404
+ const sentryDSNExists = (0, utils_1.findExistingValue)('SENTRY_DSN', 'SECRET', 'ENVIRONMENT', existingValues);
405
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Sentry'));
406
+ if (sentryDSNExists) {
407
+ yield promptAndStoreAnswer(environment, questions_1.sentryQuestions, existingValues);
408
+ }
409
+ else {
410
+ const { useSentry } = yield (0, prompts_1.default)([
411
+ {
412
+ name: 'useSentry',
413
+ type: 'confirm',
414
+ message: 'Do you want to use Sentry?',
415
+ initial: Boolean(process.env.SENTRY_DNS)
416
+ }
417
+ ]);
418
+ if (useSentry) {
419
+ yield promptAndStoreAnswer(environment, questions_1.sentryQuestions, existingValues);
420
+ }
421
+ }
422
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('METABASE ADMIN'));
423
+ yield promptAndStoreAnswer(environment, questions_1.metabaseAdminQuestions, existingValues);
424
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('SMTP'));
425
+ yield promptAndStoreAnswer(environment, questions_1.emailQuestions, existingValues);
426
+ const allAnswers = ALL_ANSWERS.reduce((acc, answer) => {
427
+ return Object.assign(Object.assign({}, acc), answer);
428
+ });
429
+ /*
430
+ * Variables the user doesn't need to set manually
431
+ */
432
+ const answerOrExisting = (variable, existingValue, fn) => fn(variable || (existingValue === null || existingValue === void 0 ? void 0 : existingValue.value)) || '';
433
+ function findExistingOrDefine(name, type, scope, newValue) {
434
+ return (0, utils_1.findExistingValue)(name, type, scope, existingValues)
435
+ ? null
436
+ : process.env[name] || newValue;
437
+ }
438
+ const derivedUpdates = [
439
+ {
440
+ name: 'GH_ENCRYPTION_PASSWORD',
441
+ type: 'SECRET',
442
+ didExist: (0, utils_1.findExistingValue)('GH_ENCRYPTION_PASSWORD', 'SECRET', 'REPOSITORY', existingValues),
443
+ value: findExistingOrDefine('GH_ENCRYPTION_PASSWORD', 'SECRET', 'REPOSITORY', (0, utils_1.generateLongPassword)()),
444
+ scope: 'REPOSITORY'
445
+ }
446
+ ];
447
+ derivedUpdates.push({
448
+ name: 'NOTIFICATION_TRANSPORT',
449
+ type: 'VARIABLE',
450
+ didExist: (0, utils_1.findExistingValue)('NOTIFICATION_TRANSPORT', 'VARIABLE', 'ENVIRONMENT', existingValues),
451
+ value: findExistingOrDefine('NOTIFICATION_TRANSPORT', 'VARIABLE', 'ENVIRONMENT', 'email'),
452
+ scope: 'ENVIRONMENT'
453
+ });
454
+ derivedUpdates.push(...ssl_answers);
455
+ if (configureBackup) {
456
+ derivedUpdates.push({
457
+ name: 'BACKUP_ENCRYPTION_PASSPHRASE',
458
+ type: 'SECRET',
459
+ didExist: (0, utils_1.findExistingValue)('BACKUP_ENCRYPTION_PASSPHRASE', 'SECRET', 'ENVIRONMENT', existingValues),
460
+ value: findExistingOrDefine('BACKUP_ENCRYPTION_PASSPHRASE', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
461
+ scope: 'ENVIRONMENT'
462
+ });
463
+ }
464
+ const applicationServerUpdates = [
465
+ {
466
+ name: 'ELASTICSEARCH_SUPERUSER_PASSWORD',
467
+ type: 'SECRET',
468
+ didExist: (0, utils_1.findExistingValue)('ELASTICSEARCH_SUPERUSER_PASSWORD', 'SECRET', 'ENVIRONMENT', existingValues),
469
+ value: findExistingOrDefine('ELASTICSEARCH_SUPERUSER_PASSWORD', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
470
+ scope: 'ENVIRONMENT'
471
+ },
472
+ {
473
+ name: 'KIBANA_SYSTEM_PASSWORD',
474
+ type: 'SECRET',
475
+ didExist: (0, utils_1.findExistingValue)('KIBANA_SYSTEM_PASSWORD', 'SECRET', 'ENVIRONMENT', existingValues),
476
+ value: findExistingOrDefine('KIBANA_SYSTEM_PASSWORD', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
477
+ scope: 'ENVIRONMENT'
478
+ },
479
+ {
480
+ name: 'MINIO_ROOT_USER',
481
+ type: 'SECRET',
482
+ didExist: (0, utils_1.findExistingValue)('MINIO_ROOT_USER', 'SECRET', 'ENVIRONMENT', existingValues),
483
+ value: findExistingOrDefine('MINIO_ROOT_USER', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
484
+ scope: 'ENVIRONMENT'
485
+ },
486
+ {
487
+ name: 'MINIO_ROOT_PASSWORD',
488
+ type: 'SECRET',
489
+ didExist: (0, utils_1.findExistingValue)('MINIO_ROOT_PASSWORD', 'SECRET', 'ENVIRONMENT', existingValues),
490
+ value: findExistingOrDefine('MINIO_ROOT_PASSWORD', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
491
+ scope: 'ENVIRONMENT'
492
+ },
493
+ {
494
+ name: 'MONGODB_ADMIN_USER',
495
+ type: 'SECRET',
496
+ didExist: (0, utils_1.findExistingValue)('MONGODB_ADMIN_USER', 'SECRET', 'ENVIRONMENT', existingValues),
497
+ value: findExistingOrDefine('MONGODB_ADMIN_USER', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
498
+ scope: 'ENVIRONMENT'
499
+ },
500
+ {
501
+ name: 'MONGODB_ADMIN_PASSWORD',
502
+ type: 'SECRET',
503
+ didExist: (0, utils_1.findExistingValue)('MONGODB_ADMIN_PASSWORD', 'SECRET', 'ENVIRONMENT', existingValues),
504
+ value: findExistingOrDefine('MONGODB_ADMIN_PASSWORD', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
505
+ scope: 'ENVIRONMENT'
506
+ },
507
+ {
508
+ name: 'POSTGRES_USER',
509
+ type: 'SECRET',
510
+ didExist: (0, utils_1.findExistingValue)('POSTGRES_USER', 'SECRET', 'ENVIRONMENT', existingValues),
511
+ value: findExistingOrDefine('POSTGRES_USER', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
512
+ scope: 'ENVIRONMENT'
513
+ },
514
+ {
515
+ name: 'POSTGRES_PASSWORD',
516
+ type: 'SECRET',
517
+ didExist: (0, utils_1.findExistingValue)('POSTGRES_PASSWORD', 'SECRET', 'ENVIRONMENT', existingValues),
518
+ value: findExistingOrDefine('POSTGRES_PASSWORD', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
519
+ scope: 'ENVIRONMENT'
520
+ },
521
+ {
522
+ name: 'SUPER_USER_PASSWORD',
523
+ type: 'SECRET',
524
+ didExist: (0, utils_1.findExistingValue)('SUPER_USER_PASSWORD', 'SECRET', 'ENVIRONMENT', existingValues),
525
+ value: findExistingOrDefine('SUPER_USER_PASSWORD', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
526
+ scope: 'ENVIRONMENT'
527
+ },
528
+ {
529
+ type: 'VARIABLE',
530
+ name: 'ACTIVATE_USERS',
531
+ value: 'production' === environment_type ? 'false' : 'true',
532
+ didExist: (0, utils_1.findExistingValue)('ACTIVATE_USERS', 'VARIABLE', 'ENVIRONMENT', existingValues),
533
+ scope: 'ENVIRONMENT'
534
+ },
535
+ {
536
+ type: 'VARIABLE',
537
+ name: 'COUNTRY_CONFIG_HOST',
538
+ value: answerOrExisting(allAnswers.domain, (0, utils_1.findExistingValue)('DOMAIN', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => `https://countryconfig.${val}`),
539
+ didExist: (0, utils_1.findExistingValue)('COUNTRY_CONFIG_HOST', 'VARIABLE', 'ENVIRONMENT', existingValues),
540
+ scope: 'ENVIRONMENT'
541
+ },
542
+ {
543
+ type: 'VARIABLE',
544
+ name: 'GATEWAY_HOST',
545
+ value: answerOrExisting(allAnswers.domain, (0, utils_1.findExistingValue)('DOMAIN', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => `https://gateway.${val}`),
546
+ didExist: (0, utils_1.findExistingValue)('GATEWAY_HOST', 'VARIABLE', 'ENVIRONMENT', existingValues),
547
+ scope: 'ENVIRONMENT'
548
+ },
549
+ {
550
+ type: 'VARIABLE',
551
+ name: 'CONTENT_SECURITY_POLICY_WILDCARD',
552
+ value: answerOrExisting(allAnswers.domain, (0, utils_1.findExistingValue)('DOMAIN', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => `*.${val}`),
553
+ didExist: (0, utils_1.findExistingValue)('CONTENT_SECURITY_POLICY_WILDCARD', 'VARIABLE', 'ENVIRONMENT', existingValues),
554
+ scope: 'ENVIRONMENT'
555
+ },
556
+ {
557
+ type: 'VARIABLE',
558
+ name: 'CLIENT_APP_URL',
559
+ value: answerOrExisting(allAnswers.domain, (0, utils_1.findExistingValue)('DOMAIN', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => `https://register.${val}`),
560
+ didExist: (0, utils_1.findExistingValue)('CLIENT_APP_URL', 'VARIABLE', 'ENVIRONMENT', existingValues),
561
+ scope: 'ENVIRONMENT'
562
+ },
563
+ {
564
+ type: 'VARIABLE',
565
+ name: 'LOGIN_URL',
566
+ value: answerOrExisting(allAnswers.domain, (0, utils_1.findExistingValue)('DOMAIN', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => `https://login.${val}`),
567
+ didExist: (0, utils_1.findExistingValue)('LOGIN_URL', 'VARIABLE', 'ENVIRONMENT', existingValues),
568
+ scope: 'ENVIRONMENT'
569
+ },
570
+ {
571
+ type: 'VARIABLE',
572
+ name: 'RESTORE_ENVIRONMENT_NAME',
573
+ value: answerOrExisting(restoreEnvironmentName, (0, utils_1.findExistingValue)('RESTORE_ENVIRONMENT_NAME', 'VARIABLE', 'ENVIRONMENT', existingValues), (val) => val || ''),
574
+ didExist: (0, utils_1.findExistingValue)('RESTORE_ENVIRONMENT_NAME', 'VARIABLE', 'ENVIRONMENT', existingValues),
575
+ scope: 'ENVIRONMENT'
576
+ }
577
+ ];
578
+ if (enableEncryption) {
579
+ applicationServerUpdates.push({
580
+ name: 'ENCRYPTION_KEY',
581
+ type: 'SECRET',
582
+ didExist: (0, utils_1.findExistingValue)('ENCRYPTION_KEY', 'SECRET', 'ENVIRONMENT', existingValues),
583
+ value: findExistingOrDefine('ENCRYPTION_KEY', 'SECRET', 'ENVIRONMENT', (0, utils_1.generateLongPassword)()),
584
+ scope: 'ENVIRONMENT'
585
+ });
586
+ }
587
+ if (configureBackup && backupHostPrivateKey && backupHostPublicKey) {
588
+ applicationServerUpdates.push({
589
+ name: 'BACKUP_HOST_PRIVATE_KEY',
590
+ type: 'SECRET',
591
+ didExist: undefined,
592
+ value: backupHostPrivateKey,
593
+ scope: 'ENVIRONMENT'
594
+ });
595
+ applicationServerUpdates.push({
596
+ name: 'BACKUP_HOST_PUBLIC_KEY',
597
+ type: 'SECRET',
598
+ didExist: undefined,
599
+ value: backupHostPublicKey,
600
+ scope: 'ENVIRONMENT'
601
+ });
602
+ }
603
+ derivedUpdates.push(...applicationServerUpdates);
604
+ const updates = getAnswers(existingValues)
605
+ .concat(...derivedUpdates.filter((update) => update.value !== null))
606
+ .filter((variable) => {
607
+ var _a;
608
+ return Boolean(variable.value) &&
609
+ // Only update values that changed
610
+ (variable.type !== 'VARIABLE' ||
611
+ variable.value !== ((_a = variable.didExist) === null || _a === void 0 ? void 0 : _a.value));
612
+ });
613
+ (0, utils_1.storeSecrets)(environment, updates);
614
+ /*
615
+ * List out all updates to the variables and confirm with the user
616
+ */
617
+ const newSecrets = updates.filter((update) => update.type === 'SECRET' && !update.didExist);
618
+ const updatedSecrets = updates.filter((update) => update.type === 'SECRET' && Boolean(update.didExist));
619
+ const newVariables = updates.filter((update) => update.type === 'VARIABLE' && !update.didExist);
620
+ const updatedVariables = updates.filter((update) => update.type === 'VARIABLE' && Boolean(update.didExist));
621
+ const unknownVariables = existingValues.filter((value) => {
622
+ return !ALL_QUESTIONS.find((question) => question.valueLabel === value.name &&
623
+ question.valueType === value.type &&
624
+ question.scope === value.scope);
625
+ });
626
+ (0, logger_1.log)('');
627
+ if (newSecrets.length > 0) {
628
+ (0, logger_1.log)(kleur_1.default.yellow(`The following secrets will be added to Github for environment ${environment}:`));
629
+ newSecrets
630
+ .filter(({ scope }) => scope === 'ENVIRONMENT')
631
+ .forEach((secret) => {
632
+ (0, logger_1.log)(secret.name, '=', secret.value);
633
+ });
634
+ (0, logger_1.log)('');
635
+ (0, logger_1.log)(kleur_1.default.yellow(`The following secrets will be added to Github repository:`));
636
+ newSecrets
637
+ .filter(({ scope }) => scope === 'REPOSITORY')
638
+ .forEach((secret) => {
639
+ (0, logger_1.log)(secret.name, '=', secret.value);
640
+ });
641
+ (0, logger_1.log)('');
642
+ }
643
+ if (updatedSecrets.length > 0) {
644
+ (0, logger_1.log)(kleur_1.default.yellow(`The following secrets will be updated in Github for environment ${environment}:`));
645
+ updatedSecrets.forEach((secret) => {
646
+ (0, logger_1.log)(secret.name, '=', secret.value);
647
+ });
648
+ (0, logger_1.log)('');
649
+ }
650
+ if (newVariables.length > 0) {
651
+ (0, logger_1.log)(kleur_1.default.yellow(`The following variables will be added to Github for environment ${environment}:`));
652
+ newVariables.forEach((variable) => {
653
+ (0, logger_1.log)(variable.name, '=', variable.value);
654
+ });
655
+ (0, logger_1.log)('');
656
+ }
657
+ if (updatedVariables.length > 0) {
658
+ (0, logger_1.log)(kleur_1.default.yellow(`The following variables will be updated in Github for environment ${environment}:`));
659
+ updatedVariables.forEach((variable) => {
660
+ var _a;
661
+ (0, logger_1.log)(variable.name, '=', variable.value, `(was ${(_a = variable.didExist) === null || _a === void 0 ? void 0 : _a.value})`);
662
+ });
663
+ (0, logger_1.log)('');
664
+ }
665
+ if (unknownVariables.length > 0) {
666
+ (0, logger_1.log)(kleur_1.default.yellow(`The following unknown variables/secrets were stored in Github are not managed by this script:`));
667
+ (0, logger_1.log)('');
668
+ (0, logger_1.log)(kleur_1.default.blue(`Repository:`));
669
+ unknownVariables
670
+ .filter(({ scope }) => scope === 'REPOSITORY')
671
+ .forEach((variable) => {
672
+ (0, logger_1.log)(kleur_1.default.cyan(variable.type) + ':', variable.name);
673
+ });
674
+ (0, logger_1.log)('');
675
+ (0, logger_1.log)(kleur_1.default.blue(`Environment:`));
676
+ unknownVariables
677
+ .filter(({ scope }) => scope === 'ENVIRONMENT')
678
+ .forEach((variable) => {
679
+ (0, logger_1.log)(kleur_1.default.cyan(variable.type) + ':', variable.name);
680
+ });
681
+ (0, logger_1.log)('');
682
+ (0, logger_1.log)(kleur_1.default.yellow(`These variables will not be updated by this script. If you want to update them, you will need to do so manually.`));
683
+ (0, logger_1.log)('');
684
+ }
685
+ if ([]
686
+ .concat(newSecrets)
687
+ .concat(updatedSecrets)
688
+ .concat(newVariables)
689
+ .concat(updatedVariables).length === 0) {
690
+ process.exit(0);
691
+ }
692
+ const saveChanges = yield confirm({
693
+ message: 'Do you want to continue?',
694
+ default: true
695
+ });
696
+ if (!saveChanges) {
697
+ process.exit(0);
698
+ }
699
+ for (const newSecret of newSecrets) {
700
+ (0, logger_1.log)(`Creating secret ${newSecret.name} with value ${newSecret.value}`);
701
+ if (newSecret.scope === 'ENVIRONMENT') {
702
+ yield (0, github_1.createEnvironmentSecret)(octokit, repositoryId, environment, newSecret.name, newSecret.value, githubOrganisation, githubRepository);
703
+ }
704
+ else {
705
+ yield (0, github_1.createRepositorySecret)(octokit, repositoryId, newSecret.name, newSecret.value, githubOrganisation, githubRepository);
706
+ }
707
+ }
708
+ for (const updatedSecret of updatedSecrets) {
709
+ (0, logger_1.log)(`Updating secret ${updatedSecret.name} with value ${updatedSecret.value}`);
710
+ if (updatedSecret.scope === 'ENVIRONMENT') {
711
+ yield (0, github_1.createEnvironmentSecret)(octokit, repositoryId, environment, updatedSecret.name, updatedSecret.value, githubOrganisation, githubRepository);
712
+ }
713
+ else {
714
+ yield (0, github_1.createRepositorySecret)(octokit, repositoryId, updatedSecret.name, updatedSecret.value, githubOrganisation, githubRepository);
715
+ }
716
+ }
717
+ for (const newVariable of newVariables) {
718
+ (0, logger_1.log)(`Creating variable ${newVariable.name} with value ${newVariable.value}`);
719
+ if (newVariable.scope === 'ENVIRONMENT') {
720
+ yield (0, github_1.createEnvironmentVariable)(octokit, repositoryId, environment, newVariable.name, newVariable.value);
721
+ }
722
+ else {
723
+ yield (0, github_1.createRepositoryVariable)(octokit, repositoryId, newVariable.name, newVariable.value);
724
+ }
725
+ }
726
+ for (const updatedVariable of updatedVariables) {
727
+ (0, logger_1.log)(`Updating variable ${updatedVariable.name} with value ${updatedVariable.value}`);
728
+ if (updatedVariable.scope === 'ENVIRONMENT') {
729
+ yield (0, github_1.updateEnvironmentVariable)(octokit, repositoryId, environment, updatedVariable.name, updatedVariable.value);
730
+ }
731
+ else {
732
+ yield (0, github_1.updateRepositoryVariable)(octokit, repositoryId, updatedVariable.name, updatedVariable.value);
733
+ }
734
+ }
735
+ (0, logger_1.log)(kleur_1.default.green(`Successfully updated Github secrets and variables for environment ${environment}`));
736
+ (0, logger_1.log)('\n', kleur_1.default.bold().underline('Running configuration files updates'));
737
+ (0, templates_1.generateInventory)(environment, {
738
+ kube_worker_nodes: kubeWorkerNodes,
739
+ kube_api_host: infrastructure.kubeAPIHost || '',
740
+ backup_host: backupHost || '',
741
+ users: users
742
+ });
743
+ (0, templates_1.copyChartsValues)(environment, {
744
+ env: environment,
745
+ environment_type: environment_type,
746
+ // FIXME: In general that should be environment_type,
747
+ // Hardcode like this blocks us from being generic:
748
+ // https://github.com/opencrvs/opencrvs-core/issues/11171
749
+ two_fa_enabled: environment !== 'production' ? false : true,
750
+ backup_enabled: configureBackup ? true : false,
751
+ restore_enabled: restoreEnvironmentName ? true : false,
752
+ restore_environment_name: restoreEnvironmentName || '',
753
+ restore_type: restoreType,
754
+ traefik_mode: traefikConfOption,
755
+ backup_type: backupType
756
+ });
757
+ let addon_message = kubeWorkerNodes.length > 0 || configureBackup
758
+ ? '--------------------------------------------------------------------------------------------\n' +
759
+ `\n➡️ ${kleur_1.default.bold().yellow('COPY the SSH public key from the master VM to your clipboard')}\n` +
760
+ '--------------------------------------------------------------------------------------------\n'
761
+ : '';
762
+ addon_message +=
763
+ kubeWorkerNodes.length > 0
764
+ ? `➡️ ${kleur_1.default.bold().yellow('Run following command on Kubernetes worker VM to create provision user and setup SSH key:')}\n` +
765
+ '\n' +
766
+ 'curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\ \n' +
767
+ `bash opencrvs-bootstrap.sh --ssh-public-key "${kleur_1.default.bold('[PUT PROVISION USER PUBLIC KEY FROM MASTER NODE]')}"\n`
768
+ : '';
769
+ addon_message += configureBackup
770
+ ? `\n➡️ ${kleur_1.default.bold().yellow('Run following command on backup server to create provision user and setup SSH key:')}\n` +
771
+ 'curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\ \n' +
772
+ `bash opencrvs-bootstrap.sh --ssh-public-key "${kleur_1.default.bold('[PUT PROVISION USER PUBLIC KEY FROM MASTER NODE]')}"`
773
+ : '';
774
+ (0, logger_1.log)(`
775
+ ${kleur_1.default.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━')}
776
+ Follow the steps below to complete the setup of your environment:
777
+ ${kleur_1.default.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━')}
778
+ ➡️ ${kleur_1.default.bold().yellow('Run following command on Kubernetes master VM to bootstrap self-hosted runner:')}
779
+
780
+ curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\
781
+ bash opencrvs-bootstrap.sh --owner ${githubOrganisation} \\
782
+ --repo ${githubRepository} \\
783
+ --env ${environment} \\
784
+ --token ${githubToken} \\
785
+ --enable-runner
786
+
787
+ ${addon_message}
788
+
789
+ ${kleur_1.default.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━')}
790
+ ${kleur_1.default.yellow('Please KINDLY read hints above')}
791
+ `);
792
+ (0, logger_1.log)('\nAll variables stored in', kleur_1.default.cyan(`.env.${environment}`));
793
+ (0, logger_1.log)(kleur_1.default.bold().yellow('DO NOT COMMIT THIS FILE TO GIT!'));
794
+ }))();