@opencrvs/toolkit 2.0.0-rc.bd55713 → 2.0.0-rc.bd854e0

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 (70) hide show
  1. package/README.md +1 -0
  2. package/build.sh +3 -3
  3. package/dist/application-config/index.js +17 -6
  4. package/dist/cli.js +362 -305
  5. package/dist/commons/api/router.d.ts +10 -0
  6. package/dist/commons/conditionals/conditionals.d.ts +3 -3
  7. package/dist/commons/events/AdvancedSearchConfig.d.ts +12 -0
  8. package/dist/commons/events/CountryConfigQueryInput.d.ts +42 -0
  9. package/dist/commons/events/EventConfig.d.ts +2 -0
  10. package/dist/commons/events/EventIndex.d.ts +25 -0
  11. package/dist/commons/events/EventMetadata.d.ts +26 -0
  12. package/dist/commons/events/FieldConfig.d.ts +10 -0
  13. package/dist/commons/events/WorkqueueConfig.d.ts +39 -0
  14. package/dist/commons/events/locations.d.ts +1 -0
  15. package/dist/commons/events/state/index.d.ts +8 -0
  16. package/dist/commons/events/state/utils.d.ts +9 -0
  17. package/dist/conditionals/index.js +10 -5
  18. package/dist/environment/custom-types.d.ts.map +1 -1
  19. package/dist/environment/custom-types.js +10 -0
  20. package/dist/environment/derived-variables.d.ts.map +1 -1
  21. package/dist/environment/derived-variables.js +11 -1
  22. package/dist/environment/editor-questions.d.ts +0 -1
  23. package/dist/environment/editor-questions.d.ts.map +1 -1
  24. package/dist/environment/editor-questions.js +16 -5
  25. package/dist/environment/git.d.ts.map +1 -1
  26. package/dist/environment/git.js +15 -5
  27. package/dist/environment/github.d.ts.map +1 -1
  28. package/dist/environment/github.js +25 -12
  29. package/dist/environment/index.d.ts +0 -1
  30. package/dist/environment/index.d.ts.map +1 -1
  31. package/dist/environment/index.js +12 -2
  32. package/dist/environment/logger.d.ts.map +1 -1
  33. package/dist/environment/logger.js +10 -0
  34. package/dist/environment/manage-users.d.ts.map +1 -1
  35. package/dist/environment/manage-users.js +21 -8
  36. package/dist/environment/questions-helper.d.ts.map +1 -1
  37. package/dist/environment/questions-helper.js +15 -5
  38. package/dist/environment/questions.d.ts +0 -23
  39. package/dist/environment/questions.d.ts.map +1 -1
  40. package/dist/environment/questions.js +24 -67
  41. package/dist/environment/setup-environment.js +85 -54
  42. package/dist/environment/ssh-keygen.d.ts.map +1 -1
  43. package/dist/environment/ssh-keygen.js +15 -2
  44. package/dist/environment/swarm-to-k8s.js +26 -15
  45. package/dist/environment/templates.d.ts.map +1 -1
  46. package/dist/environment/templates.js +26 -12
  47. package/dist/environment/update-workflows.d.ts.map +1 -1
  48. package/dist/environment/update-workflows.js +48 -30
  49. package/dist/environment/users.d.ts +1 -1
  50. package/dist/environment/users.d.ts.map +1 -1
  51. package/dist/environment/users.js +29 -9
  52. package/dist/environment/utils.d.ts.map +1 -1
  53. package/dist/environment/utils.js +11 -1
  54. package/dist/events/index.js +40 -6
  55. package/dist/migrations/v2.0/index.js +10 -5
  56. package/dist/notification/index.js +17 -6
  57. package/dist/scopes/index.d.ts +89 -1
  58. package/dist/scopes/index.js +10 -5
  59. package/dist/{environment/templates → templates}/charts-values/dependencies/values.yaml +7 -6
  60. package/dist/{environment/templates/charts-values/dependencies → templates/charts-values/opencrvs-services}/values.override.yaml +1 -1
  61. package/dist/{environment/templates → templates}/charts-values/opencrvs-services/values.yaml +8 -6
  62. package/dist/{environment/templates → templates}/charts-values/traefik/values.override.yaml +1 -1
  63. package/dist/{environment/templates → templates}/charts-values/traefik/values.yaml +6 -7
  64. package/dist/{environment/templates → templates}/inventory/production.example.yml +2 -2
  65. package/opencrvs-toolkit-2.0.0-rc.bd854e0.tgz +0 -0
  66. package/package.json +1 -1
  67. package/opencrvs-toolkit-2.0.0-rc.bd55713.tgz +0 -0
  68. /package/dist/{environment/templates/charts-values/opencrvs-services → templates/charts-values/dependencies}/values.override.yaml +0 -0
  69. /package/dist/{environment/templates → templates}/inventory/inventory.template.yml +0 -0
  70. /package/dist/{environment/templates → templates}/inventory/qa.example.yml +0 -0
