@opencrvs/toolkit 2.1.0-rc.c8d2a48 → 2.1.0-rc.cebd0a2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +0 -1
- package/dist/application-config/index.js +1 -2
- package/dist/cli.js +125 -191
- package/dist/commons/api/router.d.ts +1644 -1627
- package/dist/commons/application-config/index.d.ts +6 -6
- package/dist/commons/conditionals/conditionals.d.ts +323 -32
- package/dist/commons/events/ActionConfig.d.ts +105 -105
- package/dist/commons/events/ActionDocument.d.ts +119 -119
- package/dist/commons/events/ActionInput.d.ts +6 -0
- package/dist/commons/events/ActionType.d.ts +62 -62
- package/dist/commons/events/AdvancedSearchConfig.d.ts +507 -507
- package/dist/commons/events/AuditLog.d.ts +43 -43
- package/dist/commons/events/CompositeFieldValue.d.ts +4 -4
- package/dist/commons/events/Conditional.d.ts +3 -3
- package/dist/commons/events/CountryConfigQueryInput.d.ts +590 -590
- package/dist/commons/events/Draft.d.ts +37 -37
- package/dist/commons/events/DynamicFieldValue.d.ts +9 -9
- package/dist/commons/events/EventConfig.d.ts +5 -5
- package/dist/commons/events/EventDocument.d.ts +48 -48
- package/dist/commons/events/EventIndex.d.ts +62 -62
- package/dist/commons/events/EventMetadata.d.ts +40 -40
- package/dist/commons/events/FieldConfig.d.ts +337 -337
- package/dist/commons/events/FieldType.d.ts +51 -51
- package/dist/commons/events/FieldTypeMapping.d.ts +100 -100
- package/dist/commons/events/FieldValue.d.ts +12 -12
- package/dist/commons/events/Flag.d.ts +15 -15
- package/dist/commons/events/TemplateConfig.d.ts +1 -1
- package/dist/commons/events/WorkqueueColumnConfig.d.ts +40 -40
- package/dist/commons/events/WorkqueueConfig.d.ts +820 -820
- package/dist/commons/events/deduplication.d.ts +1 -1
- package/dist/commons/events/event.d.ts +2 -2
- package/dist/commons/events/field.d.ts +198 -69
- package/dist/commons/events/locations.d.ts +6 -96
- package/dist/commons/events/mocks.test.utils.d.ts +4 -18
- package/dist/commons/events/scopes.d.ts +4 -4
- package/dist/commons/events/state/index.d.ts +17 -17
- package/dist/commons/events/state/utils.d.ts +7 -7
- package/dist/commons/events/test.utils.d.ts +43 -40
- package/dist/commons/events/utils.d.ts +114 -114
- package/dist/commons/notification/UserNotifications.d.ts +10 -10
- package/dist/environment/derived-variables.d.ts +131 -119
- package/dist/environment/derived-variables.d.ts.map +1 -1
- package/dist/environment/derived-variables.js +14 -0
- package/dist/environment/index.d.ts +0 -1
- package/dist/environment/index.d.ts.map +1 -1
- package/dist/environment/index.js +0 -10
- package/dist/environment/logger.d.ts +12 -3
- package/dist/environment/logger.d.ts.map +1 -1
- package/dist/environment/manage-users.js +7 -17
- package/dist/environment/questions.d.ts +74 -75
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/setup-environment.js +29 -10
- package/dist/environment/swarm-to-k8s.js +7 -17
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/environment/templates.js +1 -2
- package/dist/environment/update-workflows.d.ts.map +1 -1
- package/dist/environment/update-workflows.js +10 -21
- package/dist/environment/users.js +20 -28
- package/dist/environment/utils.d.ts +1 -1
- package/dist/environment/utils.js +7 -17
- package/dist/events/deduplication.d.ts +1 -1
- package/dist/events/index.js +58 -62
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +7 -17
- package/dist/migrations/v2.0/migrate-application-config-url.js +3 -4
- package/dist/migrations/v2.0/remove-hearth-migrations.js +7 -17
- package/dist/notification/index.js +57 -48
- package/dist/scopes/index.d.ts +146 -146
- package/dist/templates/charts-values/dependencies/values.yaml +3 -0
- package/dist/templates/charts-values/opencrvs-services/values.yaml +4 -0
- package/opencrvs-toolkit-2.1.0-rc.cebd0a2.tgz +0 -0
- package/package.json +4 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/environment/paths.d.ts +0 -11
- package/dist/environment/paths.d.ts.map +0 -1
- package/dist/environment/paths.js +0 -89
- package/dist/environment/upgrade.d.ts +0 -2
- package/dist/environment/upgrade.d.ts.map +0 -1
- package/dist/environment/upgrade.js +0 -80
- package/opencrvs-toolkit-2.1.0-rc.c8d2a48.tgz +0 -0
package/README.md
CHANGED
|
@@ -989,10 +989,9 @@ var NotifiedAction = ActionBase.extend(
|
|
|
989
989
|
var EditAction = ActionBase.extend(
|
|
990
990
|
z13.object({
|
|
991
991
|
type: z13.literal(ActionType.EDIT),
|
|
992
|
-
/** @deprecated New Edit-actions should no longer contain content. This is kept for old 2.0 edits. */
|
|
993
992
|
content: z13.object({
|
|
994
993
|
comment: z13.string().describe("Comment for the edit action.").optional()
|
|
995
|
-
})
|
|
994
|
+
})
|
|
996
995
|
}).shape
|
|
997
996
|
);
|
|
998
997
|
var PrintContent = z13.object({
|
package/dist/cli.js
CHANGED
|
@@ -30,49 +30,6 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
mod
|
|
31
31
|
));
|
|
32
32
|
|
|
33
|
-
// src/environment/paths.ts
|
|
34
|
-
function getEnvironmentDir(environment) {
|
|
35
|
-
return (0, import_path2.join)("environments", environment);
|
|
36
|
-
}
|
|
37
|
-
function getEnvironmentInventoryPath(environment) {
|
|
38
|
-
return (0, import_path2.join)(getEnvironmentDir(environment), INVENTORY_FILE_NAME);
|
|
39
|
-
}
|
|
40
|
-
function findOldInventoryFiles() {
|
|
41
|
-
return glob.sync((0, import_path2.join)(OLD_INVENTORY_DIR, "*.yml")).sort();
|
|
42
|
-
}
|
|
43
|
-
function getEnvironmentNameFromOldInventoryPath(filePath) {
|
|
44
|
-
return (0, import_path2.basename)(filePath, ".yml");
|
|
45
|
-
}
|
|
46
|
-
function hasOldInventoryLayout() {
|
|
47
|
-
return findOldInventoryFiles().length > 0;
|
|
48
|
-
}
|
|
49
|
-
function assertNoOldInventoryLayout() {
|
|
50
|
-
if (!hasOldInventoryLayout()) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
throw new Error(
|
|
54
|
-
[
|
|
55
|
-
`Old inventory layout detected at ${OLD_INVENTORY_DIR}.`,
|
|
56
|
-
"Please run `yarn environment:upgrade` before running `yarn environment:init`."
|
|
57
|
-
].join(" ")
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
var import_fs, import_path2, glob, OLD_INVENTORY_DIR, INVENTORY_FILE_NAME;
|
|
61
|
-
var init_paths = __esm({
|
|
62
|
-
"src/environment/paths.ts"() {
|
|
63
|
-
"use strict";
|
|
64
|
-
import_fs = require("fs");
|
|
65
|
-
import_path2 = require("path");
|
|
66
|
-
glob = __toESM(require("glob"));
|
|
67
|
-
OLD_INVENTORY_DIR = (0, import_path2.join)(
|
|
68
|
-
"infrastructure",
|
|
69
|
-
"server-setup",
|
|
70
|
-
"inventory"
|
|
71
|
-
);
|
|
72
|
-
INVENTORY_FILE_NAME = "inventory.yml";
|
|
73
|
-
}
|
|
74
|
-
});
|
|
75
|
-
|
|
76
33
|
// src/environment/logger.ts
|
|
77
34
|
var import_kleur, log, warn, success, info, error;
|
|
78
35
|
var init_logger = __esm({
|
|
@@ -423,6 +380,20 @@ var init_derived_variables = __esm({
|
|
|
423
380
|
type: "disabled",
|
|
424
381
|
scope: "ENVIRONMENT"
|
|
425
382
|
},
|
|
383
|
+
{
|
|
384
|
+
name: "MONGODB_ADMIN_USER",
|
|
385
|
+
valueLabel: "MONGODB_ADMIN_USER",
|
|
386
|
+
valueType: "SECRET",
|
|
387
|
+
type: "disabled",
|
|
388
|
+
scope: "ENVIRONMENT"
|
|
389
|
+
},
|
|
390
|
+
{
|
|
391
|
+
name: "MONGODB_ADMIN_PASSWORD",
|
|
392
|
+
valueLabel: "MONGODB_ADMIN_PASSWORD",
|
|
393
|
+
valueType: "SECRET",
|
|
394
|
+
type: "disabled",
|
|
395
|
+
scope: "ENVIRONMENT"
|
|
396
|
+
},
|
|
426
397
|
{
|
|
427
398
|
name: "POSTGRES_USER",
|
|
428
399
|
valueLabel: "POSTGRES_USER",
|
|
@@ -514,9 +485,9 @@ function storeSecrets(environment, answers) {
|
|
|
514
485
|
let envConfig = {};
|
|
515
486
|
try {
|
|
516
487
|
envConfig = import_dotenv.default.parse(
|
|
517
|
-
(0,
|
|
488
|
+
(0, import_fs.readFileSync)(`${process.cwd()}/.env.${environment}`)
|
|
518
489
|
);
|
|
519
|
-
} catch (
|
|
490
|
+
} catch (error4) {
|
|
520
491
|
envConfig = {};
|
|
521
492
|
}
|
|
522
493
|
const linesFromAnswers = answers.map(
|
|
@@ -524,10 +495,10 @@ function storeSecrets(environment, answers) {
|
|
|
524
495
|
);
|
|
525
496
|
const linesFromEnvConfig = Object.entries(envConfig).filter(([name]) => !answers.find((update) => update.name === name)).map(([name, value]) => `${name}="${value}"`);
|
|
526
497
|
const allLines = [...linesFromEnvConfig, ...linesFromAnswers].sort();
|
|
527
|
-
(0,
|
|
498
|
+
(0, import_fs.writeFileSync)(`.env.${environment}`, allLines.join("\n"));
|
|
528
499
|
}
|
|
529
500
|
function readYamlFile(filePath) {
|
|
530
|
-
const fileContent =
|
|
501
|
+
const fileContent = import_fs.default.readFileSync(filePath, "utf8");
|
|
531
502
|
return yaml.load(fileContent);
|
|
532
503
|
}
|
|
533
504
|
function writeYamlFile(filePath, data) {
|
|
@@ -540,16 +511,16 @@ function writeYamlFile(filePath, data) {
|
|
|
540
511
|
noRefs: true,
|
|
541
512
|
sortKeys: false
|
|
542
513
|
});
|
|
543
|
-
|
|
544
|
-
} catch (
|
|
545
|
-
throw new Error(`Failed to write inventory file: ${
|
|
514
|
+
import_fs.default.writeFileSync(filePath, yamlContent, "utf8");
|
|
515
|
+
} catch (error4) {
|
|
516
|
+
throw new Error(`Failed to write inventory file: ${error4}`);
|
|
546
517
|
}
|
|
547
518
|
}
|
|
548
|
-
var
|
|
519
|
+
var import_fs, yaml, import_dotenv;
|
|
549
520
|
var init_utils = __esm({
|
|
550
521
|
"src/environment/utils.ts"() {
|
|
551
522
|
"use strict";
|
|
552
|
-
|
|
523
|
+
import_fs = __toESM(require("fs"));
|
|
553
524
|
yaml = __toESM(require("js-yaml"));
|
|
554
525
|
import_dotenv = __toESM(require("dotenv"));
|
|
555
526
|
}
|
|
@@ -602,29 +573,29 @@ function extractWorkerNodes(data) {
|
|
|
602
573
|
return worker_hosts;
|
|
603
574
|
}
|
|
604
575
|
function copyChartsValues(env, values) {
|
|
605
|
-
const srcDir =
|
|
606
|
-
const destDir =
|
|
607
|
-
|
|
576
|
+
const srcDir = import_path2.default.resolve(__dirname, "templates", "charts-values");
|
|
577
|
+
const destDir = import_path2.default.resolve(process.cwd(), "environments", env);
|
|
578
|
+
import_fs2.default.mkdirSync(destDir, { recursive: true });
|
|
608
579
|
values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
|
|
609
580
|
values["static_ssl"] = values["traefik_mode"] === "static_ssl";
|
|
610
581
|
values["opencrvs_environment"] = env;
|
|
611
582
|
function copyRecursive(src, dest) {
|
|
612
|
-
const stat =
|
|
583
|
+
const stat = import_fs2.default.statSync(src);
|
|
613
584
|
if (stat.isDirectory()) {
|
|
614
|
-
|
|
615
|
-
for (const item of
|
|
616
|
-
copyRecursive(
|
|
585
|
+
import_fs2.default.mkdirSync(dest, { recursive: true });
|
|
586
|
+
for (const item of import_fs2.default.readdirSync(src)) {
|
|
587
|
+
copyRecursive(import_path2.default.join(src, item), import_path2.default.join(dest, item));
|
|
617
588
|
}
|
|
618
589
|
} else {
|
|
619
|
-
const content =
|
|
590
|
+
const content = import_fs2.default.readFileSync(src, "utf8");
|
|
620
591
|
const template = import_handlebars.default.compile(content);
|
|
621
592
|
const updated = template(values);
|
|
622
593
|
const isOverridesFile = dest.endsWith("override.yaml");
|
|
623
|
-
if (isOverridesFile &&
|
|
594
|
+
if (isOverridesFile && import_fs2.default.existsSync(dest)) {
|
|
624
595
|
log(` \u21B7 Skipped existing overrides file: ${dest}`);
|
|
625
596
|
return;
|
|
626
597
|
}
|
|
627
|
-
|
|
598
|
+
import_fs2.default.writeFileSync(dest, updated, "utf8");
|
|
628
599
|
log(` \u2713 Created: ${dest}`);
|
|
629
600
|
}
|
|
630
601
|
}
|
|
@@ -635,31 +606,36 @@ function copyChartsValues(env, values) {
|
|
|
635
606
|
`);
|
|
636
607
|
}
|
|
637
608
|
function generateInventory(env, values) {
|
|
638
|
-
const templatePath =
|
|
609
|
+
const templatePath = import_path2.default.join(
|
|
639
610
|
__dirname,
|
|
640
611
|
"templates",
|
|
641
612
|
"inventory",
|
|
642
613
|
"inventory.template.yml"
|
|
643
614
|
);
|
|
644
|
-
const outputPath =
|
|
645
|
-
|
|
615
|
+
const outputPath = import_path2.default.join(
|
|
616
|
+
process.cwd(),
|
|
617
|
+
"infrastructure",
|
|
618
|
+
"server-setup",
|
|
619
|
+
"inventory",
|
|
620
|
+
`${env}.yml`
|
|
621
|
+
);
|
|
622
|
+
const templateFile = import_fs2.default.readFileSync(templatePath, "utf-8");
|
|
646
623
|
const template = import_handlebars.default.compile(templateFile);
|
|
647
624
|
values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
|
|
648
625
|
const updated = template(values);
|
|
649
|
-
|
|
650
|
-
|
|
626
|
+
import_fs2.default.mkdirSync(import_path2.default.dirname(outputPath), { recursive: true });
|
|
627
|
+
import_fs2.default.writeFileSync(outputPath, updated);
|
|
651
628
|
log(`
|
|
652
629
|
\u2705 Generated inventory file at ${outputPath}
|
|
653
630
|
`);
|
|
654
631
|
}
|
|
655
|
-
var
|
|
632
|
+
var import_fs2, import_path2, import_handlebars;
|
|
656
633
|
var init_templates = __esm({
|
|
657
634
|
"src/environment/templates.ts"() {
|
|
658
635
|
"use strict";
|
|
659
|
-
|
|
660
|
-
|
|
636
|
+
import_fs2 = __toESM(require("fs"));
|
|
637
|
+
import_path2 = __toESM(require("path"));
|
|
661
638
|
init_logger();
|
|
662
|
-
init_paths();
|
|
663
639
|
import_handlebars = __toESM(require("handlebars"));
|
|
664
640
|
import_handlebars.default.registerHelper("data_label_idx", function(value) {
|
|
665
641
|
return parseInt(value) + 2;
|
|
@@ -1275,7 +1251,7 @@ function getCurrentUserSSHKeys() {
|
|
|
1275
1251
|
keys.push(keyContent);
|
|
1276
1252
|
}
|
|
1277
1253
|
}
|
|
1278
|
-
} catch (
|
|
1254
|
+
} catch (error4) {
|
|
1279
1255
|
continue;
|
|
1280
1256
|
}
|
|
1281
1257
|
}
|
|
@@ -1811,7 +1787,6 @@ var init_setup_environment = __esm({
|
|
|
1811
1787
|
init_editor_questions();
|
|
1812
1788
|
init_questions_helper();
|
|
1813
1789
|
init_manage_users();
|
|
1814
|
-
init_paths();
|
|
1815
1790
|
ALL_QUESTIONS = [];
|
|
1816
1791
|
ALL_ANSWERS = [];
|
|
1817
1792
|
ALL_QUESTIONS.push(
|
|
@@ -1975,7 +1950,9 @@ var init_setup_environment = __esm({
|
|
|
1975
1950
|
);
|
|
1976
1951
|
const kubeWorkerNodes = infrastructure.kubeWorkerNodes ? infrastructure.kubeWorkerNodes.split(",").map((ip) => ip.trim()) : [];
|
|
1977
1952
|
log("\n", import_kleur4.default.bold().underline("SSH Users"), "\n");
|
|
1978
|
-
const users = await manageUsers(
|
|
1953
|
+
const users = await manageUsers(
|
|
1954
|
+
`infrastructure/server-setup/inventory/${environment}.yml`
|
|
1955
|
+
);
|
|
1979
1956
|
log("\n", import_kleur4.default.bold().underline("Traefik SSL Certificate"), "\n");
|
|
1980
1957
|
const sslCertExists = findExistingValue(
|
|
1981
1958
|
"SSL_CRT",
|
|
@@ -2313,6 +2290,40 @@ var init_setup_environment = __esm({
|
|
|
2313
2290
|
),
|
|
2314
2291
|
scope: "ENVIRONMENT"
|
|
2315
2292
|
},
|
|
2293
|
+
{
|
|
2294
|
+
name: "MONGODB_ADMIN_USER",
|
|
2295
|
+
type: "SECRET",
|
|
2296
|
+
didExist: findExistingValue(
|
|
2297
|
+
"MONGODB_ADMIN_USER",
|
|
2298
|
+
"SECRET",
|
|
2299
|
+
"ENVIRONMENT",
|
|
2300
|
+
existingValues
|
|
2301
|
+
),
|
|
2302
|
+
value: findExistingOrDefine(
|
|
2303
|
+
"MONGODB_ADMIN_USER",
|
|
2304
|
+
"SECRET",
|
|
2305
|
+
"ENVIRONMENT",
|
|
2306
|
+
generateLongPassword()
|
|
2307
|
+
),
|
|
2308
|
+
scope: "ENVIRONMENT"
|
|
2309
|
+
},
|
|
2310
|
+
{
|
|
2311
|
+
name: "MONGODB_ADMIN_PASSWORD",
|
|
2312
|
+
type: "SECRET",
|
|
2313
|
+
didExist: findExistingValue(
|
|
2314
|
+
"MONGODB_ADMIN_PASSWORD",
|
|
2315
|
+
"SECRET",
|
|
2316
|
+
"ENVIRONMENT",
|
|
2317
|
+
existingValues
|
|
2318
|
+
),
|
|
2319
|
+
value: findExistingOrDefine(
|
|
2320
|
+
"MONGODB_ADMIN_PASSWORD",
|
|
2321
|
+
"SECRET",
|
|
2322
|
+
"ENVIRONMENT",
|
|
2323
|
+
generateLongPassword()
|
|
2324
|
+
),
|
|
2325
|
+
scope: "ENVIRONMENT"
|
|
2326
|
+
},
|
|
2316
2327
|
{
|
|
2317
2328
|
name: "POSTGRES_USER",
|
|
2318
2329
|
type: "SECRET",
|
|
@@ -2789,11 +2800,11 @@ __export(update_workflows_exports, {
|
|
|
2789
2800
|
updateWorkflowEnvironments: () => updateWorkflowEnvironments
|
|
2790
2801
|
});
|
|
2791
2802
|
async function extractInfrastructureNames() {
|
|
2792
|
-
const files =
|
|
2793
|
-
const infraEnvironments = files.map((file) => (0,
|
|
2803
|
+
const files = glob.sync("infrastructure/server-setup/inventory/*.yml");
|
|
2804
|
+
const infraEnvironments = files.map((file) => (0, import_path3.basename)(file, ".yml"));
|
|
2794
2805
|
if (infraEnvironments.length === 0) {
|
|
2795
2806
|
console.log(
|
|
2796
|
-
|
|
2807
|
+
"\u26A0\uFE0F Warning: No environment directories found in infrastructure/server-setup/inventory/"
|
|
2797
2808
|
);
|
|
2798
2809
|
return [];
|
|
2799
2810
|
}
|
|
@@ -2803,8 +2814,8 @@ async function extractInfrastructureNames() {
|
|
|
2803
2814
|
async function extractEnvironmentNames() {
|
|
2804
2815
|
const entries = await (0, import_promises.readdir)("environments");
|
|
2805
2816
|
const environments = entries.filter((entry) => {
|
|
2806
|
-
const fullPath = (0,
|
|
2807
|
-
return (0,
|
|
2817
|
+
const fullPath = (0, import_path3.join)("environments", entry);
|
|
2818
|
+
return (0, import_fs3.statSync)(fullPath).isDirectory();
|
|
2808
2819
|
});
|
|
2809
2820
|
if (environments.length === 0) {
|
|
2810
2821
|
console.log(
|
|
@@ -2830,7 +2841,7 @@ async function updateWorkflows(envList, config) {
|
|
|
2830
2841
|
const { workflows } = config;
|
|
2831
2842
|
for (const workflowPath of workflows) {
|
|
2832
2843
|
try {
|
|
2833
|
-
const fileContents = (0,
|
|
2844
|
+
const fileContents = (0, import_fs3.readFileSync)(workflowPath, "utf8");
|
|
2834
2845
|
const workflowData = yaml2.load(fileContents);
|
|
2835
2846
|
if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
|
|
2836
2847
|
throw new Error(
|
|
@@ -2838,15 +2849,15 @@ async function updateWorkflows(envList, config) {
|
|
|
2838
2849
|
);
|
|
2839
2850
|
}
|
|
2840
2851
|
const updatedContent = updateOptionsInYaml(fileContents, envList);
|
|
2841
|
-
(0,
|
|
2852
|
+
(0, import_fs3.writeFileSync)(workflowPath, updatedContent, "utf8");
|
|
2842
2853
|
log(` \u2713 Successfully updated ${workflowPath}`);
|
|
2843
|
-
} catch (
|
|
2854
|
+
} catch (error4) {
|
|
2844
2855
|
console.error(
|
|
2845
2856
|
`
|
|
2846
2857
|
\u26A0\uFE0F Error updating ${workflowPath} with environments: [${envList.join(", ")}]`
|
|
2847
2858
|
);
|
|
2848
|
-
console.error(`\u2717 Failed to update ${workflowPath}:`,
|
|
2849
|
-
throw
|
|
2859
|
+
console.error(`\u2717 Failed to update ${workflowPath}:`, error4);
|
|
2860
|
+
throw error4;
|
|
2850
2861
|
}
|
|
2851
2862
|
}
|
|
2852
2863
|
}
|
|
@@ -2887,89 +2898,21 @@ async function updateWorkflowEnvironments() {
|
|
|
2887
2898
|
} else {
|
|
2888
2899
|
log("\u2139\uFE0F No workflows were updated.");
|
|
2889
2900
|
}
|
|
2890
|
-
} catch (
|
|
2891
|
-
console.error("\n\u274C Error updating workflows:",
|
|
2901
|
+
} catch (error4) {
|
|
2902
|
+
console.error("\n\u274C Error updating workflows:", error4);
|
|
2892
2903
|
process.exit(1);
|
|
2893
2904
|
}
|
|
2894
2905
|
}
|
|
2895
|
-
var import_promises,
|
|
2906
|
+
var import_promises, import_fs3, import_path3, glob, yaml2;
|
|
2896
2907
|
var init_update_workflows = __esm({
|
|
2897
2908
|
"src/environment/update-workflows.ts"() {
|
|
2898
2909
|
"use strict";
|
|
2899
2910
|
import_promises = require("fs/promises");
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2911
|
+
import_fs3 = require("fs");
|
|
2912
|
+
import_path3 = require("path");
|
|
2913
|
+
glob = __toESM(require("glob"));
|
|
2903
2914
|
yaml2 = __toESM(require("js-yaml"));
|
|
2904
2915
|
init_logger();
|
|
2905
|
-
init_paths();
|
|
2906
|
-
}
|
|
2907
|
-
});
|
|
2908
|
-
|
|
2909
|
-
// src/environment/upgrade.ts
|
|
2910
|
-
var upgrade_exports = {};
|
|
2911
|
-
__export(upgrade_exports, {
|
|
2912
|
-
upgradeEnvironmentLayout: () => upgradeEnvironmentLayout
|
|
2913
|
-
});
|
|
2914
|
-
function moveFileIfDestinationMissing(sourcePath, destinationPath) {
|
|
2915
|
-
if (!(0, import_fs5.existsSync)(sourcePath)) {
|
|
2916
|
-
return false;
|
|
2917
|
-
}
|
|
2918
|
-
if ((0, import_fs5.existsSync)(destinationPath)) {
|
|
2919
|
-
warn(
|
|
2920
|
-
`\u26A0\uFE0F Skipped ${sourcePath}; destination already exists at ${destinationPath}`
|
|
2921
|
-
);
|
|
2922
|
-
return false;
|
|
2923
|
-
}
|
|
2924
|
-
(0, import_fs5.mkdirSync)((0, import_path5.dirname)(destinationPath), { recursive: true });
|
|
2925
|
-
(0, import_fs5.renameSync)(sourcePath, destinationPath);
|
|
2926
|
-
log(` \u2713 Moved ${sourcePath} -> ${destinationPath}`);
|
|
2927
|
-
return true;
|
|
2928
|
-
}
|
|
2929
|
-
function migrateInventoryFiles() {
|
|
2930
|
-
const oldInventoryFiles = findOldInventoryFiles();
|
|
2931
|
-
if (oldInventoryFiles.length === 0) {
|
|
2932
|
-
log(`\u2139\uFE0F No old inventory files found at ${OLD_INVENTORY_DIR}`);
|
|
2933
|
-
return false;
|
|
2934
|
-
}
|
|
2935
|
-
log(import_kleur5.default.bold("\nMigrating Ansible inventory files"));
|
|
2936
|
-
let didMoveInventory = false;
|
|
2937
|
-
for (const oldInventoryFile of oldInventoryFiles) {
|
|
2938
|
-
const environment = getEnvironmentNameFromOldInventoryPath(oldInventoryFile);
|
|
2939
|
-
didMoveInventory = moveFileIfDestinationMissing(
|
|
2940
|
-
oldInventoryFile,
|
|
2941
|
-
getEnvironmentInventoryPath(environment)
|
|
2942
|
-
) || didMoveInventory;
|
|
2943
|
-
}
|
|
2944
|
-
try {
|
|
2945
|
-
if ((0, import_fs5.existsSync)(OLD_INVENTORY_DIR) && (0, import_fs5.readdirSync)(OLD_INVENTORY_DIR).length === 0) {
|
|
2946
|
-
(0, import_fs5.rmdirSync)(OLD_INVENTORY_DIR);
|
|
2947
|
-
log(` \u2713 Removed empty ${OLD_INVENTORY_DIR}`);
|
|
2948
|
-
}
|
|
2949
|
-
} catch {
|
|
2950
|
-
warn(`\u26A0\uFE0F Could not remove ${OLD_INVENTORY_DIR}; please review it manually`);
|
|
2951
|
-
}
|
|
2952
|
-
return didMoveInventory;
|
|
2953
|
-
}
|
|
2954
|
-
async function upgradeEnvironmentLayout() {
|
|
2955
|
-
const didMoveInventory = migrateInventoryFiles();
|
|
2956
|
-
await updateWorkflowEnvironments();
|
|
2957
|
-
if (didMoveInventory) {
|
|
2958
|
-
success("\n\u2705 Environment layout upgrade completed successfully.");
|
|
2959
|
-
return;
|
|
2960
|
-
}
|
|
2961
|
-
success("\n\u2705 Environment layout already uses the current structure.");
|
|
2962
|
-
}
|
|
2963
|
-
var import_fs5, import_path5, import_kleur5;
|
|
2964
|
-
var init_upgrade = __esm({
|
|
2965
|
-
"src/environment/upgrade.ts"() {
|
|
2966
|
-
"use strict";
|
|
2967
|
-
import_fs5 = require("fs");
|
|
2968
|
-
import_path5 = require("path");
|
|
2969
|
-
import_kleur5 = __toESM(require("kleur"));
|
|
2970
|
-
init_logger();
|
|
2971
|
-
init_paths();
|
|
2972
|
-
init_update_workflows();
|
|
2973
2916
|
}
|
|
2974
2917
|
});
|
|
2975
2918
|
|
|
@@ -2982,7 +2925,7 @@ async function select4(options) {
|
|
|
2982
2925
|
const inquirer = await import("@inquirer/prompts");
|
|
2983
2926
|
return inquirer.select(options);
|
|
2984
2927
|
}
|
|
2985
|
-
async function selectInventoryFile(dirPath = "./
|
|
2928
|
+
async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inventory/") {
|
|
2986
2929
|
if (!fs4.existsSync(dirPath)) {
|
|
2987
2930
|
warn(`\u26A0\uFE0F No environment configuration directory found at ${dirPath}`);
|
|
2988
2931
|
warn(
|
|
@@ -2990,20 +2933,22 @@ async function selectInventoryFile(dirPath = "./environments") {
|
|
|
2990
2933
|
);
|
|
2991
2934
|
return null;
|
|
2992
2935
|
}
|
|
2993
|
-
const
|
|
2994
|
-
const filePath = path4.join(dirPath,
|
|
2995
|
-
|
|
2936
|
+
const files = fs4.readdirSync(dirPath).filter((file) => {
|
|
2937
|
+
const filePath = path4.join(dirPath, file);
|
|
2938
|
+
const isFile = fs4.statSync(filePath).isFile();
|
|
2939
|
+
const ext = path4.extname(file).slice(1).toLowerCase();
|
|
2940
|
+
return isFile && (ext === "yml" || ext === "yaml");
|
|
2996
2941
|
}).sort();
|
|
2997
|
-
if (
|
|
2942
|
+
if (files.length === 0) {
|
|
2998
2943
|
warn(`\u26A0\uFE0F No environment configuration files found at ${dirPath}`);
|
|
2999
2944
|
warn(
|
|
3000
2945
|
"Hint: If this is a new infrastructure repository, run `opencrvs environment init` first."
|
|
3001
2946
|
);
|
|
3002
2947
|
return null;
|
|
3003
2948
|
}
|
|
3004
|
-
const choices =
|
|
3005
|
-
name:
|
|
3006
|
-
value:
|
|
2949
|
+
const choices = files.map((file) => ({
|
|
2950
|
+
name: path4.basename(file, path4.extname(file)),
|
|
2951
|
+
value: path4.join(dirPath, file)
|
|
3007
2952
|
}));
|
|
3008
2953
|
const selectedFile = await select4({
|
|
3009
2954
|
message: "Select environment (inventory file) to load users:",
|
|
@@ -3012,34 +2957,33 @@ async function selectInventoryFile(dirPath = "./environments") {
|
|
|
3012
2957
|
return selectedFile;
|
|
3013
2958
|
}
|
|
3014
2959
|
async function manageEnvironmentUsers() {
|
|
3015
|
-
console.log("\n",
|
|
2960
|
+
console.log("\n", import_kleur5.default.bold().underline("Manage users"), "\n");
|
|
3016
2961
|
const inventory_file = await selectInventoryFile();
|
|
3017
2962
|
if (!inventory_file) {
|
|
3018
2963
|
return;
|
|
3019
2964
|
}
|
|
3020
2965
|
await manageUsers(inventory_file);
|
|
3021
2966
|
}
|
|
3022
|
-
var fs4, path4,
|
|
2967
|
+
var fs4, path4, import_kleur5;
|
|
3023
2968
|
var init_users = __esm({
|
|
3024
2969
|
"src/environment/users.ts"() {
|
|
3025
2970
|
"use strict";
|
|
3026
2971
|
fs4 = __toESM(require("fs"));
|
|
3027
2972
|
path4 = __toESM(require("path"));
|
|
3028
|
-
|
|
2973
|
+
import_kleur5 = __toESM(require("kleur"));
|
|
3029
2974
|
init_manage_users();
|
|
3030
2975
|
init_logger();
|
|
3031
|
-
init_paths();
|
|
3032
2976
|
}
|
|
3033
2977
|
});
|
|
3034
2978
|
|
|
3035
2979
|
// src/environment/swarm-to-k8s.ts
|
|
3036
2980
|
var swarm_to_k8s_exports = {};
|
|
3037
|
-
var path5,
|
|
2981
|
+
var path5, import_kleur6, import_core2;
|
|
3038
2982
|
var init_swarm_to_k8s = __esm({
|
|
3039
2983
|
"src/environment/swarm-to-k8s.ts"() {
|
|
3040
2984
|
"use strict";
|
|
3041
2985
|
path5 = __toESM(require("path"));
|
|
3042
|
-
|
|
2986
|
+
import_kleur6 = __toESM(require("kleur"));
|
|
3043
2987
|
init_logger();
|
|
3044
2988
|
init_utils();
|
|
3045
2989
|
init_templates();
|
|
@@ -3048,7 +2992,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
3048
2992
|
init_github();
|
|
3049
2993
|
(async () => {
|
|
3050
2994
|
log(
|
|
3051
|
-
|
|
2995
|
+
import_kleur6.default.bold(
|
|
3052
2996
|
"------------------------------------------------\nOpenCRVS Infrastructure migration script: \nMigrating Swarm configurations to Kubernetes\n------------------------------------------------\n"
|
|
3053
2997
|
)
|
|
3054
2998
|
);
|
|
@@ -3079,7 +3023,7 @@ var init_swarm_to_k8s = __esm({
|
|
|
3079
3023
|
);
|
|
3080
3024
|
process.exit(0);
|
|
3081
3025
|
}
|
|
3082
|
-
log(
|
|
3026
|
+
log(import_kleur6.default.bold().underline("Migration properties:"));
|
|
3083
3027
|
log(` \u2713 Environment: ${environment}`);
|
|
3084
3028
|
const old_inventory_path = process.env.OLD_INVENTORY_PATH || "";
|
|
3085
3029
|
if (!old_inventory_path) {
|
|
@@ -3397,9 +3341,8 @@ async function runUpgrade(dockerSwarm) {
|
|
|
3397
3341
|
}
|
|
3398
3342
|
|
|
3399
3343
|
// src/environment/index.ts
|
|
3400
|
-
var
|
|
3401
|
-
var
|
|
3402
|
-
init_paths();
|
|
3344
|
+
var import_fs4 = require("fs");
|
|
3345
|
+
var import_path4 = require("path");
|
|
3403
3346
|
var REQUIRED_REPOSITORY_DIRECTORIES = [
|
|
3404
3347
|
".github/workflows",
|
|
3405
3348
|
"environments",
|
|
@@ -3409,7 +3352,7 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
|
3409
3352
|
const missingDirectories = REQUIRED_REPOSITORY_DIRECTORIES.filter(
|
|
3410
3353
|
(directory) => {
|
|
3411
3354
|
try {
|
|
3412
|
-
return !(0,
|
|
3355
|
+
return !(0, import_fs4.statSync)((0, import_path4.resolve)(repositoryRoot, directory)).isDirectory();
|
|
3413
3356
|
} catch {
|
|
3414
3357
|
return true;
|
|
3415
3358
|
}
|
|
@@ -3423,14 +3366,8 @@ function validateRepositoryStructure(repositoryRoot = process.cwd()) {
|
|
|
3423
3366
|
}
|
|
3424
3367
|
async function runEnvironmentInit() {
|
|
3425
3368
|
validateRepositoryStructure();
|
|
3426
|
-
assertNoOldInventoryLayout();
|
|
3427
3369
|
await Promise.resolve().then(() => (init_setup_environment(), setup_environment_exports));
|
|
3428
3370
|
}
|
|
3429
|
-
async function runEnvironmentUpgrade() {
|
|
3430
|
-
validateRepositoryStructure();
|
|
3431
|
-
const { upgradeEnvironmentLayout: upgradeEnvironmentLayout2 } = await Promise.resolve().then(() => (init_upgrade(), upgrade_exports));
|
|
3432
|
-
await upgradeEnvironmentLayout2();
|
|
3433
|
-
}
|
|
3434
3371
|
async function runEnvironmentUpdateWorkflows() {
|
|
3435
3372
|
validateRepositoryStructure();
|
|
3436
3373
|
const { updateWorkflowEnvironments: updateWorkflowEnvironments2 } = await Promise.resolve().then(() => (init_update_workflows(), update_workflows_exports));
|
|
@@ -3500,7 +3437,6 @@ Usage: opencrvs environment <subcommand>
|
|
|
3500
3437
|
|
|
3501
3438
|
Subcommands:
|
|
3502
3439
|
init Initialise a new environment
|
|
3503
|
-
upgrade Upgrade existing environment configuration layout
|
|
3504
3440
|
update-workflows Update workflow environment options
|
|
3505
3441
|
users Manage environment users
|
|
3506
3442
|
swarm-to-k8s Migrate Docker Swarm configuration to Kubernetes
|
|
@@ -3511,8 +3447,6 @@ Subcommands:
|
|
|
3511
3447
|
switch (subcommand) {
|
|
3512
3448
|
case "init":
|
|
3513
3449
|
return runEnvironmentCommand("initialisation", runEnvironmentInit);
|
|
3514
|
-
case "upgrade":
|
|
3515
|
-
return runEnvironmentCommand("environment upgrade", runEnvironmentUpgrade);
|
|
3516
3450
|
case "update-workflows":
|
|
3517
3451
|
return runEnvironmentCommand(
|
|
3518
3452
|
"workflow update",
|
|
@@ -3533,10 +3467,10 @@ Subcommands:
|
|
|
3533
3467
|
async function runEnvironmentCommand(operation, command) {
|
|
3534
3468
|
try {
|
|
3535
3469
|
await command();
|
|
3536
|
-
} catch (
|
|
3470
|
+
} catch (error4) {
|
|
3537
3471
|
console.error(
|
|
3538
3472
|
`Environment ${operation} failed:`,
|
|
3539
|
-
|
|
3473
|
+
error4 instanceof Error ? error4.message : error4
|
|
3540
3474
|
);
|
|
3541
3475
|
process.exit(1);
|
|
3542
3476
|
}
|
|
@@ -3562,8 +3496,8 @@ async function handleUpgrade() {
|
|
|
3562
3496
|
try {
|
|
3563
3497
|
await runUpgrade(dockerSwarm);
|
|
3564
3498
|
console.log("Upgrade completed successfully!");
|
|
3565
|
-
} catch (
|
|
3566
|
-
console.error("Upgrade failed:",
|
|
3499
|
+
} catch (error4) {
|
|
3500
|
+
console.error("Upgrade failed:", error4);
|
|
3567
3501
|
process.exit(1);
|
|
3568
3502
|
}
|
|
3569
3503
|
}
|