@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.
- package/README.md +1 -0
- package/build.sh +3 -3
- package/dist/application-config/index.js +17 -6
- package/dist/cli.js +362 -305
- package/dist/commons/api/router.d.ts +10 -0
- package/dist/commons/conditionals/conditionals.d.ts +3 -3
- package/dist/commons/events/AdvancedSearchConfig.d.ts +12 -0
- package/dist/commons/events/CountryConfigQueryInput.d.ts +42 -0
- package/dist/commons/events/EventConfig.d.ts +2 -0
- package/dist/commons/events/EventIndex.d.ts +25 -0
- package/dist/commons/events/EventMetadata.d.ts +26 -0
- package/dist/commons/events/FieldConfig.d.ts +10 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +39 -0
- package/dist/commons/events/locations.d.ts +1 -0
- package/dist/commons/events/state/index.d.ts +8 -0
- package/dist/commons/events/state/utils.d.ts +9 -0
- package/dist/conditionals/index.js +10 -5
- package/dist/environment/custom-types.d.ts.map +1 -1
- package/dist/environment/custom-types.js +10 -0
- package/dist/environment/derived-variables.d.ts.map +1 -1
- package/dist/environment/derived-variables.js +11 -1
- package/dist/environment/editor-questions.d.ts +0 -1
- package/dist/environment/editor-questions.d.ts.map +1 -1
- package/dist/environment/editor-questions.js +16 -5
- package/dist/environment/git.d.ts.map +1 -1
- package/dist/environment/git.js +15 -5
- package/dist/environment/github.d.ts.map +1 -1
- package/dist/environment/github.js +25 -12
- package/dist/environment/index.d.ts +0 -1
- package/dist/environment/index.d.ts.map +1 -1
- package/dist/environment/index.js +12 -2
- package/dist/environment/logger.d.ts.map +1 -1
- package/dist/environment/logger.js +10 -0
- package/dist/environment/manage-users.d.ts.map +1 -1
- package/dist/environment/manage-users.js +21 -8
- package/dist/environment/questions-helper.d.ts.map +1 -1
- package/dist/environment/questions-helper.js +15 -5
- package/dist/environment/questions.d.ts +0 -23
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/questions.js +24 -67
- package/dist/environment/setup-environment.js +85 -54
- package/dist/environment/ssh-keygen.d.ts.map +1 -1
- package/dist/environment/ssh-keygen.js +15 -2
- package/dist/environment/swarm-to-k8s.js +26 -15
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/environment/templates.js +26 -12
- package/dist/environment/update-workflows.d.ts.map +1 -1
- package/dist/environment/update-workflows.js +48 -30
- package/dist/environment/users.d.ts +1 -1
- package/dist/environment/users.d.ts.map +1 -1
- package/dist/environment/users.js +29 -9
- package/dist/environment/utils.d.ts.map +1 -1
- package/dist/environment/utils.js +11 -1
- package/dist/events/index.js +40 -6
- package/dist/migrations/v2.0/index.js +10 -5
- package/dist/notification/index.js +17 -6
- package/dist/scopes/index.d.ts +89 -1
- package/dist/scopes/index.js +10 -5
- package/dist/{environment/templates → templates}/charts-values/dependencies/values.yaml +7 -6
- package/dist/{environment/templates/charts-values/dependencies → templates/charts-values/opencrvs-services}/values.override.yaml +1 -1
- package/dist/{environment/templates → templates}/charts-values/opencrvs-services/values.yaml +8 -6
- package/dist/{environment/templates → templates}/charts-values/traefik/values.override.yaml +1 -1
- package/dist/{environment/templates → templates}/charts-values/traefik/values.yaml +6 -7
- package/dist/{environment/templates → templates}/inventory/production.example.yml +2 -2
- package/opencrvs-toolkit-2.0.0-rc.bd854e0.tgz +0 -0
- package/package.json +1 -1
- package/opencrvs-toolkit-2.0.0-rc.bd55713.tgz +0 -0
- /package/dist/{environment/templates/charts-values/opencrvs-services → templates/charts-values/dependencies}/values.override.yaml +0 -0
- /package/dist/{environment/templates → templates}/inventory/inventory.template.yml +0 -0
- /package/dist/{environment/templates → templates}/inventory/qa.example.yml +0 -0
package/dist/cli.js
CHANGED
|
@@ -143,19 +143,19 @@ async function getPublicKey(octokit, environment, ORGANISATION, REPOSITORY_NAME)
|
|
|
143
143
|
return res.data;
|
|
144
144
|
}
|
|
145
145
|
async function createEnvironmentSecret(octokit, repositoryId, environment, name, secret, organisationName, repositoryName) {
|
|
146
|
-
await
|
|
146
|
+
await import_libsodium_wrappers.default.ready;
|
|
147
147
|
const { key, key_id } = await getPublicKey(
|
|
148
148
|
octokit,
|
|
149
149
|
environment,
|
|
150
150
|
organisationName,
|
|
151
151
|
repositoryName
|
|
152
152
|
);
|
|
153
|
-
const binkey =
|
|
154
|
-
const binsec =
|
|
155
|
-
const encBytes =
|
|
156
|
-
const encryptedValue =
|
|
153
|
+
const binkey = import_libsodium_wrappers.default.from_base64(key, import_libsodium_wrappers.default.base64_variants.ORIGINAL);
|
|
154
|
+
const binsec = import_libsodium_wrappers.default.from_string(secret);
|
|
155
|
+
const encBytes = import_libsodium_wrappers.default.crypto_box_seal(binsec, binkey);
|
|
156
|
+
const encryptedValue = import_libsodium_wrappers.default.to_base64(
|
|
157
157
|
encBytes,
|
|
158
|
-
|
|
158
|
+
import_libsodium_wrappers.default.base64_variants.ORIGINAL
|
|
159
159
|
);
|
|
160
160
|
await octokit.request(
|
|
161
161
|
`PUT /repositories/${repositoryId}/environments/${environment}/secrets/${name}`,
|
|
@@ -172,18 +172,18 @@ async function createEnvironmentSecret(octokit, repositoryId, environment, name,
|
|
|
172
172
|
);
|
|
173
173
|
}
|
|
174
174
|
async function createRepositorySecret(octokit, repositoryId, name, secret, organisationName, repositoryName) {
|
|
175
|
-
await
|
|
175
|
+
await import_libsodium_wrappers.default.ready;
|
|
176
176
|
const { key, key_id } = await getRepositoryPublicKey(
|
|
177
177
|
octokit,
|
|
178
178
|
organisationName,
|
|
179
179
|
repositoryName
|
|
180
180
|
);
|
|
181
|
-
const binkey =
|
|
182
|
-
const binsec =
|
|
183
|
-
const encBytes =
|
|
184
|
-
const encryptedValue =
|
|
181
|
+
const binkey = import_libsodium_wrappers.default.from_base64(key, import_libsodium_wrappers.default.base64_variants.ORIGINAL);
|
|
182
|
+
const binsec = import_libsodium_wrappers.default.from_string(secret);
|
|
183
|
+
const encBytes = import_libsodium_wrappers.default.crypto_box_seal(binsec, binkey);
|
|
184
|
+
const encryptedValue = import_libsodium_wrappers.default.to_base64(
|
|
185
185
|
encBytes,
|
|
186
|
-
|
|
186
|
+
import_libsodium_wrappers.default.base64_variants.ORIGINAL
|
|
187
187
|
);
|
|
188
188
|
await octokit.request(
|
|
189
189
|
`PUT /repositories/${repositoryId}/actions/secrets/${name}`,
|
|
@@ -197,10 +197,13 @@ async function createRepositorySecret(octokit, repositoryId, name, secret, organ
|
|
|
197
197
|
);
|
|
198
198
|
}
|
|
199
199
|
async function getRepositoryEnvironments(octokit, githubOrganisation, repository) {
|
|
200
|
-
const response = await octokit.request(
|
|
201
|
-
githubOrganisation,
|
|
202
|
-
|
|
203
|
-
|
|
200
|
+
const response = await octokit.request(
|
|
201
|
+
"GET /repos/{githubOrganisation}/{repository}/environments",
|
|
202
|
+
{
|
|
203
|
+
githubOrganisation,
|
|
204
|
+
repository
|
|
205
|
+
}
|
|
206
|
+
);
|
|
204
207
|
const environments = (response.data.environments ?? []).map(
|
|
205
208
|
(env) => env.name
|
|
206
209
|
);
|
|
@@ -273,7 +276,9 @@ async function listEnvironmentVariables(octokit, repositoryId, environmentName)
|
|
|
273
276
|
...variable,
|
|
274
277
|
type: "VARIABLE",
|
|
275
278
|
scope: "ENVIRONMENT"
|
|
276
|
-
})).filter(
|
|
279
|
+
})).filter(
|
|
280
|
+
(variable) => variable.name !== "ACTIONS_RUNNER_DEBUG"
|
|
281
|
+
);
|
|
277
282
|
}
|
|
278
283
|
async function listRepositoryVariables(octokit, owner, repositoryName) {
|
|
279
284
|
const response = await octokit.request(
|
|
@@ -290,12 +295,12 @@ async function listRepositoryVariables(octokit, owner, repositoryName) {
|
|
|
290
295
|
scope: "REPOSITORY"
|
|
291
296
|
}));
|
|
292
297
|
}
|
|
293
|
-
var
|
|
298
|
+
var import_libsodium_wrappers;
|
|
294
299
|
var init_github = __esm({
|
|
295
300
|
"src/environment/github.ts"() {
|
|
296
301
|
"use strict";
|
|
302
|
+
import_libsodium_wrappers = __toESM(require("libsodium-wrappers"));
|
|
297
303
|
init_logger();
|
|
298
|
-
sodium = require("libsodium-wrappers");
|
|
299
304
|
}
|
|
300
305
|
});
|
|
301
306
|
|
|
@@ -543,7 +548,9 @@ function extractAndModifyUsers(data) {
|
|
|
543
548
|
}
|
|
544
549
|
function dockerManagerFirst(data) {
|
|
545
550
|
if (!data?.["docker-manager-first"]?.hosts) {
|
|
546
|
-
throw new Error(
|
|
551
|
+
throw new Error(
|
|
552
|
+
"Invalid YAML structure: missing docker-manager-first.hosts"
|
|
553
|
+
);
|
|
547
554
|
}
|
|
548
555
|
const hosts = data["docker-manager-first"].hosts;
|
|
549
556
|
const dockerManagerFirst2 = Object.values(hosts).filter((host) => host.ansible_host).map((host) => host.ansible_host);
|
|
@@ -571,6 +578,7 @@ function copyChartsValues(env, values) {
|
|
|
571
578
|
import_fs8.default.mkdirSync(destDir, { recursive: true });
|
|
572
579
|
values["lets_encrypt"] = values["traefik_mode"] === "lets_encrypt";
|
|
573
580
|
values["static_ssl"] = values["traefik_mode"] === "static_ssl";
|
|
581
|
+
values["opencrvs_environment"] = env;
|
|
574
582
|
function copyRecursive(src, dest) {
|
|
575
583
|
const stat = import_fs8.default.statSync(src);
|
|
576
584
|
if (stat.isDirectory()) {
|
|
@@ -598,8 +606,19 @@ function copyChartsValues(env, values) {
|
|
|
598
606
|
`);
|
|
599
607
|
}
|
|
600
608
|
function generateInventory(env, values) {
|
|
601
|
-
const templatePath = import_path27.default.join(
|
|
602
|
-
|
|
609
|
+
const templatePath = import_path27.default.join(
|
|
610
|
+
__dirname,
|
|
611
|
+
"templates",
|
|
612
|
+
"inventory",
|
|
613
|
+
"inventory.template.yml"
|
|
614
|
+
);
|
|
615
|
+
const outputPath = import_path27.default.join(
|
|
616
|
+
process.cwd(),
|
|
617
|
+
"infrastructure",
|
|
618
|
+
"server-setup",
|
|
619
|
+
"inventory",
|
|
620
|
+
`${env}.yml`
|
|
621
|
+
);
|
|
603
622
|
const templateFile = import_fs8.default.readFileSync(templatePath, "utf-8");
|
|
604
623
|
const template = import_handlebars.default.compile(templateFile);
|
|
605
624
|
values["single_node"] = values["kube_worker_nodes"].length > 0 || values["backup_host"] ? "false" : "true";
|
|
@@ -626,8 +645,11 @@ var init_templates = __esm({
|
|
|
626
645
|
|
|
627
646
|
// src/environment/ssh-keygen.ts
|
|
628
647
|
function generateSSHKeyPair() {
|
|
629
|
-
|
|
630
|
-
return {
|
|
648
|
+
const keys = import_ssh2.utils.generateKeyPairSync("ed25519");
|
|
649
|
+
return {
|
|
650
|
+
publicKey: keys.public.toString(),
|
|
651
|
+
privateKey: keys.private.toString()
|
|
652
|
+
};
|
|
631
653
|
}
|
|
632
654
|
var import_ssh2;
|
|
633
655
|
var init_ssh_keygen = __esm({
|
|
@@ -687,7 +709,7 @@ function validateCIDRs(input3) {
|
|
|
687
709
|
}
|
|
688
710
|
return true;
|
|
689
711
|
}
|
|
690
|
-
var import_kleur2, notEmpty, dockerhubQuestions, githubQuestions, githubOtherQuestions, githubTokenQuestion, countryQuestions, infrastructureQuestions, staticSSLCertQuestions, backupQuestions, diskQuestions, databaseAndMonitoringQuestions,
|
|
712
|
+
var import_kleur2, notEmpty, dockerhubQuestions, githubQuestions, githubOtherQuestions, githubTokenQuestion, countryQuestions, infrastructureQuestions, staticSSLCertQuestions, backupQuestions, diskQuestions, databaseAndMonitoringQuestions, emailQuestions, sentryQuestions, metabaseAdminQuestions;
|
|
691
713
|
var init_questions = __esm({
|
|
692
714
|
"src/environment/questions.ts"() {
|
|
693
715
|
"use strict";
|
|
@@ -953,59 +975,6 @@ Leave at least 50g available for OS use.`,
|
|
|
953
975
|
scope: "ENVIRONMENT"
|
|
954
976
|
}
|
|
955
977
|
];
|
|
956
|
-
notificationTransportQuestions = [
|
|
957
|
-
{
|
|
958
|
-
name: "notificationTransport",
|
|
959
|
-
type: "select",
|
|
960
|
-
message: "Notification transport for 2FA, informant and user messaging",
|
|
961
|
-
choices: [
|
|
962
|
-
{
|
|
963
|
-
title: "Email (with SMTP details)",
|
|
964
|
-
value: "email"
|
|
965
|
-
},
|
|
966
|
-
{
|
|
967
|
-
title: "SMS (Infobip)",
|
|
968
|
-
value: "sms"
|
|
969
|
-
}
|
|
970
|
-
],
|
|
971
|
-
valueLabel: "NOTIFICATION_TRANSPORT",
|
|
972
|
-
valueType: "VARIABLE",
|
|
973
|
-
scope: "ENVIRONMENT",
|
|
974
|
-
initial: process.env.NOTIFICATION_TRANSPORT
|
|
975
|
-
}
|
|
976
|
-
];
|
|
977
|
-
smsQuestions = [
|
|
978
|
-
{
|
|
979
|
-
name: "infobipApiKey",
|
|
980
|
-
type: "text",
|
|
981
|
-
message: "What is your Infobip API key?",
|
|
982
|
-
valueType: "SECRET",
|
|
983
|
-
validate: notEmpty,
|
|
984
|
-
valueLabel: "INFOBIP_API_KEY",
|
|
985
|
-
initial: process.env.INFOBIP_API_KEY,
|
|
986
|
-
scope: "ENVIRONMENT"
|
|
987
|
-
},
|
|
988
|
-
{
|
|
989
|
-
name: "infobipGatewayEndpoint",
|
|
990
|
-
type: "text",
|
|
991
|
-
message: "What is your Infobip gateway endpoint?",
|
|
992
|
-
valueType: "SECRET",
|
|
993
|
-
validate: notEmpty,
|
|
994
|
-
valueLabel: "INFOBIP_GATEWAY_ENDPOINT",
|
|
995
|
-
initial: process.env.INFOBIP_GATEWAY_ENDPOINT,
|
|
996
|
-
scope: "ENVIRONMENT"
|
|
997
|
-
},
|
|
998
|
-
{
|
|
999
|
-
name: "infobipSenderId",
|
|
1000
|
-
type: "text",
|
|
1001
|
-
message: "What is your Infobip sender ID?",
|
|
1002
|
-
valueType: "SECRET",
|
|
1003
|
-
validate: notEmpty,
|
|
1004
|
-
valueLabel: "INFOBIP_SENDER_ID",
|
|
1005
|
-
initial: process.env.INFOBIP_SENDER_ID,
|
|
1006
|
-
scope: "ENVIRONMENT"
|
|
1007
|
-
}
|
|
1008
|
-
];
|
|
1009
978
|
emailQuestions = [
|
|
1010
979
|
{
|
|
1011
980
|
name: "smtpHost",
|
|
@@ -1130,7 +1099,7 @@ function editorQuestion(question) {
|
|
|
1130
1099
|
);
|
|
1131
1100
|
}
|
|
1132
1101
|
async function askQuestionWithEditor(questions, existingValues) {
|
|
1133
|
-
|
|
1102
|
+
const answers = [];
|
|
1134
1103
|
for (const question of questions) {
|
|
1135
1104
|
const questionWithVariableLabel = {
|
|
1136
1105
|
...question,
|
|
@@ -1147,18 +1116,22 @@ async function askQuestionWithEditor(questions, existingValues) {
|
|
|
1147
1116
|
);
|
|
1148
1117
|
let updateSecret = true;
|
|
1149
1118
|
if (existingSecret) {
|
|
1150
|
-
updateSecret = (await (0, import_prompts.default)([
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
existingSecret.
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1119
|
+
updateSecret = (await (0, import_prompts.default)([
|
|
1120
|
+
{
|
|
1121
|
+
name: "overWrite",
|
|
1122
|
+
type: "confirm",
|
|
1123
|
+
message: `${import_kleur3.default.yellow(
|
|
1124
|
+
`${existingSecret.scope === "REPOSITORY" ? "Repository secret" : "Secret"} ${import_kleur3.default.cyan(
|
|
1125
|
+
existingSecret.name
|
|
1126
|
+
)} already exists in Github. Do you want to update it?`
|
|
1127
|
+
)}`
|
|
1128
|
+
}
|
|
1129
|
+
])).overWrite;
|
|
1159
1130
|
}
|
|
1160
1131
|
if (!existingSecret || updateSecret === true) {
|
|
1161
|
-
const question_answer = await editorQuestion(
|
|
1132
|
+
const question_answer = await editorQuestion(
|
|
1133
|
+
questionWithVariableLabel.message
|
|
1134
|
+
);
|
|
1162
1135
|
const answer = {
|
|
1163
1136
|
type: "SECRET",
|
|
1164
1137
|
scope: "ENVIRONMENT",
|
|
@@ -1349,7 +1322,9 @@ async function addNewUser(existingUsers) {
|
|
|
1349
1322
|
});
|
|
1350
1323
|
const ssh_keys = keysInput.split("\n").map((key) => key.trim()).filter((key) => key && !key.startsWith("#"));
|
|
1351
1324
|
if (ssh_keys.length === 0) {
|
|
1352
|
-
warn(
|
|
1325
|
+
warn(
|
|
1326
|
+
"\u26A0\uFE0F Warning: No SSH keys provided. User will not be able to login remotely."
|
|
1327
|
+
);
|
|
1353
1328
|
}
|
|
1354
1329
|
const role = await selectRole();
|
|
1355
1330
|
const state = "present";
|
|
@@ -1388,8 +1363,12 @@ async function editUser(user) {
|
|
|
1388
1363
|
console.log("\u2500".repeat(70));
|
|
1389
1364
|
console.log(`\u{1F4DD} Editing user: ${updatedUser.name}`);
|
|
1390
1365
|
console.log("\u2500".repeat(70));
|
|
1391
|
-
console.log(
|
|
1392
|
-
|
|
1366
|
+
console.log(
|
|
1367
|
+
`Current Role: ${updatedUser.role === "admin" ? "\u{1F451} admin" : "\u{1F464} operator"}`
|
|
1368
|
+
);
|
|
1369
|
+
console.log(
|
|
1370
|
+
`Current State: ${updatedUser.state === "present" ? "\u2705 present" : "\u274C absent"}`
|
|
1371
|
+
);
|
|
1393
1372
|
console.log(`Current SSH Keys: ${updatedUser.ssh_keys.length} key(s)`);
|
|
1394
1373
|
if (updatedUser.ssh_keys.length > 0) {
|
|
1395
1374
|
updatedUser.ssh_keys.forEach((key, idx) => {
|
|
@@ -1634,11 +1613,8 @@ async function select3(options) {
|
|
|
1634
1613
|
return inquirer.select(options);
|
|
1635
1614
|
}
|
|
1636
1615
|
function questionToPrompt({
|
|
1637
|
-
// eslint-disable-next-line no-unused-vars
|
|
1638
1616
|
valueType,
|
|
1639
|
-
// eslint-disable-next-line no-unused-vars
|
|
1640
1617
|
valueLabel,
|
|
1641
|
-
// eslint-disable-next-line no-unused-vars
|
|
1642
1618
|
scope,
|
|
1643
1619
|
...promptOptions
|
|
1644
1620
|
}) {
|
|
@@ -1662,39 +1638,42 @@ function getAnswers(existingValues) {
|
|
|
1662
1638
|
const existingQuestion = ALL_QUESTIONS.find(
|
|
1663
1639
|
(question) => question.name === key
|
|
1664
1640
|
);
|
|
1665
|
-
|
|
1641
|
+
if (!existingQuestion?.valueLabel || existingQuestion.valueType !== "SECRET" && existingQuestion.valueType !== "VARIABLE") {
|
|
1642
|
+
throw new Error(`No secret or variable question found for ${key}`);
|
|
1643
|
+
}
|
|
1644
|
+
const { valueLabel, valueType, scope } = existingQuestion;
|
|
1666
1645
|
if (valueType === "SECRET") {
|
|
1667
1646
|
const existingSecret = findExistingValue(
|
|
1668
|
-
|
|
1647
|
+
valueLabel,
|
|
1669
1648
|
"SECRET",
|
|
1670
|
-
|
|
1649
|
+
scope,
|
|
1671
1650
|
existingValues
|
|
1672
1651
|
);
|
|
1673
1652
|
return {
|
|
1674
1653
|
type: valueType,
|
|
1675
|
-
name:
|
|
1654
|
+
name: valueLabel,
|
|
1676
1655
|
value: value.toString(),
|
|
1677
1656
|
didExist: existingSecret,
|
|
1678
|
-
scope
|
|
1657
|
+
scope
|
|
1679
1658
|
};
|
|
1680
1659
|
}
|
|
1681
1660
|
const existingVariable = findExistingValue(
|
|
1682
|
-
|
|
1661
|
+
valueLabel,
|
|
1683
1662
|
valueType,
|
|
1684
|
-
|
|
1663
|
+
scope,
|
|
1685
1664
|
existingValues
|
|
1686
1665
|
);
|
|
1687
1666
|
return {
|
|
1688
1667
|
type: valueType,
|
|
1689
|
-
name:
|
|
1668
|
+
name: valueLabel,
|
|
1690
1669
|
didExist: findExistingValue(
|
|
1691
|
-
|
|
1670
|
+
valueLabel,
|
|
1692
1671
|
valueType,
|
|
1693
|
-
|
|
1672
|
+
scope,
|
|
1694
1673
|
existingValues
|
|
1695
1674
|
),
|
|
1696
1675
|
value: value.toString() || existingVariable?.value || "",
|
|
1697
|
-
scope
|
|
1676
|
+
scope
|
|
1698
1677
|
};
|
|
1699
1678
|
});
|
|
1700
1679
|
});
|
|
@@ -1719,7 +1698,10 @@ async function promptAndStoreAnswer(environment, questions, existingValues) {
|
|
|
1719
1698
|
if (existingVariable) {
|
|
1720
1699
|
let initial_value = existingVariable.value;
|
|
1721
1700
|
if (questionWithVariableLabel.type === "select" && Array.isArray(questionWithVariableLabel.choices)) {
|
|
1722
|
-
initial_value = getIndexFromChoices(
|
|
1701
|
+
initial_value = getIndexFromChoices(
|
|
1702
|
+
questionWithVariableLabel.choices,
|
|
1703
|
+
existingVariable.value
|
|
1704
|
+
);
|
|
1723
1705
|
}
|
|
1724
1706
|
return [
|
|
1725
1707
|
{
|
|
@@ -1840,8 +1822,12 @@ var init_setup_environment = __esm({
|
|
|
1840
1822
|
auth: githubToken
|
|
1841
1823
|
});
|
|
1842
1824
|
log(import_kleur4.default.green("\nSuccessfully logged in to Github\n"));
|
|
1843
|
-
|
|
1844
|
-
|
|
1825
|
+
const existingEnvironments = await getRepositoryEnvironments(
|
|
1826
|
+
octokit,
|
|
1827
|
+
githubOrganisation,
|
|
1828
|
+
githubRepository
|
|
1829
|
+
);
|
|
1830
|
+
const defaultChoices = [
|
|
1845
1831
|
{ name: "Development", value: "development" },
|
|
1846
1832
|
{ name: "Quality assurance (no PII data)", value: "qa" },
|
|
1847
1833
|
{
|
|
@@ -1855,34 +1841,34 @@ var init_setup_environment = __esm({
|
|
|
1855
1841
|
];
|
|
1856
1842
|
const choices = [
|
|
1857
1843
|
...defaultChoices,
|
|
1858
|
-
...existingEnvironments.filter(
|
|
1859
|
-
(env) => !defaultChoices.some((choice) => choice.value === env)
|
|
1860
|
-
).map((env) => ({
|
|
1844
|
+
...existingEnvironments.filter((env) => !defaultChoices.some((choice) => choice.value === env)).map((env) => ({
|
|
1861
1845
|
name: env,
|
|
1862
1846
|
value: env
|
|
1863
1847
|
}))
|
|
1864
1848
|
];
|
|
1865
|
-
const environment = await selectWithCustom(
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
}
|
|
1870
|
-
);
|
|
1849
|
+
const environment = await selectWithCustom({
|
|
1850
|
+
message: "Choose a name and purpose for the environment?",
|
|
1851
|
+
choices
|
|
1852
|
+
});
|
|
1871
1853
|
let environment_type = "non-production";
|
|
1872
1854
|
if (["development", "qa"].includes(environment)) {
|
|
1873
1855
|
environment_type = "non-production";
|
|
1874
1856
|
} else if (["staging", "production"].includes(environment)) {
|
|
1875
1857
|
environment_type = "production";
|
|
1876
1858
|
} else {
|
|
1877
|
-
environment_type = await select3(
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1859
|
+
environment_type = await select3({
|
|
1860
|
+
message: "Purpose for the environment?",
|
|
1861
|
+
choices: [
|
|
1862
|
+
{
|
|
1863
|
+
name: "Development/Quality assurance/Testing (no PII data)",
|
|
1864
|
+
value: "non-production"
|
|
1865
|
+
},
|
|
1866
|
+
{
|
|
1867
|
+
name: "Staging/Production (hosts PII data, requires frequent backups)",
|
|
1868
|
+
value: "production"
|
|
1869
|
+
}
|
|
1870
|
+
]
|
|
1871
|
+
});
|
|
1886
1872
|
}
|
|
1887
1873
|
const environment_exists = existingEnvironments.map((e) => e.trim()).includes(environment);
|
|
1888
1874
|
if (!environment) {
|
|
@@ -1942,10 +1928,17 @@ var init_setup_environment = __esm({
|
|
|
1942
1928
|
);
|
|
1943
1929
|
}
|
|
1944
1930
|
if (environment_type === "production") {
|
|
1945
|
-
log(
|
|
1946
|
-
"
|
|
1947
|
-
|
|
1948
|
-
|
|
1931
|
+
log(
|
|
1932
|
+
"\n",
|
|
1933
|
+
import_kleur4.default.yellow().bold(
|
|
1934
|
+
"WARNING! You are setting up a production environment.\n Make sure you have read the deployment guide carefully before proceeding.\n"
|
|
1935
|
+
)
|
|
1936
|
+
);
|
|
1937
|
+
await promptAndStoreAnswer(
|
|
1938
|
+
environment,
|
|
1939
|
+
githubOtherQuestions,
|
|
1940
|
+
existingValues
|
|
1941
|
+
);
|
|
1949
1942
|
}
|
|
1950
1943
|
log("\n", import_kleur4.default.bold().underline("Docker Hub"));
|
|
1951
1944
|
await promptAndStoreAnswer(environment, dockerhubQuestions, existingValues);
|
|
@@ -1957,7 +1950,9 @@ var init_setup_environment = __esm({
|
|
|
1957
1950
|
);
|
|
1958
1951
|
const kubeWorkerNodes = infrastructure.kubeWorkerNodes ? infrastructure.kubeWorkerNodes.split(",").map((ip) => ip.trim()) : [];
|
|
1959
1952
|
log("\n", import_kleur4.default.bold().underline("SSH Users"), "\n");
|
|
1960
|
-
const users = await manageUsers(
|
|
1953
|
+
const users = await manageUsers(
|
|
1954
|
+
`infrastructure/server-setup/inventory/${environment}.yml`
|
|
1955
|
+
);
|
|
1961
1956
|
log("\n", import_kleur4.default.bold().underline("Traefik SSL Certificate"), "\n");
|
|
1962
1957
|
const sslCertExists = findExistingValue(
|
|
1963
1958
|
"SSL_CRT",
|
|
@@ -1966,23 +1961,24 @@ var init_setup_environment = __esm({
|
|
|
1966
1961
|
existingValues
|
|
1967
1962
|
);
|
|
1968
1963
|
let ssl_answers = [];
|
|
1969
|
-
const traefikConfOption = (await (0, import_prompts2.default)(
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
]
|
|
1983
|
-
)).traefikConfOption;
|
|
1964
|
+
const traefikConfOption = (await (0, import_prompts2.default)([
|
|
1965
|
+
{
|
|
1966
|
+
name: "traefikConfOption",
|
|
1967
|
+
type: "select",
|
|
1968
|
+
message: "Choose option to configure Traefik SSL Certificate",
|
|
1969
|
+
choices: [
|
|
1970
|
+
{ title: "Let's Encrypt certificate", value: "lets_encrypt" },
|
|
1971
|
+
{ title: "Static SSL certificate", value: "static_ssl" },
|
|
1972
|
+
{ title: "Custom configuration", value: "custom" }
|
|
1973
|
+
],
|
|
1974
|
+
initial: sslCertExists ? 1 : 0
|
|
1975
|
+
}
|
|
1976
|
+
])).traefikConfOption;
|
|
1984
1977
|
if (traefikConfOption === "static_ssl") {
|
|
1985
|
-
ssl_answers = await askQuestionWithEditor(
|
|
1978
|
+
ssl_answers = await askQuestionWithEditor(
|
|
1979
|
+
staticSSLCertQuestions,
|
|
1980
|
+
existingEnvironmentSecrets
|
|
1981
|
+
);
|
|
1986
1982
|
}
|
|
1987
1983
|
log("\n", import_kleur4.default.bold().underline("Storage"), "\n");
|
|
1988
1984
|
let enableEncryption = false;
|
|
@@ -2007,11 +2003,19 @@ var init_setup_environment = __esm({
|
|
|
2007
2003
|
enableEncryption = answers_enable_encryption.enableEncryption;
|
|
2008
2004
|
}
|
|
2009
2005
|
if (enableEncryption && !encryption_key_defined && !environment_exists) {
|
|
2010
|
-
log(
|
|
2006
|
+
log(
|
|
2007
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2008
|
+
import_kleur4.default.bold().yellow(" Disk encryption is enabled")
|
|
2009
|
+
);
|
|
2011
2010
|
await promptAndStoreAnswer(environment, diskQuestions, existingValues);
|
|
2012
2011
|
} else {
|
|
2013
2012
|
if (!enableEncryption && !encryption_key_defined && environment_exists) {
|
|
2014
|
-
log(
|
|
2013
|
+
log(
|
|
2014
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2015
|
+
import_kleur4.default.bold().grey(
|
|
2016
|
+
`Environment ${environment} is already configured, skipping disk encryption question`
|
|
2017
|
+
)
|
|
2018
|
+
);
|
|
2015
2019
|
}
|
|
2016
2020
|
const DISK_SPACE = findExistingValue(
|
|
2017
2021
|
"DISK_SPACE",
|
|
@@ -2020,17 +2024,19 @@ var init_setup_environment = __esm({
|
|
|
2020
2024
|
existingValues
|
|
2021
2025
|
);
|
|
2022
2026
|
if (!DISK_SPACE) {
|
|
2023
|
-
log(
|
|
2027
|
+
log(
|
|
2028
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2029
|
+
import_kleur4.default.bold().grey("All available disk space at /data will be used")
|
|
2030
|
+
);
|
|
2024
2031
|
} else {
|
|
2025
|
-
log(
|
|
2032
|
+
log(
|
|
2033
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2034
|
+
import_kleur4.default.bold().yellow("Variable DISK_SPACE is read-only, allocated space:"),
|
|
2035
|
+
DISK_SPACE?.value
|
|
2036
|
+
);
|
|
2026
2037
|
}
|
|
2027
2038
|
}
|
|
2028
|
-
let backupHost = findExistingValue(
|
|
2029
|
-
"BACKUP_HOST",
|
|
2030
|
-
"VARIABLE",
|
|
2031
|
-
"ENVIRONMENT",
|
|
2032
|
-
existingValues
|
|
2033
|
-
)?.value || "";
|
|
2039
|
+
let backupHost = findExistingValue("BACKUP_HOST", "VARIABLE", "ENVIRONMENT", existingValues)?.value || "";
|
|
2034
2040
|
let backupType = "";
|
|
2035
2041
|
let restoreEnvironmentName = findExistingValue(
|
|
2036
2042
|
"RESTORE_ENVIRONMENT_NAME",
|
|
@@ -2060,7 +2066,7 @@ var init_setup_environment = __esm({
|
|
|
2060
2066
|
backupQuestions,
|
|
2061
2067
|
existingValues
|
|
2062
2068
|
);
|
|
2063
|
-
|
|
2069
|
+
const backupHostPrivateKeyExists = findExistingValue(
|
|
2064
2070
|
"BACKUP_HOST_PRIVATE_KEY",
|
|
2065
2071
|
"SECRET",
|
|
2066
2072
|
"ENVIRONMENT",
|
|
@@ -2072,7 +2078,10 @@ var init_setup_environment = __esm({
|
|
|
2072
2078
|
const { publicKey, privateKey } = generateSSHKeyPair();
|
|
2073
2079
|
backupHostPublicKey = publicKey;
|
|
2074
2080
|
backupHostPrivateKey = privateKey;
|
|
2075
|
-
log(
|
|
2081
|
+
log(
|
|
2082
|
+
import_kleur4.default.bold().green("\u2714"),
|
|
2083
|
+
import_kleur4.default.bold().yellow(`Generated new SSH key pair for backup host: ${backupHost}`)
|
|
2084
|
+
);
|
|
2076
2085
|
}
|
|
2077
2086
|
} else {
|
|
2078
2087
|
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Backup is disabled"));
|
|
@@ -2086,32 +2095,30 @@ var init_setup_environment = __esm({
|
|
|
2086
2095
|
});
|
|
2087
2096
|
}
|
|
2088
2097
|
if (configureRestore) {
|
|
2089
|
-
const env_list_filtered = existingEnvironments.filter(
|
|
2090
|
-
|
|
2091
|
-
{
|
|
2092
|
-
message: "What is the name of your environment to restore?",
|
|
2093
|
-
choices: env_list_filtered.map((env) => ({
|
|
2094
|
-
name: env,
|
|
2095
|
-
value: env
|
|
2096
|
-
})),
|
|
2097
|
-
initial: restoreEnvironmentName
|
|
2098
|
-
}
|
|
2099
|
-
);
|
|
2100
|
-
restoreType = await select3(
|
|
2101
|
-
{
|
|
2102
|
-
message: `Select ${import_kleur4.default.yellow().bold(restoreEnvironmentName)} environment backup mode`,
|
|
2103
|
-
choices: [
|
|
2104
|
-
{
|
|
2105
|
-
name: "Full dump (daily full database backup)",
|
|
2106
|
-
value: "dump"
|
|
2107
|
-
},
|
|
2108
|
-
{
|
|
2109
|
-
name: "Differential (weekly full, daily diff backup)",
|
|
2110
|
-
value: "differential"
|
|
2111
|
-
}
|
|
2112
|
-
]
|
|
2113
|
-
}
|
|
2098
|
+
const env_list_filtered = existingEnvironments.filter(
|
|
2099
|
+
(env) => env !== environment
|
|
2114
2100
|
);
|
|
2101
|
+
restoreEnvironmentName = await selectWithCustom({
|
|
2102
|
+
message: "What is the name of your environment to restore?",
|
|
2103
|
+
choices: env_list_filtered.map((env) => ({
|
|
2104
|
+
name: env,
|
|
2105
|
+
value: env
|
|
2106
|
+
})),
|
|
2107
|
+
initial: restoreEnvironmentName
|
|
2108
|
+
});
|
|
2109
|
+
restoreType = await select3({
|
|
2110
|
+
message: `Select ${import_kleur4.default.yellow().bold(restoreEnvironmentName)} environment backup mode`,
|
|
2111
|
+
choices: [
|
|
2112
|
+
{
|
|
2113
|
+
name: "Full dump (daily full database backup)",
|
|
2114
|
+
value: "dump"
|
|
2115
|
+
},
|
|
2116
|
+
{
|
|
2117
|
+
name: "Differential (weekly full, daily diff backup)",
|
|
2118
|
+
value: "differential"
|
|
2119
|
+
}
|
|
2120
|
+
]
|
|
2121
|
+
});
|
|
2115
2122
|
} else {
|
|
2116
2123
|
log(import_kleur4.default.bold().green("\u2714"), import_kleur4.default.bold().yellow("Restore is disabled"));
|
|
2117
2124
|
}
|
|
@@ -2131,16 +2138,14 @@ var init_setup_environment = __esm({
|
|
|
2131
2138
|
if (sentryDSNExists) {
|
|
2132
2139
|
await promptAndStoreAnswer(environment, sentryQuestions, existingValues);
|
|
2133
2140
|
} else {
|
|
2134
|
-
const { useSentry } = await (0, import_prompts2.default)(
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
]
|
|
2143
|
-
);
|
|
2141
|
+
const { useSentry } = await (0, import_prompts2.default)([
|
|
2142
|
+
{
|
|
2143
|
+
name: "useSentry",
|
|
2144
|
+
type: "confirm",
|
|
2145
|
+
message: "Do you want to use Sentry?",
|
|
2146
|
+
initial: Boolean(process.env.SENTRY_DNS)
|
|
2147
|
+
}
|
|
2148
|
+
]);
|
|
2144
2149
|
if (useSentry) {
|
|
2145
2150
|
await promptAndStoreAnswer(environment, sentryQuestions, existingValues);
|
|
2146
2151
|
}
|
|
@@ -2465,12 +2470,16 @@ var init_setup_environment = __esm({
|
|
|
2465
2470
|
{
|
|
2466
2471
|
type: "VARIABLE",
|
|
2467
2472
|
name: "RESTORE_ENVIRONMENT_NAME",
|
|
2468
|
-
value: answerOrExisting(
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
2472
|
-
|
|
2473
|
-
|
|
2473
|
+
value: answerOrExisting(
|
|
2474
|
+
restoreEnvironmentName,
|
|
2475
|
+
findExistingValue(
|
|
2476
|
+
"RESTORE_ENVIRONMENT_NAME",
|
|
2477
|
+
"VARIABLE",
|
|
2478
|
+
"ENVIRONMENT",
|
|
2479
|
+
existingValues
|
|
2480
|
+
),
|
|
2481
|
+
(val) => val || ""
|
|
2482
|
+
),
|
|
2474
2483
|
didExist: findExistingValue(
|
|
2475
2484
|
"RESTORE_ENVIRONMENT_NAME",
|
|
2476
2485
|
"VARIABLE",
|
|
@@ -2727,32 +2736,26 @@ var init_setup_environment = __esm({
|
|
|
2727
2736
|
)
|
|
2728
2737
|
);
|
|
2729
2738
|
log("\n", import_kleur4.default.bold().underline("Running configuration files updates"));
|
|
2730
|
-
generateInventory(
|
|
2731
|
-
|
|
2732
|
-
|
|
2733
|
-
|
|
2734
|
-
|
|
2735
|
-
|
|
2736
|
-
|
|
2737
|
-
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2743
|
-
|
|
2744
|
-
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2748
|
-
|
|
2749
|
-
|
|
2750
|
-
restore_environment_name: restoreEnvironmentName || "",
|
|
2751
|
-
restore_type: restoreType,
|
|
2752
|
-
traefik_mode: traefikConfOption,
|
|
2753
|
-
backup_type: backupType
|
|
2754
|
-
}
|
|
2755
|
-
);
|
|
2739
|
+
generateInventory(environment, {
|
|
2740
|
+
kube_worker_nodes: kubeWorkerNodes,
|
|
2741
|
+
kube_api_host: infrastructure.kubeAPIHost || "",
|
|
2742
|
+
backup_host: backupHost || "",
|
|
2743
|
+
users
|
|
2744
|
+
});
|
|
2745
|
+
copyChartsValues(environment, {
|
|
2746
|
+
env: environment,
|
|
2747
|
+
environment_type,
|
|
2748
|
+
// FIXME: In general that should be environment_type,
|
|
2749
|
+
// Hardcode like this blocks us from being generic:
|
|
2750
|
+
// https://github.com/opencrvs/opencrvs-core/issues/11171
|
|
2751
|
+
two_fa_enabled: environment !== "production" ? false : true,
|
|
2752
|
+
backup_enabled: configureBackup ? true : false,
|
|
2753
|
+
restore_enabled: restoreEnvironmentName ? true : false,
|
|
2754
|
+
restore_environment_name: restoreEnvironmentName || "",
|
|
2755
|
+
restore_type: restoreType,
|
|
2756
|
+
traefik_mode: traefikConfOption,
|
|
2757
|
+
backup_type: backupType
|
|
2758
|
+
});
|
|
2756
2759
|
let addon_message = kubeWorkerNodes.length > 0 || configureBackup ? `--------------------------------------------------------------------------------------------
|
|
2757
2760
|
|
|
2758
2761
|
\u27A1\uFE0F ${import_kleur4.default.bold().yellow("COPY the SSH public key from the master VM to your clipboard")}
|
|
@@ -2800,7 +2803,9 @@ async function extractInfrastructureNames() {
|
|
|
2800
2803
|
const files = glob.sync("infrastructure/server-setup/inventory/*.yml");
|
|
2801
2804
|
const infraEnvironments = files.map((file) => (0, import_path28.basename)(file, ".yml"));
|
|
2802
2805
|
if (infraEnvironments.length === 0) {
|
|
2803
|
-
console.log(
|
|
2806
|
+
console.log(
|
|
2807
|
+
"\u26A0\uFE0F Warning: No environment directories found in infrastructure/server-setup/inventory/"
|
|
2808
|
+
);
|
|
2804
2809
|
return [];
|
|
2805
2810
|
}
|
|
2806
2811
|
log("\u{1F50D} Found infrastructure configurations:", infraEnvironments.join(", "));
|
|
@@ -2813,7 +2818,9 @@ async function extractEnvironmentNames() {
|
|
|
2813
2818
|
return (0, import_fs9.statSync)(fullPath).isDirectory();
|
|
2814
2819
|
});
|
|
2815
2820
|
if (environments.length === 0) {
|
|
2816
|
-
console.log(
|
|
2821
|
+
console.log(
|
|
2822
|
+
"\u26A0\uFE0F Warning: No environment directories found in environments/"
|
|
2823
|
+
);
|
|
2817
2824
|
return [];
|
|
2818
2825
|
}
|
|
2819
2826
|
log("\u{1F50D} Found OpenCRVS configurations:", environments.join(", "));
|
|
@@ -2837,14 +2844,18 @@ async function updateWorkflows(envList, config) {
|
|
|
2837
2844
|
const fileContents = (0, import_fs9.readFileSync)(workflowPath, "utf8");
|
|
2838
2845
|
const workflowData = yaml2.load(fileContents);
|
|
2839
2846
|
if (!workflowData?.on?.workflow_dispatch?.inputs?.environment?.options) {
|
|
2840
|
-
throw new Error(
|
|
2847
|
+
throw new Error(
|
|
2848
|
+
"Workflow does not have the expected structure: on.workflow_dispatch.inputs.environment.options"
|
|
2849
|
+
);
|
|
2841
2850
|
}
|
|
2842
2851
|
const updatedContent = updateOptionsInYaml(fileContents, envList);
|
|
2843
2852
|
(0, import_fs9.writeFileSync)(workflowPath, updatedContent, "utf8");
|
|
2844
2853
|
log(` \u2713 Successfully updated ${workflowPath}`);
|
|
2845
2854
|
} catch (error4) {
|
|
2846
|
-
console.error(
|
|
2847
|
-
|
|
2855
|
+
console.error(
|
|
2856
|
+
`
|
|
2857
|
+
\u26A0\uFE0F Error updating ${workflowPath} with environments: [${envList.join(", ")}]`
|
|
2858
|
+
);
|
|
2848
2859
|
console.error(`\u2717 Failed to update ${workflowPath}:`, error4);
|
|
2849
2860
|
throw error4;
|
|
2850
2861
|
}
|
|
@@ -2852,30 +2863,41 @@ async function updateWorkflows(envList, config) {
|
|
|
2852
2863
|
}
|
|
2853
2864
|
async function updateWorkflowEnvironments() {
|
|
2854
2865
|
try {
|
|
2866
|
+
let didUpdateWorkflows = false;
|
|
2855
2867
|
const infraEnvironments = await extractInfrastructureNames();
|
|
2856
|
-
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2868
|
+
if (infraEnvironments.length > 0) {
|
|
2869
|
+
console.log("\u{1F504} Updating infrastructure workflows:");
|
|
2870
|
+
await updateWorkflows(infraEnvironments, {
|
|
2871
|
+
workflows: [
|
|
2872
|
+
".github/workflows/provision.yml",
|
|
2873
|
+
".github/workflows/reset-2fa.yml"
|
|
2874
|
+
],
|
|
2875
|
+
path: "on.workflow_dispatch.inputs.environment.options"
|
|
2876
|
+
});
|
|
2877
|
+
didUpdateWorkflows = true;
|
|
2878
|
+
}
|
|
2864
2879
|
const environments = await extractEnvironmentNames();
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2868
|
-
|
|
2869
|
-
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2874
|
-
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2880
|
+
if (environments.length > 0) {
|
|
2881
|
+
const workflows = [
|
|
2882
|
+
".github/workflows/deploy-dependencies.yml",
|
|
2883
|
+
".github/workflows/deploy-opencrvs.yml",
|
|
2884
|
+
".github/workflows/clear-all-data.yml",
|
|
2885
|
+
".github/workflows/seed-data.yml",
|
|
2886
|
+
".github/workflows/reindex.yml",
|
|
2887
|
+
".github/workflows/github-to-k8s-sync-env.yml"
|
|
2888
|
+
];
|
|
2889
|
+
log("\u{1F4CB} Updating OpenCRVS application workflows:");
|
|
2890
|
+
await updateWorkflows(environments, {
|
|
2891
|
+
workflows,
|
|
2892
|
+
path: "on.workflow_dispatch.inputs.environment.options"
|
|
2893
|
+
});
|
|
2894
|
+
didUpdateWorkflows = true;
|
|
2895
|
+
}
|
|
2896
|
+
if (didUpdateWorkflows) {
|
|
2897
|
+
success("\u2705 Workflow updates completed successfully!");
|
|
2898
|
+
} else {
|
|
2899
|
+
log("\u2139\uFE0F No workflows were updated.");
|
|
2900
|
+
}
|
|
2879
2901
|
} catch (error4) {
|
|
2880
2902
|
console.error("\n\u274C Error updating workflows:", error4);
|
|
2881
2903
|
process.exit(1);
|
|
@@ -2891,21 +2913,25 @@ var init_update_workflows = __esm({
|
|
|
2891
2913
|
glob = __toESM(require("glob"));
|
|
2892
2914
|
yaml2 = __toESM(require("js-yaml"));
|
|
2893
2915
|
init_logger();
|
|
2894
|
-
if (require.main === module) {
|
|
2895
|
-
updateWorkflowEnvironments();
|
|
2896
|
-
}
|
|
2897
2916
|
}
|
|
2898
2917
|
});
|
|
2899
2918
|
|
|
2900
2919
|
// src/environment/users.ts
|
|
2901
2920
|
var users_exports = {};
|
|
2921
|
+
__export(users_exports, {
|
|
2922
|
+
manageEnvironmentUsers: () => manageEnvironmentUsers
|
|
2923
|
+
});
|
|
2902
2924
|
async function select4(options) {
|
|
2903
2925
|
const inquirer = await import("@inquirer/prompts");
|
|
2904
2926
|
return inquirer.select(options);
|
|
2905
2927
|
}
|
|
2906
2928
|
async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inventory/") {
|
|
2907
2929
|
if (!fs8.existsSync(dirPath)) {
|
|
2908
|
-
|
|
2930
|
+
warn(`\u26A0\uFE0F No environment configuration directory found at ${dirPath}`);
|
|
2931
|
+
warn(
|
|
2932
|
+
"Hint: If this is a new infrastructure repository, run `opencrvs environment init` first."
|
|
2933
|
+
);
|
|
2934
|
+
return null;
|
|
2909
2935
|
}
|
|
2910
2936
|
const files = fs8.readdirSync(dirPath).filter((file) => {
|
|
2911
2937
|
const filePath = path26.join(dirPath, file);
|
|
@@ -2914,7 +2940,11 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
|
|
|
2914
2940
|
return isFile && (ext === "yml" || ext === "yaml");
|
|
2915
2941
|
}).sort();
|
|
2916
2942
|
if (files.length === 0) {
|
|
2917
|
-
|
|
2943
|
+
warn(`\u26A0\uFE0F No environment configuration files found at ${dirPath}`);
|
|
2944
|
+
warn(
|
|
2945
|
+
"Hint: If this is a new infrastructure repository, run `opencrvs environment init` first."
|
|
2946
|
+
);
|
|
2947
|
+
return null;
|
|
2918
2948
|
}
|
|
2919
2949
|
const choices = files.map((file) => ({
|
|
2920
2950
|
name: path26.basename(file, path26.extname(file)),
|
|
@@ -2926,10 +2956,13 @@ async function selectInventoryFile(dirPath = "./infrastructure/server-setup/inve
|
|
|
2926
2956
|
});
|
|
2927
2957
|
return selectedFile;
|
|
2928
2958
|
}
|
|
2929
|
-
async function
|
|
2959
|
+
async function manageEnvironmentUsers() {
|
|
2930
2960
|
console.log("\n", import_kleur5.default.bold().underline("Manage users"), "\n");
|
|
2931
2961
|
const inventory_file = await selectInventoryFile();
|
|
2932
|
-
|
|
2962
|
+
if (!inventory_file) {
|
|
2963
|
+
return;
|
|
2964
|
+
}
|
|
2965
|
+
await manageUsers(inventory_file);
|
|
2933
2966
|
}
|
|
2934
2967
|
var fs8, path26, import_kleur5;
|
|
2935
2968
|
var init_users = __esm({
|
|
@@ -2939,7 +2972,7 @@ var init_users = __esm({
|
|
|
2939
2972
|
path26 = __toESM(require("path"));
|
|
2940
2973
|
import_kleur5 = __toESM(require("kleur"));
|
|
2941
2974
|
init_manage_users();
|
|
2942
|
-
|
|
2975
|
+
init_logger();
|
|
2943
2976
|
}
|
|
2944
2977
|
});
|
|
2945
2978
|
|
|
@@ -2958,9 +2991,11 @@ var init_swarm_to_k8s = __esm({
|
|
|
2958
2991
|
init_ssh_keygen();
|
|
2959
2992
|
init_github();
|
|
2960
2993
|
(async () => {
|
|
2961
|
-
log(
|
|
2962
|
-
|
|
2963
|
-
|
|
2994
|
+
log(
|
|
2995
|
+
import_kleur6.default.bold(
|
|
2996
|
+
"------------------------------------------------\nOpenCRVS Infrastructure migration script: \nMigrating Swarm configurations to Kubernetes\n------------------------------------------------\n"
|
|
2997
|
+
)
|
|
2998
|
+
);
|
|
2964
2999
|
const environment_type = process.env.ENVIRONMENT_TYPE || "production";
|
|
2965
3000
|
const environment = process.env.ENVIRONMENT || "";
|
|
2966
3001
|
const githubToken = process.env.INFRA_TOKEN || "";
|
|
@@ -2983,7 +3018,9 @@ var init_swarm_to_k8s = __esm({
|
|
|
2983
3018
|
process.exit(1);
|
|
2984
3019
|
}
|
|
2985
3020
|
if (["backup", "jumpbox"].includes(environment)) {
|
|
2986
|
-
info(
|
|
3021
|
+
info(
|
|
3022
|
+
` > ${environment} environment will not be migrated, see migration notes`
|
|
3023
|
+
);
|
|
2987
3024
|
process.exit(0);
|
|
2988
3025
|
}
|
|
2989
3026
|
log(import_kleur6.default.bold().underline("Migration properties:"));
|
|
@@ -2991,7 +3028,10 @@ var init_swarm_to_k8s = __esm({
|
|
|
2991
3028
|
const old_inventory_path = process.env.OLD_INVENTORY_PATH || "";
|
|
2992
3029
|
if (!old_inventory_path) {
|
|
2993
3030
|
error("\n", "Environment variable OLD_INVENTORY_PATH is not set. Exiting.");
|
|
2994
|
-
log(
|
|
3031
|
+
log(
|
|
3032
|
+
"\n",
|
|
3033
|
+
"Old inventory path is required to read existing Swarm configurations."
|
|
3034
|
+
);
|
|
2995
3035
|
process.exit(1);
|
|
2996
3036
|
}
|
|
2997
3037
|
const ansible_inventory = path27.join(old_inventory_path, environment + ".yml");
|
|
@@ -3004,32 +3044,26 @@ var init_swarm_to_k8s = __esm({
|
|
|
3004
3044
|
log(` \u2713 Worker nodes: ${kube_worker_nodes.join(", ")}`);
|
|
3005
3045
|
const backup_host = extractBackupNode(data);
|
|
3006
3046
|
log(` \u2713 Backup host: ${backup_host}`);
|
|
3007
|
-
generateInventory(
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
|
|
3018
|
-
|
|
3019
|
-
|
|
3020
|
-
|
|
3021
|
-
|
|
3022
|
-
|
|
3023
|
-
|
|
3024
|
-
|
|
3025
|
-
|
|
3026
|
-
|
|
3027
|
-
restore_environment_name: environment === "staging" ? "production" : "",
|
|
3028
|
-
restore_type: "dump",
|
|
3029
|
-
traefik_mode: "static_ssl",
|
|
3030
|
-
backup_type: "dump"
|
|
3031
|
-
}
|
|
3032
|
-
);
|
|
3047
|
+
generateInventory(environment, {
|
|
3048
|
+
kube_worker_nodes,
|
|
3049
|
+
users,
|
|
3050
|
+
backup_host: environment === "production" ? backup_host : "",
|
|
3051
|
+
kube_api_host: master
|
|
3052
|
+
});
|
|
3053
|
+
copyChartsValues(environment, {
|
|
3054
|
+
env: environment,
|
|
3055
|
+
environment_type,
|
|
3056
|
+
// FIXME: In general that should be environment_type,
|
|
3057
|
+
// Hardcode like this blocks us from being generic:
|
|
3058
|
+
// https://github.com/opencrvs/opencrvs-core/issues/11171
|
|
3059
|
+
two_fa_enabled: environment !== "production" ? false : true,
|
|
3060
|
+
backup_enabled: environment === "production" ? "true" : "false",
|
|
3061
|
+
restore_enabled: environment === "staging" ? "true" : "false",
|
|
3062
|
+
restore_environment_name: environment === "staging" ? "production" : "",
|
|
3063
|
+
restore_type: "dump",
|
|
3064
|
+
traefik_mode: "static_ssl",
|
|
3065
|
+
backup_type: "dump"
|
|
3066
|
+
});
|
|
3033
3067
|
if (environment === "staging") {
|
|
3034
3068
|
const octokit = new import_core2.Octokit({
|
|
3035
3069
|
auth: githubToken
|
|
@@ -3048,14 +3082,21 @@ var init_swarm_to_k8s = __esm({
|
|
|
3048
3082
|
"production"
|
|
3049
3083
|
);
|
|
3050
3084
|
} catch (err) {
|
|
3051
|
-
error(
|
|
3085
|
+
error(
|
|
3086
|
+
`Failed to create variable RESTORE_ENVIRONMENT_NAME for environment ${environment}:`,
|
|
3087
|
+
err
|
|
3088
|
+
);
|
|
3052
3089
|
}
|
|
3053
3090
|
}
|
|
3054
3091
|
if (environment === "production") {
|
|
3055
3092
|
const octokit = new import_core2.Octokit({
|
|
3056
3093
|
auth: githubToken
|
|
3057
3094
|
});
|
|
3058
|
-
console.log(
|
|
3095
|
+
console.log(
|
|
3096
|
+
"Fetching repository ID for:",
|
|
3097
|
+
githubOrganisation,
|
|
3098
|
+
githubRepository
|
|
3099
|
+
);
|
|
3059
3100
|
const repositoryId = await getRepositoryId(
|
|
3060
3101
|
octokit,
|
|
3061
3102
|
githubOrganisation,
|
|
@@ -3085,10 +3126,15 @@ var init_swarm_to_k8s = __esm({
|
|
|
3085
3126
|
);
|
|
3086
3127
|
log(` \u2713 Created secret ${secretName} for environment ${environment}`);
|
|
3087
3128
|
} catch (err) {
|
|
3088
|
-
error(
|
|
3129
|
+
error(
|
|
3130
|
+
`Failed to create secret ${secretName} for environment ${environment}:`,
|
|
3131
|
+
err
|
|
3132
|
+
);
|
|
3089
3133
|
}
|
|
3090
3134
|
}
|
|
3091
|
-
for (const [variableName, variableValue] of Object.entries(
|
|
3135
|
+
for (const [variableName, variableValue] of Object.entries(
|
|
3136
|
+
variablesToCreate
|
|
3137
|
+
)) {
|
|
3092
3138
|
try {
|
|
3093
3139
|
await createEnvironmentVariable(
|
|
3094
3140
|
octokit,
|
|
@@ -3097,9 +3143,14 @@ var init_swarm_to_k8s = __esm({
|
|
|
3097
3143
|
variableName,
|
|
3098
3144
|
variableValue
|
|
3099
3145
|
);
|
|
3100
|
-
log(
|
|
3146
|
+
log(
|
|
3147
|
+
` \u2713 Created variable ${variableName} for environment ${environment}`
|
|
3148
|
+
);
|
|
3101
3149
|
} catch (err) {
|
|
3102
|
-
error(
|
|
3150
|
+
error(
|
|
3151
|
+
`Failed to create variable ${variableName} for environment ${environment}:`,
|
|
3152
|
+
err
|
|
3153
|
+
);
|
|
3103
3154
|
}
|
|
3104
3155
|
}
|
|
3105
3156
|
}
|
|
@@ -5276,11 +5327,13 @@ var scopeOptionsPlaceEvent = z3.object({
|
|
|
5276
5327
|
event: scopeByEvent,
|
|
5277
5328
|
placeOfEvent: JurisdictionFilter.optional()
|
|
5278
5329
|
}).describe("Options applicable to all record scopes.");
|
|
5279
|
-
var
|
|
5330
|
+
var scopeOptionsDeclaredOrNotified = scopeOptionsPlaceEvent.extend({
|
|
5331
|
+
notifiedIn: JurisdictionFilter.optional(),
|
|
5332
|
+
notifiedBy: UserFilter.optional(),
|
|
5280
5333
|
declaredIn: JurisdictionFilter.optional(),
|
|
5281
5334
|
declaredBy: UserFilter.optional()
|
|
5282
5335
|
}).describe("Options applicable to actions that may take place after DECLARE");
|
|
5283
|
-
var AllRecordScopeOptions =
|
|
5336
|
+
var AllRecordScopeOptions = scopeOptionsDeclaredOrNotified.extend({
|
|
5284
5337
|
registeredIn: JurisdictionFilter.optional(),
|
|
5285
5338
|
registeredBy: UserFilter.optional()
|
|
5286
5339
|
}).describe(
|
|
@@ -5318,6 +5371,8 @@ var ResolvedScopeOptionsPlaceEvent = z3.object({
|
|
|
5318
5371
|
"Resolved options applicable to all record scopes, with location ID instead of jurisdiction filter."
|
|
5319
5372
|
);
|
|
5320
5373
|
var ResolvedScopeOptionsDeclared = ResolvedScopeOptionsPlaceEvent.extend({
|
|
5374
|
+
notifiedIn: UUID.nullish(),
|
|
5375
|
+
notifiedBy: z3.string().optional(),
|
|
5321
5376
|
declaredIn: UUID.nullish(),
|
|
5322
5377
|
declaredBy: z3.string().optional()
|
|
5323
5378
|
}).describe(
|
|
@@ -5363,7 +5418,7 @@ var RecordScopeV2 = z3.discriminatedUnion("type", [
|
|
|
5363
5418
|
}),
|
|
5364
5419
|
z3.object({
|
|
5365
5420
|
type: ScopesWithDeclaredOptions,
|
|
5366
|
-
options:
|
|
5421
|
+
options: scopeOptionsDeclaredOrNotified.optional()
|
|
5367
5422
|
}),
|
|
5368
5423
|
z3.object({
|
|
5369
5424
|
type: ScopesWithFullOptions,
|
|
@@ -5484,8 +5539,9 @@ var decodeScope = (encodedScope) => {
|
|
|
5484
5539
|
var DEFAULT_SCOPE_OPTIONS = {
|
|
5485
5540
|
placeOfEvent: JurisdictionFilter.enum.all,
|
|
5486
5541
|
accessLevel: JurisdictionFilter.enum.all,
|
|
5487
|
-
|
|
5488
|
-
declaredIn: JurisdictionFilter.enum.all
|
|
5542
|
+
notifiedIn: JurisdictionFilter.enum.all,
|
|
5543
|
+
declaredIn: JurisdictionFilter.enum.all,
|
|
5544
|
+
registeredIn: JurisdictionFilter.enum.all
|
|
5489
5545
|
};
|
|
5490
5546
|
|
|
5491
5547
|
// ../commons/src/scopes.deprecated.do-not-use.ts
|
|
@@ -8260,7 +8316,8 @@ async function runEnvironmentUpdateWorkflows() {
|
|
|
8260
8316
|
}
|
|
8261
8317
|
async function runEnvironmentUsers() {
|
|
8262
8318
|
validateRepositoryStructure();
|
|
8263
|
-
await Promise.resolve().then(() => (init_users(), users_exports));
|
|
8319
|
+
const { manageEnvironmentUsers: manageEnvironmentUsers2 } = await Promise.resolve().then(() => (init_users(), users_exports));
|
|
8320
|
+
await manageEnvironmentUsers2();
|
|
8264
8321
|
}
|
|
8265
8322
|
async function runEnvironmentSwarmToK8s() {
|
|
8266
8323
|
validateRepositoryStructure();
|