@@ -1,4 +1,14 @@
1
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
+ */
2
12
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
13
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
14
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -50,13 +60,7 @@ const editor_questions_1 = require("./editor-questions");
50
60
  const questions_helper_1 = require("./questions-helper");
51
61
  const manage_users_1 = require("./manage-users");
52
62
  function questionToPrompt(_a) {
53
- var {
54
- // eslint-disable-next-line no-unused-vars
55
- valueType,
56
- // eslint-disable-next-line no-unused-vars
57
- valueLabel,
58
- // eslint-disable-next-line no-unused-vars
59
- scope } = _a, promptOptions = __rest(_a, ["valueType", "valueLabel", "scope"]);
63
+ var { valueType, valueLabel, scope } = _a, promptOptions = __rest(_a, ["valueType", "valueLabel", "scope"]);
60
64
  return promptOptions;
61
65
  }
62
66
  const ALL_QUESTIONS = [];
@@ -73,24 +77,29 @@ function getAnswers(existingValues) {
73
77
  });
74
78
  return questionsThatAreSecretsOrVariables.map(([key, value]) => {
75
79
  const existingQuestion = ALL_QUESTIONS.find((question) => question.name === key);
76
- const valueType = existingQuestion.valueType;
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;
77
86
  if (valueType === 'SECRET') {
78
- const existingSecret = (0, utils_1.findExistingValue)(existingQuestion.valueLabel, 'SECRET', existingQuestion === null || existingQuestion === void 0 ? void 0 : existingQuestion.scope, existingValues);
87
+ const existingSecret = (0, utils_1.findExistingValue)(valueLabel, 'SECRET', scope, existingValues);
79
88
  return {
80
89
  type: valueType,
81
- name: existingQuestion === null || existingQuestion === void 0 ? void 0 : existingQuestion.valueLabel,
90
+ name: valueLabel,
82
91
  value: value.toString(),
83
92
  didExist: existingSecret,
84
- scope: existingQuestion.scope
93
+ scope
85
94
  };
86
95
  }
87
- const existingVariable = (0, utils_1.findExistingValue)(existingQuestion === null || existingQuestion === void 0 ? void 0 : existingQuestion.valueLabel, valueType, existingQuestion === null || existingQuestion === void 0 ? void 0 : existingQuestion.scope, existingValues);
96
+ const existingVariable = (0, utils_1.findExistingValue)(valueLabel, valueType, scope, existingValues);
88
97
  return {
89
98
  type: valueType,
90
- name: existingQuestion === null || existingQuestion === void 0 ? void 0 : existingQuestion.valueLabel,
91
- didExist: (0, utils_1.findExistingValue)(existingQuestion === null || existingQuestion === void 0 ? void 0 : existingQuestion.valueLabel, valueType, existingQuestion === null || existingQuestion === void 0 ? void 0 : existingQuestion.scope, existingValues),
99
+ name: valueLabel,
100
+ didExist: (0, utils_1.findExistingValue)(valueLabel, valueType, scope, existingValues),
92
101
  value: value.toString() || (existingVariable === null || existingVariable === void 0 ? void 0 : existingVariable.value) || '',
93
- scope: existingQuestion.scope
102
+ scope
94
103
  };
95
104
  });
96
105
  });
