@opencrvs/toolkit 2.1.0-rc.ffe0b7f → 2.1.0
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 +2 -12
- package/build.sh +22 -4
- package/create-countryconfig/index.js +441 -59
- package/create-countryconfig/node_modules/.bin/degit +21 -0
- package/create-countryconfig/package.json +4 -1
- package/dist/application-config/index.js +362 -284
- package/dist/authentication/index.d.ts +66 -0
- package/dist/authentication/index.d.ts.map +1 -0
- package/dist/authentication/index.js +765 -0
- package/dist/cli.js +3627 -1224
- package/dist/commons/api/router.d.ts +940 -363
- package/dist/commons/application-config/index.d.ts +0 -2
- package/dist/commons/conditionals/conditionals.d.ts +6 -6
- package/dist/commons/conditionals/validate.d.ts +34 -8
- package/dist/commons/events/ActionConfig.d.ts +5 -14
- package/dist/commons/events/ActionDocument.d.ts +35 -15
- package/dist/commons/events/ActionInput.d.ts +4 -4
- package/dist/commons/events/ActionStatus.d.ts +14 -0
- package/dist/commons/events/AdvancedSearchConfig.d.ts +48 -12
- package/dist/commons/events/AuditLog.d.ts +148 -0
- package/dist/commons/events/Draft.d.ts +1 -21
- package/dist/commons/events/EventConfig.d.ts +3 -0
- package/dist/commons/events/EventDocument.d.ts +472 -4
- package/dist/commons/events/EventIndex.d.ts +3 -26
- package/dist/commons/events/EventMetadata.d.ts +1 -11
- package/dist/commons/events/EventStatus.d.ts +19 -0
- package/dist/commons/events/FieldConfig.d.ts +109 -63
- package/dist/commons/events/FieldTypeMapping.d.ts +17 -17
- package/dist/commons/events/FieldValue.d.ts +3 -2
- package/dist/commons/events/Flag.d.ts +42 -0
- package/dist/commons/events/FormConfig.d.ts +6 -0
- package/dist/commons/events/PageConfig.d.ts +4 -0
- package/dist/commons/events/PlainDate.d.ts +8 -0
- package/dist/commons/events/SummaryConfig.d.ts +249 -0
- package/dist/commons/events/WorkqueueConfig.d.ts +17 -14
- package/dist/commons/events/event.d.ts +12 -0
- package/dist/commons/events/index.d.ts +1 -0
- package/dist/commons/events/locationPayloads.d.ts +95 -0
- package/dist/commons/events/locations.d.ts +169 -26
- package/dist/commons/events/mocks.test.utils.d.ts +30 -0
- package/dist/commons/events/scopes.d.ts +21 -1
- package/dist/commons/events/test.utils.d.ts +78 -25
- package/dist/commons/events/utils.d.ts +39 -4
- package/dist/commons/notification/UserNotifications.d.ts +28 -13
- package/dist/commons/notification/dispatch.d.ts +10 -0
- package/dist/commons/notification/index.d.ts +1 -0
- package/dist/conditionals/index.js +349 -65
- package/dist/csv.d.ts +25 -0
- package/dist/csv.d.ts.map +1 -0
- package/dist/csv.js +120 -0
- package/dist/environment/index.d.ts.map +1 -1
- package/dist/environment/index.js +2 -1
- package/dist/environment/logger.d.ts +15 -3
- package/dist/environment/logger.d.ts.map +1 -1
- package/dist/environment/manage-users.js +1 -1
- package/dist/environment/questions.d.ts.map +1 -1
- package/dist/environment/questions.js +20 -14
- package/dist/environment/setup-environment.d.ts +1 -1
- package/dist/environment/setup-environment.d.ts.map +1 -1
- package/dist/environment/setup-environment.js +593 -562
- package/dist/environment/swarm-to-k8s.js +3 -4
- package/dist/environment/templates.d.ts +0 -1
- package/dist/environment/templates.d.ts.map +1 -1
- package/dist/environment/templates.js +3 -8
- package/dist/environment/update-workflows.d.ts.map +1 -1
- package/dist/environment/update-workflows.js +4 -0
- package/dist/environment/utils.d.ts +0 -12
- package/dist/environment/utils.d.ts.map +1 -1
- package/dist/environment/utils.js +1 -28
- package/dist/events/index.js +7689 -7063
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +3 -0
- package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -0
- package/dist/migrations/v2.1/add-recovery-link-notifications.js +511 -0
- package/dist/migrations/v2.1/add-translations.d.ts +9 -0
- package/dist/migrations/v2.1/add-translations.d.ts.map +1 -0
- package/dist/migrations/v2.1/add-translations.js +149 -0
- package/dist/migrations/{v2.0/rename-api-paths.d.ts → v2.1/enable-telemetry.d.ts} +1 -1
- package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -0
- package/dist/migrations/v2.1/enable-telemetry.js +455 -0
- package/dist/migrations/v2.1/index.d.ts.map +1 -1
- package/dist/migrations/v2.1/index.js +1952 -0
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +14 -0
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +1 -0
- package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +348 -0
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +2 -0
- package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +1 -0
- package/dist/migrations/v2.1/remove-metabase-package-installs.js +161 -0
- package/dist/migrations/{v2.0/migrate-scopes.d.ts → v2.1/remove-sentry.d.ts} +1 -1
- package/dist/migrations/v2.1/remove-sentry.d.ts.map +1 -0
- package/dist/migrations/v2.1/remove-sentry.js +354 -0
- package/dist/migrations/{v2.0/create-events-index.d.ts → v2.1/rename-trigger-paths.d.ts} +1 -1
- package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +1 -0
- package/dist/migrations/{v2.0/rename-api-paths.js → v2.1/rename-trigger-paths.js} +69 -40
- package/dist/migrations/v2.1/template-files.d.ts +8 -0
- package/dist/migrations/v2.1/template-files.d.ts.map +1 -0
- package/dist/migrations/v2.1/template-files.js +49 -0
- package/dist/migrations/v2.1/upgrade-tilt.d.ts +8 -0
- package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +1 -0
- package/dist/migrations/v2.1/upgrade-tilt.js +139 -0
- package/dist/notification/index.js +1887 -1438
- package/dist/scopes/index.d.ts +614 -36
- package/dist/scopes/index.js +351 -65
- package/dist/telemetry/index.d.ts +45 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +43 -0
- package/dist/templates/charts-values/dependencies/values.yaml +8 -0
- package/dist/templates/charts-values/opencrvs-services/values.yaml +10 -3
- package/dist/templates/charts-values/opentelemetry/values.yaml +102 -0
- package/dist/templates/charts-values/traefik/values.yaml +23 -9
- package/dist/templates/countryconfig-template/.tiltignore +1 -0
- package/dist/templates/countryconfig-template/Dockerfile.assets +7 -0
- package/dist/templates/countryconfig-template/Tiltfile +112 -0
- package/dist/templates/countryconfig-template/assets/README.md +1 -0
- package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +61 -0
- package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +455 -0
- package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +168 -0
- package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +67 -0
- package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +168 -0
- package/dist/templates/countryconfig-template/assets/metabase/README.md +34 -0
- package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +36 -0
- package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +46 -0
- package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +27737 -0
- package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +21 -0
- package/dist/templates/countryconfig-template/assets/metabase/package.json +13 -0
- package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +108 -0
- package/dist/templates/countryconfig-template/assets/metabase/run.sh +120 -0
- package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +40 -0
- package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +135 -0
- package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +108 -0
- package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +50 -0
- package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +35 -0
- package/dist/templates/countryconfig-template/tilt/common.tilt +145 -0
- package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +15 -0
- package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +56 -0
- package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +21 -0
- package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +38 -0
- package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +17 -0
- package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +16 -0
- package/dist/templates/countryconfig-template/tilt/lib.tilt +95 -0
- package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +136 -0
- package/dist/templates/inventory/inventory.template.yml +1 -3
- package/dist/translations/template.d.ts +11 -0
- package/dist/translations/template.d.ts.map +1 -0
- package/dist/translations/template.js +100 -0
- package/dist/verify/endpoints.d.ts +2 -0
- package/dist/verify/endpoints.d.ts.map +1 -0
- package/dist/verify/endpoints.js +510 -0
- package/opencrvs-toolkit-2.1.0.tgz +0 -0
- package/package.json +13 -7
- package/tsconfig.build.json +11 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.json +3 -0
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +0 -3
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +0 -1
- package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +0 -429
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +0 -3
- package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +0 -1
- package/dist/migrations/v2.0/add-resend-invite-notification.js +0 -373
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts +0 -22
- package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +0 -1
- package/dist/migrations/v2.0/checkout-upstream-files.js +0 -146
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +0 -2
- package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +0 -1
- package/dist/migrations/v2.0/convert-config-files-to-ts.js +0 -838
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +0 -3
- package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +0 -1
- package/dist/migrations/v2.0/convert-paragraph-to-heading.js +0 -158
- package/dist/migrations/v2.0/create-events-index.d.ts.map +0 -1
- package/dist/migrations/v2.0/create-events-index.js +0 -325
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +0 -11
- package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +0 -1
- package/dist/migrations/v2.0/delete-infrastructure-directory.js +0 -123
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +0 -3
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +0 -1
- package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +0 -110
- package/dist/migrations/v2.0/index.d.ts +0 -13
- package/dist/migrations/v2.0/index.d.ts.map +0 -1
- package/dist/migrations/v2.0/index.js +0 -103
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +0 -3
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +0 -1
- package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +0 -432
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +0 -13
- package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +0 -1
- package/dist/migrations/v2.0/merge-infrastructure-directory.js +0 -222
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts +0 -3
- package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +0 -1
- package/dist/migrations/v2.0/migrate-application-config-url.js +0 -343
- package/dist/migrations/v2.0/migrate-scopes.d.ts.map +0 -1
- package/dist/migrations/v2.0/migrate-scopes.js +0 -305
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +0 -3
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +0 -1
- package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +0 -267
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +0 -3
- package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +0 -1
- package/dist/migrations/v2.0/migrate-workqueue-configs.js +0 -317
- package/dist/migrations/v2.0/remove-delete-actions.d.ts +0 -3
- package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-delete-actions.js +0 -156
- package/dist/migrations/v2.0/remove-demo-scope.d.ts +0 -3
- package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-demo-scope.js +0 -74
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +0 -3
- package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-deprecated-imports.js +0 -96
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +0 -3
- package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-fhir-url-helpers.js +0 -163
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +0 -3
- package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-hearth-migrations.js +0 -87
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +0 -3
- package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-old-statistics-service.js +0 -356
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +0 -3
- package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-pending-certification-flag.js +0 -109
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +0 -3
- package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-review-from-register-action.js +0 -163
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +0 -3
- package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +0 -1
- package/dist/migrations/v2.0/remove-unused-environment-variables.js +0 -186
- package/dist/migrations/v2.0/rename-api-paths.d.ts.map +0 -1
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts +0 -3
- package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +0 -1
- package/dist/migrations/v2.0/rename-location-parent-id.js +0 -180
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +0 -3
- package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +0 -1
- package/dist/migrations/v2.0/simplify-analytics-precalculations.js +0 -195
- package/dist/migrations/v2.0/update-package-json.d.ts +0 -3
- package/dist/migrations/v2.0/update-package-json.d.ts.map +0 -1
- package/dist/migrations/v2.0/update-package-json.js +0 -105
- package/dist/templates/inventory/production.example.yml +0 -77
- package/dist/templates/inventory/qa.example.yml +0 -48
- package/opencrvs-toolkit-2.1.0-rc.ffe0b7f.tgz +0 -0
- package/tsconfig.tsbuildinfo +0 -1
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type Outcome = 'copied' | 'kept' | 'merged' | 'conflict' | 'dropped' | 'exists' | 'exists-differs' | 'not-moved';
|
|
2
|
+
export interface AssetsMigrationResult {
|
|
3
|
+
/** Paths relative to `assets/`, by what happened to them. */
|
|
4
|
+
outcomes: Record<string, Outcome>;
|
|
5
|
+
/** Paths relative to `infrastructure/` that can be removed. */
|
|
6
|
+
migrated: string[];
|
|
7
|
+
}
|
|
8
|
+
export type ReadBase = (file: string) => Uint8Array | undefined;
|
|
9
|
+
export declare function migrateInfrastructureToAssets(cwd: string, templateDir: string, readBase: ReadBase): AssetsMigrationResult;
|
|
10
|
+
/** Removes migrated files and any directories they leave empty. */
|
|
11
|
+
export declare function removeMigrated(cwd: string, migrated: string[]): void;
|
|
12
|
+
declare function main(dockerSwarm?: boolean): Promise<void>;
|
|
13
|
+
export { main };
|
|
14
|
+
//# sourceMappingURL=migrate-infrastructure-to-assets.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"migrate-infrastructure-to-assets.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.1/migrate-infrastructure-to-assets.ts"],"names":[],"mappings":"AAiHA,KAAK,OAAO,GACR,QAAQ,GACR,MAAM,GACN,QAAQ,GACR,UAAU,GACV,SAAS,GACT,QAAQ,GACR,gBAAgB,GAChB,WAAW,CAAA;AAEf,MAAM,WAAW,qBAAqB;IACpC,6DAA6D;IAC7D,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACjC,+DAA+D;IAC/D,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AAED,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,UAAU,GAAG,SAAS,CAAA;AAyF/D,wBAAgB,6BAA6B,CAC3C,GAAG,EAAE,MAAM,EACX,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,QAAQ,GACjB,qBAAqB,CAmGvB;AAED,mEAAmE;AACnE,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAwB7D;AAeD,iBAAe,IAAI,CAAC,WAAW,UAAQ,iBAiFtC;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
6
|
+
*
|
|
7
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
8
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
9
|
+
*
|
|
10
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
11
|
+
*/
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.migrateInfrastructureToAssets = migrateInfrastructureToAssets;
|
|
26
|
+
exports.removeMigrated = removeMigrated;
|
|
27
|
+
exports.main = main;
|
|
28
|
+
/**
|
|
29
|
+
* Codemod: move `infrastructure/` into the v2.1 `assets/` directory, merging
|
|
30
|
+
* the country's changes with the template's.
|
|
31
|
+
*
|
|
32
|
+
* The assets image (Dockerfile.assets) is now built from `assets/` with a
|
|
33
|
+
* single `COPY assets /assets`, and the charts copy `/assets/metabase`,
|
|
34
|
+
* `/assets/postgres` and `/assets/elasticsearch` out of it.
|
|
35
|
+
*
|
|
36
|
+
* What it does, for every file under `infrastructure/{metabase,postgres,
|
|
37
|
+
* deployment,elasticsearch}/` and the template's `assets/`, going to the same
|
|
38
|
+
* path under `assets/`:
|
|
39
|
+
* - template only → copied from the template
|
|
40
|
+
* - unchanged since v2.0 → the template's version (or dropped,
|
|
41
|
+
* when the template no longer has it)
|
|
42
|
+
* - changed by the country only → the country's version
|
|
43
|
+
* - changed on both sides → 3-way merged (`git merge-file`), with
|
|
44
|
+
* conflict markers left for review
|
|
45
|
+
* - country only → moved across as is
|
|
46
|
+
* The v2.0 version of each file, used as the merge base, is read from
|
|
47
|
+
* opencrvs-farajaland's release/v2.0.0 on GitHub.
|
|
48
|
+
*
|
|
49
|
+
* `assets/elasticsearch/reindex.sh`, which the reindex job runs, is built from
|
|
50
|
+
* `infrastructure/deployment/reindex.sh` so a customised reindex script
|
|
51
|
+
* carries over.
|
|
52
|
+
*
|
|
53
|
+
* `postgres/on-deploy.sh` is never moved: the data-migration-analytics job
|
|
54
|
+
* runs every `*.sh` in `/assets/postgres`, and the chart ships its own
|
|
55
|
+
* on-deploy script. The v2.0 Dockerfile.assets deleted it from the image for
|
|
56
|
+
* the same reason.
|
|
57
|
+
*
|
|
58
|
+
* Then `Dockerfile.assets` is replaced with the template's, the migrated files
|
|
59
|
+
* are removed from `infrastructure/` (kept with `--docker-swarm`), and the
|
|
60
|
+
* result is staged. Files with conflicts are left unstaged. Anything else in
|
|
61
|
+
* `infrastructure/`, such as Docker Swarm configuration, is left in place.
|
|
62
|
+
*
|
|
63
|
+
* Caveats:
|
|
64
|
+
* - Existing files under `assets/` are never overwritten, so running it
|
|
65
|
+
* again, or after migrating by hand, leaves them alone. The
|
|
66
|
+
* `infrastructure/` original is then only removed when identical.
|
|
67
|
+
* - Binary files changed by the country keep the country's version.
|
|
68
|
+
* - Requires network access to raw.githubusercontent.com. Without it
|
|
69
|
+
* nothing is changed and the step is reported as skipped.
|
|
70
|
+
*/
|
|
71
|
+
const child_process_1 = require("child_process");
|
|
72
|
+
const fs_1 = require("fs");
|
|
73
|
+
const os_1 = require("os");
|
|
74
|
+
const path_1 = __importDefault(require("path"));
|
|
75
|
+
const template_files_1 = require("./template-files");
|
|
76
|
+
const INFRASTRUCTURE_DIR = 'infrastructure';
|
|
77
|
+
const ASSETS_DIR = 'assets';
|
|
78
|
+
const BASE_URL = 'https://raw.githubusercontent.com/opencrvs/opencrvs-farajaland/release/v2.0.0/infrastructure';
|
|
79
|
+
/** Assets built from a differently named v2.0 file, when not present themselves. */
|
|
80
|
+
const SOURCE_OF = {
|
|
81
|
+
'elasticsearch/reindex.sh': 'deployment/reindex.sh'
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* What the assets image needs. The rest of `infrastructure/` (Docker Swarm
|
|
85
|
+
* compose files, server setup and so on) is left where it is.
|
|
86
|
+
*/
|
|
87
|
+
const MIGRATED_DIRS = ['metabase', 'postgres', 'deployment', 'elasticsearch'];
|
|
88
|
+
/** Never moved into `assets/`. */
|
|
89
|
+
const NOT_MOVED = ['postgres/on-deploy.sh'];
|
|
90
|
+
const isMigrated = (file) => MIGRATED_DIRS.some((dir) => file.startsWith(`${dir}/`));
|
|
91
|
+
/** Runs git silently in the working directory, returning true on success. */
|
|
92
|
+
function tryGit(args) {
|
|
93
|
+
try {
|
|
94
|
+
(0, child_process_1.execFileSync)('git', args, { stdio: 'ignore' });
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
catch (_a) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function assertIsGitRepo() {
|
|
102
|
+
if (!tryGit(['rev-parse', '--is-inside-work-tree'])) {
|
|
103
|
+
throw new Error(`${process.cwd()} is not a git repository. Initialise git (or run the upgrade inside a git checkout) before re-running.`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/*
|
|
107
|
+
* Plain Uint8Array rather than Buffer: the repository's Node typings reject a
|
|
108
|
+
* Buffer where fs expects an ArrayBufferView.
|
|
109
|
+
*/
|
|
110
|
+
const toBytes = (buffer) => new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
111
|
+
const sameBytes = (a, b) => a.length === b.length && a.every((byte, index) => byte === b[index]);
|
|
112
|
+
const isBinary = (contents) => contents.includes(0);
|
|
113
|
+
function readIfExists(file) {
|
|
114
|
+
return (0, fs_1.existsSync)(file) ? toBytes((0, fs_1.readFileSync)(file)) : undefined;
|
|
115
|
+
}
|
|
116
|
+
/** 3-way merge of text contents. `conflicts` is 0 for a clean merge. */
|
|
117
|
+
function mergeFile(file, ours, base, theirs) {
|
|
118
|
+
const dir = (0, fs_1.mkdtempSync)(path_1.default.join((0, os_1.tmpdir)(), 'opencrvs-merge-assets-'));
|
|
119
|
+
try {
|
|
120
|
+
const [oursPath, basePath, theirsPath] = ['ours', 'base', 'theirs'].map((name) => path_1.default.join(dir, name));
|
|
121
|
+
(0, fs_1.writeFileSync)(oursPath, ours);
|
|
122
|
+
(0, fs_1.writeFileSync)(basePath, base);
|
|
123
|
+
(0, fs_1.writeFileSync)(theirsPath, theirs);
|
|
124
|
+
// Without -p git writes the result into `oursPath`, so large files
|
|
125
|
+
// (e.g. the Metabase init dump) don't overflow the stdout buffer
|
|
126
|
+
const args = [
|
|
127
|
+
'merge-file',
|
|
128
|
+
'-q',
|
|
129
|
+
'-L',
|
|
130
|
+
`infrastructure/${file}`,
|
|
131
|
+
'-L',
|
|
132
|
+
'v2.0',
|
|
133
|
+
'-L',
|
|
134
|
+
`v2.1 template`,
|
|
135
|
+
oursPath,
|
|
136
|
+
basePath,
|
|
137
|
+
theirsPath
|
|
138
|
+
];
|
|
139
|
+
let conflicts = 0;
|
|
140
|
+
try {
|
|
141
|
+
(0, child_process_1.execFileSync)('git', args, { stdio: 'ignore' });
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
const { status } = error;
|
|
145
|
+
// git merge-file exits with the number of conflicts, or 255 on error
|
|
146
|
+
if (!status || status >= 255)
|
|
147
|
+
throw error;
|
|
148
|
+
conflicts = status;
|
|
149
|
+
}
|
|
150
|
+
return { contents: toBytes((0, fs_1.readFileSync)(oursPath)), conflicts };
|
|
151
|
+
}
|
|
152
|
+
finally {
|
|
153
|
+
(0, fs_1.rmSync)(dir, { recursive: true, force: true });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/** Every v2.0 file the migration needs as a merge base, fetched up front. */
|
|
157
|
+
function fetchBases(files) {
|
|
158
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
159
|
+
const bases = new Map();
|
|
160
|
+
for (const file of files) {
|
|
161
|
+
const url = `${BASE_URL}/${file}`;
|
|
162
|
+
const response = yield fetch(url);
|
|
163
|
+
if (response.ok) {
|
|
164
|
+
bases.set(file, new Uint8Array(yield response.arrayBuffer()));
|
|
165
|
+
}
|
|
166
|
+
else if (response.status !== 404) {
|
|
167
|
+
// 404 means the file is the country's own; anything else would merge
|
|
168
|
+
// against a missing base, so give up before touching anything
|
|
169
|
+
throw new Error(`GitHub answered ${response.status} ${response.statusText} for ${url}`);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
return bases;
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
function migrateInfrastructureToAssets(cwd, templateDir, readBase) {
|
|
176
|
+
const infrastructure = path_1.default.join(cwd, INFRASTRUCTURE_DIR);
|
|
177
|
+
const templateAssets = path_1.default.join(templateDir, ASSETS_DIR);
|
|
178
|
+
const relativeTo = (dir) => (file) => file.slice(dir.length + 1);
|
|
179
|
+
const localFiles = (0, template_files_1.listFiles)(cwd, INFRASTRUCTURE_DIR)
|
|
180
|
+
.map(relativeTo(INFRASTRUCTURE_DIR))
|
|
181
|
+
.filter(isMigrated);
|
|
182
|
+
const templateFiles = (0, template_files_1.listFiles)(templateDir, ASSETS_DIR).map(relativeTo(ASSETS_DIR));
|
|
183
|
+
const outcomes = {};
|
|
184
|
+
const migrated = new Set();
|
|
185
|
+
for (const file of [...new Set([...templateFiles, ...localFiles])].sort()) {
|
|
186
|
+
const sourceFile = !localFiles.includes(file) && localFiles.includes(SOURCE_OF[file])
|
|
187
|
+
? SOURCE_OF[file]
|
|
188
|
+
: file;
|
|
189
|
+
const ours = readIfExists(path_1.default.join(infrastructure, sourceFile));
|
|
190
|
+
const theirsPath = path_1.default.join(templateAssets, file);
|
|
191
|
+
const theirs = readIfExists(theirsPath);
|
|
192
|
+
const base = ours && readBase(sourceFile);
|
|
193
|
+
const target = path_1.default.join(cwd, ASSETS_DIR, file);
|
|
194
|
+
if (NOT_MOVED.includes(file)) {
|
|
195
|
+
if (ours && base && sameBytes(ours, base)) {
|
|
196
|
+
migrated.add(file);
|
|
197
|
+
outcomes[file] = 'dropped';
|
|
198
|
+
}
|
|
199
|
+
else if (ours) {
|
|
200
|
+
outcomes[file] = 'not-moved';
|
|
201
|
+
}
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
const ownsSource = ours !== undefined && sourceFile === file;
|
|
205
|
+
if ((0, fs_1.existsSync)(target)) {
|
|
206
|
+
// Migrated before (a re-run, or by hand): only remove the original
|
|
207
|
+
// when nothing in it would be lost
|
|
208
|
+
if (ownsSource) {
|
|
209
|
+
const same = sameBytes(toBytes((0, fs_1.readFileSync)(target)), ours);
|
|
210
|
+
if (same) {
|
|
211
|
+
migrated.add(file);
|
|
212
|
+
}
|
|
213
|
+
outcomes[file] = same ? 'exists' : 'exists-differs';
|
|
214
|
+
}
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
if (ownsSource) {
|
|
218
|
+
migrated.add(file);
|
|
219
|
+
}
|
|
220
|
+
let contents;
|
|
221
|
+
let outcome;
|
|
222
|
+
if (!ours) {
|
|
223
|
+
contents = theirs;
|
|
224
|
+
outcome = 'copied';
|
|
225
|
+
}
|
|
226
|
+
else if (!theirs) {
|
|
227
|
+
const unchanged = base && sameBytes(ours, base);
|
|
228
|
+
contents = unchanged ? undefined : ours;
|
|
229
|
+
outcome = unchanged ? 'dropped' : 'kept';
|
|
230
|
+
}
|
|
231
|
+
else if (sameBytes(ours, theirs) || (base && sameBytes(ours, base))) {
|
|
232
|
+
contents = theirs;
|
|
233
|
+
outcome = 'copied';
|
|
234
|
+
}
|
|
235
|
+
else if (!base || sameBytes(base, theirs) || isBinary(ours)) {
|
|
236
|
+
contents = ours;
|
|
237
|
+
outcome = 'kept';
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
const result = mergeFile(sourceFile, ours, base, theirs);
|
|
241
|
+
contents = result.contents;
|
|
242
|
+
outcome = result.conflicts > 0 ? 'conflict' : 'merged';
|
|
243
|
+
}
|
|
244
|
+
outcomes[file] = outcome;
|
|
245
|
+
if (contents === undefined) {
|
|
246
|
+
continue;
|
|
247
|
+
}
|
|
248
|
+
(0, fs_1.mkdirSync)(path_1.default.dirname(target), { recursive: true });
|
|
249
|
+
(0, fs_1.writeFileSync)(target, contents);
|
|
250
|
+
const modeSource = ours && outcome === 'kept'
|
|
251
|
+
? path_1.default.join(infrastructure, sourceFile)
|
|
252
|
+
: theirsPath;
|
|
253
|
+
if ((0, fs_1.existsSync)(modeSource)) {
|
|
254
|
+
(0, fs_1.chmodSync)(target, (0, fs_1.statSync)(modeSource).mode & 0o777);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
return { outcomes, migrated: [...migrated].sort() };
|
|
258
|
+
}
|
|
259
|
+
/** Removes migrated files and any directories they leave empty. */
|
|
260
|
+
function removeMigrated(cwd, migrated) {
|
|
261
|
+
const infrastructure = path_1.default.join(cwd, INFRASTRUCTURE_DIR);
|
|
262
|
+
for (const file of migrated) {
|
|
263
|
+
(0, fs_1.rmSync)(path_1.default.join(infrastructure, file), { force: true });
|
|
264
|
+
}
|
|
265
|
+
const pruneEmpty = (dir) => {
|
|
266
|
+
if (!(0, fs_1.existsSync)(dir)) {
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
const empty = (0, fs_1.readdirSync)(dir, { withFileTypes: true })
|
|
270
|
+
.map((entry) => entry.isDirectory() ? pruneEmpty(path_1.default.join(dir, entry.name)) : false)
|
|
271
|
+
.every(Boolean);
|
|
272
|
+
if (empty) {
|
|
273
|
+
(0, fs_1.rmdirSync)(dir);
|
|
274
|
+
}
|
|
275
|
+
return empty;
|
|
276
|
+
};
|
|
277
|
+
pruneEmpty(infrastructure);
|
|
278
|
+
}
|
|
279
|
+
const DESCRIPTIONS = {
|
|
280
|
+
copied: 'from the template',
|
|
281
|
+
kept: "country's version",
|
|
282
|
+
merged: 'merged',
|
|
283
|
+
conflict: 'CONFLICT, resolve the markers by hand',
|
|
284
|
+
dropped: 'dropped, no longer used',
|
|
285
|
+
exists: 'already migrated',
|
|
286
|
+
'exists-differs': 'already exists with different contents; infrastructure/ copy kept for review',
|
|
287
|
+
'not-moved': 'changed locally but not moved: the chart runs its own on-deploy script, port your changes there'
|
|
288
|
+
};
|
|
289
|
+
function main() {
|
|
290
|
+
return __awaiter(this, arguments, void 0, function* (dockerSwarm = false) {
|
|
291
|
+
const cwd = process.cwd();
|
|
292
|
+
console.log('Moving infrastructure/ into assets/...\n');
|
|
293
|
+
const templateDir = (0, template_files_1.findTemplateDir)();
|
|
294
|
+
if ((0, fs_1.existsSync)(path_1.default.join(cwd, INFRASTRUCTURE_DIR))) {
|
|
295
|
+
assertIsGitRepo();
|
|
296
|
+
const needed = (0, template_files_1.listFiles)(cwd, INFRASTRUCTURE_DIR)
|
|
297
|
+
.map((file) => file.slice(INFRASTRUCTURE_DIR.length + 1))
|
|
298
|
+
.filter(isMigrated);
|
|
299
|
+
let bases;
|
|
300
|
+
try {
|
|
301
|
+
bases = yield fetchBases(needed);
|
|
302
|
+
}
|
|
303
|
+
catch (error) {
|
|
304
|
+
console.warn(` ⚠️ Could not read the v2.0 files to merge against (${error.message}); infrastructure/ was not migrated. Re-run 'opencrvs upgrade' with network access.`);
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
const { outcomes, migrated } = migrateInfrastructureToAssets(cwd, templateDir, (file) => bases.get(file));
|
|
308
|
+
for (const [file, outcome] of Object.entries(outcomes)) {
|
|
309
|
+
const needsReview = ['conflict', 'not-moved', 'exists-differs'].includes(outcome);
|
|
310
|
+
const shown = outcome === 'not-moved' ? INFRASTRUCTURE_DIR : ASSETS_DIR;
|
|
311
|
+
const line = ` ${needsReview ? '⚠️ ' : '✓'} ${shown}/${file}: ${DESCRIPTIONS[outcome]}`;
|
|
312
|
+
if (needsReview) {
|
|
313
|
+
console.warn(line);
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
console.log(line);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (dockerSwarm) {
|
|
320
|
+
console.log('\n infrastructure/ kept in place (--docker-swarm); assets/ now holds a copy.');
|
|
321
|
+
}
|
|
322
|
+
else {
|
|
323
|
+
removeMigrated(cwd, migrated);
|
|
324
|
+
}
|
|
325
|
+
tryGit(['add', '-A', '--', ASSETS_DIR, INFRASTRUCTURE_DIR]);
|
|
326
|
+
const conflicts = Object.keys(outcomes).filter((file) => outcomes[file] === 'conflict');
|
|
327
|
+
for (const file of conflicts) {
|
|
328
|
+
tryGit(['restore', '--staged', '--', `${ASSETS_DIR}/${file}`]);
|
|
329
|
+
}
|
|
330
|
+
if (conflicts.length > 0) {
|
|
331
|
+
console.warn(`\n ⚠️ ${conflicts.length} file(s) need their conflicts resolved: ${conflicts.map((file) => `assets/${file}`).join(', ')}`);
|
|
332
|
+
}
|
|
333
|
+
if ((0, fs_1.existsSync)(path_1.default.join(cwd, INFRASTRUCTURE_DIR)) && !dockerSwarm) {
|
|
334
|
+
console.warn(' ⚠️ infrastructure/ still has files the Kubernetes deployment does not use. Review and delete them if they are no longer needed.');
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
console.log(' infrastructure/ not found, nothing to move.');
|
|
339
|
+
}
|
|
340
|
+
const dockerfile = toBytes((0, fs_1.readFileSync)(path_1.default.join(templateDir, 'Dockerfile.assets')));
|
|
341
|
+
const current = readIfExists(path_1.default.join(cwd, 'Dockerfile.assets'));
|
|
342
|
+
if (!current || !sameBytes(current, dockerfile)) {
|
|
343
|
+
(0, fs_1.writeFileSync)(path_1.default.join(cwd, 'Dockerfile.assets'), dockerfile);
|
|
344
|
+
tryGit(['add', '--', 'Dockerfile.assets']);
|
|
345
|
+
console.log(' ✓ Dockerfile.assets replaced with the template version');
|
|
346
|
+
}
|
|
347
|
+
});
|
|
348
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-metabase-package-installs.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.1/remove-metabase-package-installs.ts"],"names":[],"mappings":"AA+KA,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAY1C"}
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
4
|
+
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
5
|
+
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
6
|
+
*
|
|
7
|
+
* OpenCRVS is also distributed under the terms of the Civil Registration
|
|
8
|
+
* & Healthcare Disclaimer located at http://opencrvs.org/license.
|
|
9
|
+
*
|
|
10
|
+
* Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
|
|
11
|
+
*/
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.main = main;
|
|
23
|
+
/**
|
|
24
|
+
* Codemod: Stop the Metabase startup scripts installing packages over the
|
|
25
|
+
* internet.
|
|
26
|
+
*
|
|
27
|
+
* `run.sh` used to `apk add gettext util-linux` on every start. Since chart
|
|
28
|
+
* v2.1.0 the dashboards Deployment renders NetworkPolicies and the chart
|
|
29
|
+
* default `network_policy.egress_mode: private` allows RFC1918 only, so the
|
|
30
|
+
* fetch to dl-cdn.alpinelinux.org is dropped, apk reports "Permission denied"
|
|
31
|
+
* and Metabase never starts. Both tools have in-image equivalents:
|
|
32
|
+
*
|
|
33
|
+
* - uuidgen (util-linux) -> /proc/sys/kernel/random/uuid, keeping uuidgen
|
|
34
|
+
* as the fallback for local macOS runs
|
|
35
|
+
* - envsubst (gettext) -> bash's own heredoc expansion
|
|
36
|
+
*
|
|
37
|
+
* This is the country-config side of core's #13778, which fixed the same
|
|
38
|
+
* scripts in `countryconfig-template` and `testland` — i.e. only for newly
|
|
39
|
+
* scaffolded country configs.
|
|
40
|
+
*
|
|
41
|
+
* What it does:
|
|
42
|
+
* Rewrites `run.sh` and `update-database.sh` under `infrastructure/metabase/`
|
|
43
|
+
* (and `assets/metabase/`, in case the directory has already been renamed)
|
|
44
|
+
* to match the fixed upstream versions.
|
|
45
|
+
*
|
|
46
|
+
* Caveats:
|
|
47
|
+
* - Anchored on the exact upstream v2.0 wording. A script that was edited
|
|
48
|
+
* locally is left alone with a warning rather than half-patched, and the
|
|
49
|
+
* dev applies core's #13778 by hand.
|
|
50
|
+
* - No-op when the files are absent (Swarm configs that dropped
|
|
51
|
+
* `infrastructure/`, or configs scaffolded from the fixed template).
|
|
52
|
+
*/
|
|
53
|
+
const fs_1 = require("fs");
|
|
54
|
+
const path_1 = require("path");
|
|
55
|
+
const METABASE_DIRS = ['infrastructure/metabase', 'assets/metabase'];
|
|
56
|
+
// ─── run.sh ──────────────────────────────────────────────────────────────────
|
|
57
|
+
const APK_BLOCK = [
|
|
58
|
+
'apk update',
|
|
59
|
+
'apk upgrade',
|
|
60
|
+
'apk add --no-cache gettext',
|
|
61
|
+
'apk add --no-cache util-linux',
|
|
62
|
+
'',
|
|
63
|
+
''
|
|
64
|
+
].join('\n');
|
|
65
|
+
const SALT_LINE = 'export OPENCRVS_METABASE_ADMIN_PASSWORD_SALT=$(uuidgen)\n';
|
|
66
|
+
const FIXED_SALT_LINE = 'export OPENCRVS_METABASE_ADMIN_PASSWORD_SALT=' +
|
|
67
|
+
'$(cat /proc/sys/kernel/random/uuid 2>/dev/null || uuidgen)\n\n';
|
|
68
|
+
const FIXED_SALT_MARKER = '/proc/sys/kernel/random/uuid';
|
|
69
|
+
// ─── update-database.sh ──────────────────────────────────────────────────────
|
|
70
|
+
const ENVSUBST_GUARD = [
|
|
71
|
+
'if ! which envsubst >/dev/null; then',
|
|
72
|
+
' echo "envsubst could not be found. Please install envsubst before continuing."',
|
|
73
|
+
' echo "MacOS: brew install gettext && brew link --force gettext"',
|
|
74
|
+
' exit 1',
|
|
75
|
+
'fi',
|
|
76
|
+
''
|
|
77
|
+
].join('\n');
|
|
78
|
+
const ENVSUBST_CALL = 'envsubst < $environment_configuration_sql_file > ' +
|
|
79
|
+
'$environment_configuration_sql_file.tmp\n';
|
|
80
|
+
const FIXED_EXPANSION = [
|
|
81
|
+
'',
|
|
82
|
+
"# Expand $VAR / ${VAR} using bash's own heredoc expansion instead of envsubst,",
|
|
83
|
+
'# because envsubst is not installed in the Metabase image',
|
|
84
|
+
'eval "cat <<OPENCRVS_ENV_EOF',
|
|
85
|
+
'$(cat "$environment_configuration_sql_file")',
|
|
86
|
+
'OPENCRVS_ENV_EOF" > "$environment_configuration_sql_file.tmp"',
|
|
87
|
+
''
|
|
88
|
+
].join('\n');
|
|
89
|
+
const FIXED_EXPANSION_MARKER = 'OPENCRVS_ENV_EOF';
|
|
90
|
+
/**
|
|
91
|
+
* Rewrites `run.sh` to read the salt from the kernel instead of installing
|
|
92
|
+
* util-linux for uuidgen.
|
|
93
|
+
*
|
|
94
|
+
* Returns the source unchanged when it is already fixed, and `undefined` when
|
|
95
|
+
* it does not match the upstream v2.0 wording — the caller warns and skips.
|
|
96
|
+
*/
|
|
97
|
+
function patchRunScript(source) {
|
|
98
|
+
if (source.includes(FIXED_SALT_MARKER) && !source.includes(APK_BLOCK)) {
|
|
99
|
+
return source;
|
|
100
|
+
}
|
|
101
|
+
if (!source.includes(APK_BLOCK) || !source.includes(SALT_LINE)) {
|
|
102
|
+
return undefined;
|
|
103
|
+
}
|
|
104
|
+
return source.replace(APK_BLOCK, '').replace(SALT_LINE, FIXED_SALT_LINE);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Rewrites `update-database.sh` to expand the environment configuration with
|
|
108
|
+
* bash instead of installing gettext for envsubst.
|
|
109
|
+
*
|
|
110
|
+
* Returns the source unchanged when it is already fixed, and `undefined` when
|
|
111
|
+
* it does not match the upstream v2.0 wording — the caller warns and skips.
|
|
112
|
+
*/
|
|
113
|
+
function patchUpdateDatabaseScript(source) {
|
|
114
|
+
if (source.includes(FIXED_EXPANSION_MARKER) &&
|
|
115
|
+
!source.includes(ENVSUBST_CALL)) {
|
|
116
|
+
return source;
|
|
117
|
+
}
|
|
118
|
+
if (!source.includes(ENVSUBST_GUARD) || !source.includes(ENVSUBST_CALL)) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
return source
|
|
122
|
+
.replace(ENVSUBST_GUARD, '')
|
|
123
|
+
.replace(ENVSUBST_CALL, FIXED_EXPANSION);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Applies `patch` to `relativePath`, writing it back only when the contents
|
|
127
|
+
* actually change. Warns and leaves the file alone when it has been edited
|
|
128
|
+
* locally, because a half-patched script still fails to start — silently.
|
|
129
|
+
*/
|
|
130
|
+
function patchFile(relativePath, patch, removed) {
|
|
131
|
+
const filePath = (0, path_1.join)(process.cwd(), relativePath);
|
|
132
|
+
if (!(0, fs_1.existsSync)(filePath)) {
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
const source = (0, fs_1.readFileSync)(filePath, 'utf8');
|
|
136
|
+
const patched = patch(source);
|
|
137
|
+
if (patched === undefined) {
|
|
138
|
+
// eslint-disable-next-line no-console
|
|
139
|
+
console.warn(` ⚠️ ${relativePath} does not match the upstream v2.0 version, so it ` +
|
|
140
|
+
`was left alone. Apply ` +
|
|
141
|
+
`https://github.com/opencrvs/opencrvs-core/pull/13778 by hand, or ` +
|
|
142
|
+
`Metabase will fail to start behind the chart's private egress policy.`);
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
if (patched === source) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
(0, fs_1.writeFileSync)(filePath, patched);
|
|
149
|
+
// eslint-disable-next-line no-console
|
|
150
|
+
console.log(` ✓ ${relativePath}: ${removed}`);
|
|
151
|
+
}
|
|
152
|
+
function main() {
|
|
153
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
154
|
+
// eslint-disable-next-line no-console
|
|
155
|
+
console.log('\nRemoving the Metabase package installs...\n');
|
|
156
|
+
for (const dir of METABASE_DIRS) {
|
|
157
|
+
patchFile((0, path_1.join)(dir, 'run.sh'), patchRunScript, 'apk add gettext util-linux');
|
|
158
|
+
patchFile((0, path_1.join)(dir, 'update-database.sh'), patchUpdateDatabaseScript, 'envsubst');
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remove-sentry.d.ts","sourceRoot":"","sources":["../../../src/migrations/v2.1/remove-sentry.ts"],"names":[],"mappings":"AAwaA,iBAAe,IAAI,kBAiClB;AAED,OAAO,EAAE,IAAI,EAAE,CAAA"}
|