@@ -108,7 +117,8 @@ function promptAndStoreAnswer(environment, questions, existingValues) {
108
117
  if (existingVariable) {
109
118
  let initial_value = existingVariable.value;
110
119
  // Get correct initial value for select questions
111
- if (questionWithVariableLabel.type === 'select' && Array.isArray(questionWithVariableLabel.choices)) {
120
+ if (questionWithVariableLabel.type === 'select' &&
121
+ Array.isArray(questionWithVariableLabel.choices)) {
112
122
  initial_value = (0, questions_helper_1.getIndexFromChoices)(questionWithVariableLabel.choices, existingVariable.value);
113
123
  }
114
124
  return [
@@ -175,8 +185,8 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
175
185
  auth: githubToken
176
186
  });
177
187
  (0, logger_1.log)(kleur_1.default.green('\nSuccessfully logged in to Github\n'));
178
- let existingEnvironments = yield (0, github_1.getRepositoryEnvironments)(octokit, githubOrganisation, githubRepository);
179
- let defaultChoices = [
188
+ const existingEnvironments = yield (0, github_1.getRepositoryEnvironments)(octokit, githubOrganisation, githubRepository);
189
+ const defaultChoices = [
180
190
  { name: 'Development', value: 'development' },
181
191
  { name: 'Quality assurance (no PII data)', value: 'qa' },
182
192
  {
@@ -186,7 +196,7 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
186
196
  {
187
197
  name: 'Production (hosts PII data, requires frequent backups)',
188
198
  value: 'production'
189
- },
199
+ }
190
200
  ];
191
201
  // Add only environments that are not already present
192
202
  const choices = [
@@ -213,9 +223,15 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
213
223
  environment_type = yield select({
214
224
  message: 'Purpose for the environment?',
215
225
  choices: [
216
- { name: 'Development/Quality assurance/Testing (no PII data)', value: 'non-production' },
217
- { name: 'Staging/Production (hosts PII data, requires frequent backups)', value: 'production' },
218
- ],
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
+ ]
219
235
  });
220
236
  }
221
237
  const environment_exists = existingEnvironments
@@ -245,7 +261,9 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
245
261
  (0, logger_1.log)('\nEnvironment with the name', environment, 'already exists in Github.', '\nFound', existingEnvironmentVariables.length, 'existing variables and', existingEnvironmentSecrets.length, 'secrets');
246
262
  }
247
263
  if (environment_type === 'production') {
248
- (0, logger_1.log)('\n', kleur_1.default.yellow().bold('WARNING! You are setting up a production environment.\n Make sure you have read the deployment guide carefully before proceeding.\n'));
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'));
249
267
  yield promptAndStoreAnswer(environment, questions_1.githubOtherQuestions, existingValues);
250
268
  }
251
269
  (0, logger_1.log)('\n', kleur_1.default.bold().underline('Docker Hub'));
@@ -253,7 +271,8 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
253
271
  (0, logger_1.log)('\n', kleur_1.default.bold().underline('Kubernetes & Runtime'));
254
272
  const infrastructure = yield promptAndStoreAnswer(environment, questions_1.infrastructureQuestions, existingValues);
255
273
  const kubeWorkerNodes = infrastructure.kubeWorkerNodes
256
- ? infrastructure.kubeWorkerNodes.split(',').map((ip) => ip.trim()) : [];
274
+ ? infrastructure.kubeWorkerNodes.split(',').map((ip) => ip.trim())
275
+ : [];
257
276
  (0, logger_1.log)('\n', kleur_1.default.bold().underline('SSH Users'), '\n');
258
277
  const users = yield (0, manage_users_1.manageUsers)(`infrastructure/server-setup/inventory/${environment}.yml`);
259
278
  (0, logger_1.log)('\n', kleur_1.default.bold().underline('Traefik SSL Certificate'), '\n');
@@ -266,13 +285,13 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
266
285
  message: 'Choose option to configure Traefik SSL Certificate',
267
286
  choices: [
268
287
  { title: "Let's Encrypt certificate", value: 'lets_encrypt' },
269
- { title: "Static SSL certificate", value: 'static_ssl' },
270
- { title: "Custom configuration", value: 'custom' }
288
+ { title: 'Static SSL certificate', value: 'static_ssl' },
289
+ { title: 'Custom configuration', value: 'custom' }
271
290
  ],
272
291
  initial: sslCertExists ? 1 : 0
273
292
  }
274
293
  ])).traefikConfOption;
275
- if (traefikConfOption === "static_ssl") {
294
+ if (traefikConfOption === 'static_ssl') {
276
295
  ssl_answers = yield (0, editor_questions_1.askQuestionWithEditor)(questions_1.staticSSLCertQuestions, existingEnvironmentSecrets);
277
296
  }
278
297
  (0, logger_1.log)('\n', kleur_1.default.bold().underline('Storage'), '\n');
@@ -296,21 +315,27 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
296
315
  }
297
316
  else {
298
317
  if (!enableEncryption && !encryption_key_defined && environment_exists) {
299
- (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().grey(`Environment ${environment} is already configured, skipping disk encryption question`));
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`));
300
321
  }
301
322
  const DISK_SPACE = (0, utils_1.findExistingValue)('DISK_SPACE', 'VARIABLE', 'ENVIRONMENT', existingValues);
302
323
  if (!DISK_SPACE) {
303
324
  (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().grey('All available disk space at /data will be used'));
304
325
  }
305
326
  else {
306
- (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().yellow('Variable DISK_SPACE is read-only, allocated space:'), DISK_SPACE === null || DISK_SPACE === void 0 ? void 0 : DISK_SPACE.value);
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);
307
330
  }
308
331
  }
309
332
  // Backup and restore configuration
310
333
  let backupHost = ((_a = (0, utils_1.findExistingValue)('BACKUP_HOST', 'VARIABLE', 'ENVIRONMENT', existingValues)) === null || _a === void 0 ? void 0 : _a.value) || '';
311
334
  let backupType = '';
312
335
  let restoreEnvironmentName = (_b = (0, utils_1.findExistingValue)('RESTORE_ENVIRONMENT_NAME', 'VARIABLE', 'ENVIRONMENT', existingValues)) === null || _b === void 0 ? void 0 : _b.value;
313
- let restoreType = ((_c = (0, utils_1.findExistingValue)('RESTORE_ENVIRONMENT_MODE', 'VARIABLE', 'ENVIRONMENT', existingValues)) === null || _c === void 0 ? void 0 : _c.value) || process.env.RESTORE_ENVIRONMENT_MODE || 'dump';
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';
314
339
  (0, logger_1.log)('\n', kleur_1.default.bold().underline('Backup'));
315
340
  let configureBackup = backupHost ? true : false;
316
341
  // Ask question only if backup and restore are not configured
@@ -323,15 +348,17 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
323
348
  let backupHostPrivateKey = '';
324
349
  let backupHostPublicKey = '';
325
350
  if (configureBackup) {
326
- const backupAnswers = (yield promptAndStoreAnswer(environment, questions_1.backupQuestions, existingValues));
327
- let backupHostPrivateKeyExists = (0, utils_1.findExistingValue)('BACKUP_HOST_PRIVATE_KEY', 'SECRET', 'ENVIRONMENT', existingValues);
351
+ const backupAnswers = yield promptAndStoreAnswer(environment, questions_1.backupQuestions, existingValues);
352
+ const backupHostPrivateKeyExists = (0, utils_1.findExistingValue)('BACKUP_HOST_PRIVATE_KEY', 'SECRET', 'ENVIRONMENT', existingValues);
328
353
  backupType = backupAnswers.backupType;
329
354
  backupHost = backupAnswers.backupHost || backupHost;
330
355
  if (!backupHostPrivateKeyExists) {
331
356
  const { publicKey, privateKey } = (0, ssh_keygen_1.generateSSHKeyPair)();
332
357
  backupHostPublicKey = publicKey;
333
358
  backupHostPrivateKey = privateKey;
334
- (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().yellow(`Generated new SSH key pair for backup host: ${backupHost}`));
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}`));
335
362
  }
336
363
  }
337
364
  else {
@@ -346,16 +373,17 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
346
373
  });
347
374
  }
348
375
  if (configureRestore) {
349
- const env_list_filtered = existingEnvironments.filter(env => env !== environment);
376
+ const env_list_filtered = existingEnvironments.filter((env) => env !== environment);
350
377
  restoreEnvironmentName = yield (0, questions_helper_1.selectWithCustom)({
351
378
  message: 'What is the name of your environment to restore?',
352
- choices: env_list_filtered.map(env => ({
379
+ choices: env_list_filtered.map((env) => ({
353
380
  name: env,
354
381
  value: env
355
382
  })),
356
383
  initial: restoreEnvironmentName
357
384
  });
358
- restoreType = yield select({ message: `Select ${kleur_1.default.yellow().bold(restoreEnvironmentName)} environment backup mode`,
385
+ restoreType = yield select({
386
+ message: `Select ${kleur_1.default.yellow().bold(restoreEnvironmentName)} environment backup mode`,
359
387
  choices: [
360
388
  {
361
389
  name: 'Full dump (daily full database backup)',
@@ -365,7 +393,8 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
365
393
  name: 'Differential (weekly full, daily diff backup)',
366
394
  value: 'differential'
367
395
  }
368
- ] });
396
+ ]
397
+ });
369
398
  }
370
399
  else {
371
400
  (0, logger_1.log)(kleur_1.default.bold().green('✔'), kleur_1.default.bold().yellow('Restore is disabled'));
@@ -400,9 +429,7 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
400
429
  /*
401
430
  * Variables the user doesn't need to set manually
402
431
  */
403
- const answerOrExisting = (variable, existingValue,
404
- // eslint-disable-next-line no-unused-vars
405
- fn) => fn(variable || (existingValue === null || existingValue === void 0 ? void 0 : existingValue.value)) || '';
432
+ const answerOrExisting = (variable, existingValue, fn) => fn(variable || (existingValue === null || existingValue === void 0 ? void 0 : existingValue.value)) || '';
406
433
  function findExistingOrDefine(name, type, scope, newValue) {
407
434
  return (0, utils_1.findExistingValue)(name, type, scope, existingValues)
408
435
  ? null
@@ -415,7 +442,7 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
415
442
  didExist: (0, utils_1.findExistingValue)('GH_ENCRYPTION_PASSWORD', 'SECRET', 'REPOSITORY', existingValues),
416
443
  value: findExistingOrDefine('GH_ENCRYPTION_PASSWORD', 'SECRET', 'REPOSITORY', (0, utils_1.generateLongPassword)()),
417
444
  scope: 'REPOSITORY'
418
- },
445
+ }
419
446
  ];
420
447
  derivedUpdates.push({
421
448
  name: 'NOTIFICATION_TRANSPORT',
@@ -722,24 +749,28 @@ ALL_QUESTIONS.push(...questions_1.githubTokenQuestion, ...questions_1.githubOthe
722
749
  two_fa_enabled: environment !== 'production' ? false : true,
723
750
  backup_enabled: configureBackup ? true : false,
724
751
  restore_enabled: restoreEnvironmentName ? true : false,
725
- restore_environment_name: restoreEnvironmentName || "",
752
+ restore_environment_name: restoreEnvironmentName || '',
726
753
  restore_type: restoreType,
727
754
  traefik_mode: traefikConfOption,
728
755
  backup_type: backupType
729
756
  });
730
- let addon_message = kubeWorkerNodes.length > 0 || configureBackup ?
731
- "--------------------------------------------------------------------------------------------\n" +
757
+ let addon_message = kubeWorkerNodes.length > 0 || configureBackup
758
+ ? '--------------------------------------------------------------------------------------------\n' +
732
759
  `\n➡️ ${kleur_1.default.bold().yellow('COPY the SSH public key from the master VM to your clipboard')}\n` +
733
- "--------------------------------------------------------------------------------------------\n" : "";
734
- addon_message += kubeWorkerNodes.length > 0 ?
735
- `➡️ ${kleur_1.default.bold().yellow('Run following command on Kubernetes worker VM to create provision user and setup SSH key:')}\n` +
736
- "\n" +
737
- "curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\ \n" +
738
- `bash opencrvs-bootstrap.sh --ssh-public-key "${kleur_1.default.bold('[PUT PROVISION USER PUBLIC KEY FROM MASTER NODE]')}"\n` : "";
739
- addon_message += configureBackup ?
740
- `\n➡️ ${kleur_1.default.bold().yellow('Run following command on backup server to create provision user and setup SSH key:')}\n` +
741
- "curl -sfL https://raw.githubusercontent.com/opencrvs/infrastructure/refs/heads/develop/scripts/bootstrap/opencrvs-bootstrap.sh -o opencrvs-bootstrap.sh && \\ \n" +
742
- `bash opencrvs-bootstrap.sh --ssh-public-key "${kleur_1.default.bold('[PUT PROVISION USER PUBLIC KEY FROM MASTER NODE]')}"` : "";
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
+ : '';
743
774
  (0, logger_1.log)(`
744
775
  ${kleur_1.default.yellow('━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━')}
745
776
  Follow the steps below to complete the setup of your environment:
@@ -1 +1 @@
1
- {"version":3,"file":"ssh-keygen.d.ts","sourceRoot":"","sources":["../../src/environment/ssh-keygen.ts"],"names":[],"mappings":"AAEA,wBAAgB,kBAAkB,IAAI;IAAE,SAAS,EAAE,MAAM,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAG9E"}
1
+ {"version":3,"file":"ssh-keygen.d.ts","sourceRoot":"","sources":["../../src/environment/ssh-keygen.ts"],"names":[],"mappings":"AAaA,wBAAgB,kBAAkB,IAAI;IACpC,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,MAAM,CAAA;CACnB,CAMA"}
@@ -1,8 +1,21 @@
1
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
+ */
2
12
  Object.defineProperty(exports, "__esModule", { value: true });
3
13
  exports.generateSSHKeyPair = generateSSHKeyPair;
4
14
  const ssh2_1 = require("ssh2");
5
15
  function generateSSHKeyPair() {
6
- let keys = ssh2_1.utils.generateKeyPairSync('ed25519');
7
- return { publicKey: keys.public.toString(), privateKey: keys.private.toString() };
16
+ const keys = ssh2_1.utils.generateKeyPairSync('ed25519');
17
+ return {
18
+ publicKey: keys.public.toString(),
19
+ privateKey: keys.private.toString()
20
+ };
8
21
  }
@@ -1,4 +1,14 @@
1
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
+ */
2
12
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
13
  if (k2 === undefined) k2 = k;
4
14
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -36,6 +46,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
36
46
  };
37
47
  Object.defineProperty(exports, "__esModule", { value: true });
38
48
  const path = __importStar(require("path"));
49
+ /* eslint-disable no-console */
39
50
  const kleur_1 = __importDefault(require("kleur"));
40
51
  const logger_1 = require("./logger");
41
52
  const utils_1 = require("./utils");
@@ -44,10 +55,10 @@ const core_1 = require("@octokit/core");
44
55
  const ssh_keygen_1 = require("./ssh-keygen");
45
56
  const github_1 = require("./github");
46
57
  (() => __awaiter(void 0, void 0, void 0, function* () {
47
- (0, logger_1.log)(kleur_1.default.bold("------------------------------------------------\n" +
48
- "OpenCRVS Infrastructure migration script: \n" +
49
- "Migrating Swarm configurations to Kubernetes\n" +
50
- "------------------------------------------------\n"));
58
+ (0, logger_1.log)(kleur_1.default.bold('------------------------------------------------\n' +
59
+ 'OpenCRVS Infrastructure migration script: \n' +
60
+ 'Migrating Swarm configurations to Kubernetes\n' +
61
+ '------------------------------------------------\n'));
51
62
  const environment_type = process.env.ENVIRONMENT_TYPE || 'production';
52
63
  const environment = process.env.ENVIRONMENT || '';
53
64
  const githubToken = process.env.INFRA_TOKEN || '';
@@ -69,7 +80,7 @@ const github_1 = require("./github");
69
80
  (0, logger_1.error)('\n', 'Environment variable INFRA_REPOSITORY is not set. Exiting.');
70
81
  process.exit(1);
71
82
  }
72
- if (["backup", "jumpbox"].includes(environment)) {
83
+ if (['backup', 'jumpbox'].includes(environment)) {
73
84
  (0, logger_1.info)(` > ${environment} environment will not be migrated, see migration notes`);
74
85
  process.exit(0);
75
86
  }
@@ -104,12 +115,12 @@ const github_1 = require("./github");
104
115
  // Hardcode like this blocks us from being generic:
105
116
  // https://github.com/opencrvs/opencrvs-core/issues/11171
106
117
  two_fa_enabled: environment !== 'production' ? false : true,
107
- backup_enabled: environment === 'production' ? "true" : "false",
108
- restore_enabled: environment === 'staging' ? "true" : "false",
109
- restore_environment_name: environment === 'staging' ? "production" : "",
110
- restore_type: "dump",
111
- traefik_mode: "static_ssl",
112
- backup_type: "dump",
118
+ backup_enabled: environment === 'production' ? 'true' : 'false',
119
+ restore_enabled: environment === 'staging' ? 'true' : 'false',
120
+ restore_environment_name: environment === 'staging' ? 'production' : '',
121
+ restore_type: 'dump',
122
+ traefik_mode: 'static_ssl',
123
+ backup_type: 'dump'
113
124
  });
114
125
  if (environment === 'staging') {
115
126
  const octokit = new core_1.Octokit({
@@ -127,18 +138,18 @@ const github_1 = require("./github");
127
138
  const octokit = new core_1.Octokit({
128
139
  auth: githubToken
129
140
  });
130
- console.log("Fetching repository ID for:", githubOrganisation, githubRepository);
141
+ console.log('Fetching repository ID for:', githubOrganisation, githubRepository);
131
142
  const repositoryId = yield (0, github_1.getRepositoryId)(octokit, githubOrganisation, githubRepository);
132
- console.log("Repository ID:", repositoryId);
143
+ console.log('Repository ID:', repositoryId);
133
144
  const { publicKey, privateKey } = (0, ssh_keygen_1.generateSSHKeyPair)();
134
145
  const secretsToCreate = {
135
146
  BACKUP_HOST_PRIVATE_KEY: privateKey,
136
147
  BACKUP_HOST_PUBLIC_KEY: publicKey,
137
- BACKUP_SERVER_USER: "backup",
148
+ BACKUP_SERVER_USER: 'backup'
138
149
  };
139
150
  const variablesToCreate = {
140
151
  BACKUP_HOST: backup_host,
141
- KUBE_WORKER_NODES: kube_worker_nodes.join(','),
152
+ KUBE_WORKER_NODES: kube_worker_nodes.join(',')
142
153
  };
143
154
  for (const [secretName, secretValue] of Object.entries(secretsToCreate)) {
144
155
  try {
@@ -1 +1 @@
1
- {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/environment/templates.ts"],"names":[],"mappings":"AAWA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,CAKvC;AAID,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,CAYpD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CASpD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CASnD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,EAAE,CAStD;AAGD;;;;GAIG;AACH;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QAwCrF;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAczE"}
1
+ {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../../src/environment/templates.ts"],"names":[],"mappings":"AAsBA,wBAAgB,QAAQ,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,CAKvC;AAID,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,CAYpD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CAWpD;AAED,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,CASnD;AAED,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,EAAE,CAStD;AAGD;;;;GAIG;AACH;;GAEG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,QA0CzC;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QA4BzE"}
@@ -1,4 +1,14 @@
1
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
+ */
2
12
  var __rest = (this && this.__rest) || function (s, e) {
3
13
  var t = {};
4
14
  for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
@@ -46,7 +56,7 @@ function extractAndModifyUsers(data) {
46
56
  }
47
57
  const users = data.all.vars.users.map((user) => {
48
58
  const { sudoer } = user, rest = __rest(user, ["sudoer"]);
49
- return Object.assign(Object.assign({}, rest), { role: sudoer ? "admin" : "operator" });
59
+ return Object.assign(Object.assign({}, rest), { role: sudoer ? 'admin' : 'operator' });
50
60
  });
51
61
  return users;
52
62
  }
@@ -93,11 +103,12 @@ function extractWorkerNodes(data) {
93
103
  * Recursively copy a directory and replace placeholders in text files.
94
104
  */
95
105
  function copyChartsValues(env, values) {
96
- const srcDir = path_1.default.resolve(__dirname, "templates", "charts-values");
97
- const destDir = path_1.default.resolve(process.cwd(), "environments", env);
106
+ const srcDir = path_1.default.resolve(__dirname, 'templates', 'charts-values');
107
+ const destDir = path_1.default.resolve(process.cwd(), 'environments', env);
98
108
  fs_1.default.mkdirSync(destDir, { recursive: true });
99
- values['lets_encrypt'] = values['traefik_mode'] === "lets_encrypt";
100
- values['static_ssl'] = values['traefik_mode'] === "static_ssl";
109
+ values['lets_encrypt'] = values['traefik_mode'] === 'lets_encrypt';
110
+ values['static_ssl'] = values['traefik_mode'] === 'static_ssl';
111
+ values['opencrvs_environment'] = env;
101
112
  function copyRecursive(src, dest) {
102
113
  const stat = fs_1.default.statSync(src);
103
114
  if (stat.isDirectory()) {
@@ -107,16 +118,16 @@ function copyChartsValues(env, values) {
107
118
  }
108
119
  }
109
120
  else {
110
- const content = fs_1.default.readFileSync(src, "utf8");
121
+ const content = fs_1.default.readFileSync(src, 'utf8');
111
122
  const template = handlebars_1.default.compile(content);
112
123
  const updated = template(values);
113
- const isOverridesFile = dest.endsWith("override.yaml");
124
+ const isOverridesFile = dest.endsWith('override.yaml');
114
125
  // Skip overwrite for existing overrides.yaml
115
126
  if (isOverridesFile && fs_1.default.existsSync(dest)) {
116
127
  (0, logger_1.log)(` ↷ Skipped existing overrides file: ${dest}`);
117
128
  return;
118
129
  }
119
- fs_1.default.writeFileSync(dest, updated, "utf8");
130
+ fs_1.default.writeFileSync(dest, updated, 'utf8');
120
131
  (0, logger_1.log)(` ✓ Created: ${dest}`);
121
132
  }
122
133
  }
@@ -137,11 +148,14 @@ function copyChartsValues(env, values) {
137
148
  */
138
149
  function generateInventory(env, values) {
139
150
  // Template and output paths
140
- const templatePath = path_1.default.join(__dirname, "templates", "inventory", "inventory.template.yml");
141
- const outputPath = path_1.default.join(process.cwd(), "infrastructure", "server-setup", "inventory", `${env}.yml`);
142
- const templateFile = fs_1.default.readFileSync(templatePath, "utf-8");
151
+ const templatePath = path_1.default.join(__dirname, 'templates', 'inventory', 'inventory.template.yml');
152
+ const outputPath = path_1.default.join(process.cwd(), 'infrastructure', 'server-setup', 'inventory', `${env}.yml`);
153
+ const templateFile = fs_1.default.readFileSync(templatePath, 'utf-8');
143
154
  const template = handlebars_1.default.compile(templateFile);
144
- values['single_node'] = (values['kube_worker_nodes'].length > 0 || values['backup_host']) ? "false" : "true";
155
+ values['single_node'] =
156
+ values['kube_worker_nodes'].length > 0 || values['backup_host']
157
+ ? 'false'
158
+ : 'true';
145
159
  const updated = template(values);
146
160
  fs_1.default.mkdirSync(path_1.default.dirname(outputPath), { recursive: true });
147
161
  fs_1.default.writeFileSync(outputPath, updated);
@@ -1 +1 @@
1
- {"version":3,"file":"update-workflows.d.ts","sourceRoot":"","sources":["../../src/environment/update-workflows.ts"],"names":[],"mappings":"AA4FA,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC,CAsChE"}
1
+ {"version":3,"file":"update-workflows.d.ts","sourceRoot":"","sources":["../../src/environment/update-workflows.ts"],"names":[],"mappings":"AAgHA,wBAAsB,0BAA0B,IAAI,OAAO,CAAC,IAAI,CAAC,CAgDhE"}
@@ -1,4 +1,14 @@
1
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
+ */
2
12
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
13
  if (k2 === undefined) k2 = k;
4
14
  var desc = Object.getOwnPropertyDescriptor(m, k);
@@ -34,6 +44,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
34
44
  Object.defineProperty(exports, "__esModule", { value: true });
35
45
  exports.updateWorkflowEnvironments = updateWorkflowEnvironments;
36
46
  const promises_1 = require("fs/promises");
47
+ /* eslint-disable no-console */
37
48
  const fs_1 = require("fs");
38
49
  const path_1 = require("path");
39
50
  const glob = __importStar(require("glob"));
@@ -42,7 +53,7 @@ const logger_1 = require("./logger");
42
53
  function extractInfrastructureNames() {
43
54
  return __awaiter(this, void 0, void 0, function* () {
44
55
  const files = glob.sync('infrastructure/server-setup/inventory/*.yml');
45
- const infraEnvironments = files.map(file => (0, path_1.basename)(file, '.yml'));
56
+ const infraEnvironments = files.map((file) => (0, path_1.basename)(file, '.yml'));
46
57
  if (infraEnvironments.length === 0) {
47
58
  console.log('⚠️ Warning: No environment directories found in infrastructure/server-setup/inventory/');
48
59
  return [];
@@ -55,7 +66,7 @@ function extractEnvironmentNames() {
55
66
  return __awaiter(this, void 0, void 0, function* () {
56
67
  const entries = yield (0, promises_1.readdir)('environments');
57
68
  // Filter only directories
58
- const environments = entries.filter(entry => {
69
+ const environments = entries.filter((entry) => {
59
70
  const fullPath = (0, path_1.join)('environments', entry);
60
71
  return (0, fs_1.statSync)(fullPath).isDirectory();
61
72
  });
@@ -79,7 +90,7 @@ function updateOptionsInYaml(content, envList) {
79
90
  const firstItemMatch = match[2].match(/^([ ]*)-/);
80
91
  const itemIndent = firstItemMatch ? firstItemMatch[1] : ' ';
81
92
  // Create new options array
82
- const newOptions = match[1] + envList.map(env => `${itemIndent}- ${env}`).join('\n') + '\n';
93
+ const newOptions = match[1] + envList.map((env) => `${itemIndent}- ${env}`).join('\n') + '\n';
83
94
  // Replace the old options array with the new one
84
95
  return content.replace(optionsRegex, newOptions);
85
96
  }
@@ -111,33 +122,44 @@ function updateWorkflows(envList, config) {
111
122
  function updateWorkflowEnvironments() {
112
123
  return __awaiter(this, void 0, void 0, function* () {
113
124
  try {
125
+ let didUpdateWorkflows = false;
114
126
  // Extract infrastructure names
115
127
  const infraEnvironments = yield extractInfrastructureNames();
116
- // Update workflows with infrastructure configurations
117
- console.log('🔄 Updating infrastructure workflows:');
118
- yield updateWorkflows(infraEnvironments, {
119
- workflows: [
120
- '.github/workflows/provision.yml',
121
- '.github/workflows/reset-2fa.yml',
122
- ],
123
- path: 'on.workflow_dispatch.inputs.environment.options'
124
- });
128
+ if (infraEnvironments.length > 0) {
129
+ console.log('🔄 Updating infrastructure workflows:');
130
+ yield updateWorkflows(infraEnvironments, {
131
+ workflows: [
132
+ '.github/workflows/provision.yml',
133
+ '.github/workflows/reset-2fa.yml'
134
+ ],
135
+ path: 'on.workflow_dispatch.inputs.environment.options'
136
+ });
137
+ didUpdateWorkflows = true;
138
+ }
125
139
  // Extract environment names (only directories)
126
140
  const environments = yield extractEnvironmentNames();
127
- const workflows = [
128
- '.github/workflows/deploy-dependencies.yml',
129
- '.github/workflows/deploy-opencrvs.yml',
130
- '.github/workflows/clear-all-data.yml',
131
- '.github/workflows/seed-data.yml',
132
- '.github/workflows/reindex.yml',
133
- '.github/workflows/github-to-k8s-sync-env.yml'
134
- ];
135
- (0, logger_1.log)("📋 Updating OpenCRVS application workflows:");
136
- yield updateWorkflows(environments, {
137
- workflows,
138
- path: 'on.workflow_dispatch.inputs.environment.options'
139
- });
140
- (0, logger_1.success)('✅ All workflows updated successfully!');
141
+ if (environments.length > 0) {
142
+ const workflows = [
143
+ '.github/workflows/deploy-dependencies.yml',
144
+ '.github/workflows/deploy-opencrvs.yml',
145
+ '.github/workflows/clear-all-data.yml',
146
+ '.github/workflows/seed-data.yml',
147
+ '.github/workflows/reindex.yml',
148
+ '.github/workflows/github-to-k8s-sync-env.yml'
149
+ ];
150
+ (0, logger_1.log)('📋 Updating OpenCRVS application workflows:');
151
+ yield updateWorkflows(environments, {
152
+ workflows,
153
+ path: 'on.workflow_dispatch.inputs.environment.options'
154
+ });
155
+ didUpdateWorkflows = true;
156
+ }
157
+ if (didUpdateWorkflows) {
158
+ (0, logger_1.success)('✅ Workflow updates completed successfully!');
159
+ }
160
+ else {
161
+ (0, logger_1.log)('ℹ️ No workflows were updated.');
162
+ }
141
163
  }
142
164
  catch (error) {
143
165
  console.error('\n❌ Error updating workflows:', error);
@@ -145,7 +167,3 @@ function updateWorkflowEnvironments() {
145
167
  }
146
168
  });
147
169
  }
148
- // Only run if this file is executed directly
149
- if (require.main === module) {
150
- updateWorkflowEnvironments();
151
- }