@opencrvs/toolkit 2.2.0-rc.90ed9cd → 2.2.0-rc.9dfc125

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (141) hide show
  1. package/build.sh +2 -12
  2. package/dist/application-config/index.js +5 -6
  3. package/dist/authentication/index.d.ts +1 -0
  4. package/dist/authentication/index.js +16 -5
  5. package/dist/cli.js +875 -193
  6. package/dist/commons/api/router.d.ts +246 -246
  7. package/dist/commons/application-config/index.d.ts +2 -2
  8. package/dist/commons/conditionals/index.d.ts +1 -0
  9. package/dist/commons/conditionals/validate.d.ts +5 -0
  10. package/dist/commons/events/ActionConfig.d.ts +16 -23
  11. package/dist/commons/events/ActionDocument.d.ts +1 -0
  12. package/dist/commons/events/ActionInput.d.ts +4 -4
  13. package/dist/commons/events/CompositeFieldValue.d.ts +5 -1
  14. package/dist/commons/events/CountryConfigQueryInput.d.ts +0 -18
  15. package/dist/commons/events/EventConfig.d.ts +12 -2
  16. package/dist/commons/events/EventIndex.d.ts +2 -6
  17. package/dist/commons/events/EventMetadata.d.ts +0 -1
  18. package/dist/commons/events/FieldConfig.d.ts +1 -1
  19. package/dist/commons/events/FieldTypeMapping.d.ts +6 -6
  20. package/dist/commons/events/Flag.d.ts +1 -7
  21. package/dist/commons/events/PlainDate.d.ts +1 -0
  22. package/dist/commons/events/WorkqueueConfig.d.ts +12 -27
  23. package/dist/commons/events/eventConfigValidation.d.ts +9 -0
  24. package/dist/commons/events/index.d.ts +2 -0
  25. package/dist/commons/events/notificationFormFallback.d.ts +10 -0
  26. package/dist/commons/events/state/flags.d.ts +1 -1
  27. package/dist/commons/events/test.utils.d.ts +3 -0
  28. package/dist/commons/events/utils.d.ts +85 -56
  29. package/dist/conditionals/index.js +2 -3
  30. package/dist/environment/custom-types.d.ts +1 -0
  31. package/dist/environment/custom-types.d.ts.map +1 -1
  32. package/dist/environment/derived-variables.d.ts +12 -4
  33. package/dist/environment/derived-variables.d.ts.map +1 -1
  34. package/dist/environment/derived-variables.js +13 -4
  35. package/dist/environment/questions.d.ts +14 -2
  36. package/dist/environment/questions.d.ts.map +1 -1
  37. package/dist/environment/questions.js +40 -19
  38. package/dist/environment/registry.d.ts +15 -0
  39. package/dist/environment/registry.d.ts.map +1 -0
  40. package/dist/environment/registry.js +112 -0
  41. package/dist/environment/setup-environment.d.ts.map +1 -1
  42. package/dist/environment/setup-environment.js +111 -24
  43. package/dist/environment/templates.d.ts.map +1 -1
  44. package/dist/events/index.js +242 -65
  45. package/dist/migrations/index.d.ts +9 -0
  46. package/dist/migrations/index.d.ts.map +1 -0
  47. package/dist/migrations/index.js +847 -0
  48. package/dist/migrations/move-declaration-to-declare-action.d.ts +38 -0
  49. package/dist/migrations/move-declaration-to-declare-action.d.ts.map +1 -0
  50. package/dist/migrations/move-declaration-to-declare-action.js +377 -0
  51. package/dist/migrations/{add-translations.d.ts → persistent/add-translations.d.ts} +1 -1
  52. package/dist/migrations/persistent/add-translations.d.ts.map +1 -0
  53. package/dist/migrations/{add-translations.js → persistent/add-translations.js} +2 -2
  54. package/dist/migrations/persistent/check-upgrade-path.d.ts +36 -0
  55. package/dist/migrations/persistent/check-upgrade-path.d.ts.map +1 -0
  56. package/dist/migrations/persistent/check-upgrade-path.js +105 -0
  57. package/dist/migrations/persistent/update-toolkit-dependency.d.ts +7 -0
  58. package/dist/migrations/persistent/update-toolkit-dependency.d.ts.map +1 -0
  59. package/dist/migrations/persistent/update-toolkit-dependency.js +77 -0
  60. package/dist/migrations/{v2.2/read-declaration-through-helper.d.ts → read-declaration-through-helper.d.ts} +1 -1
  61. package/dist/migrations/read-declaration-through-helper.d.ts.map +1 -0
  62. package/dist/migrations/{v2.2/read-declaration-through-helper.js → read-declaration-through-helper.js} +1 -1
  63. package/dist/migrations/replace-incomplete-flag.d.ts +26 -0
  64. package/dist/migrations/replace-incomplete-flag.d.ts.map +1 -0
  65. package/dist/migrations/replace-incomplete-flag.js +126 -0
  66. package/dist/notification/index.js +143 -19
  67. package/dist/scopes/index.d.ts +54 -84
  68. package/dist/scopes/index.js +12 -5
  69. package/dist/templates/charts-values/dependencies/values.yaml +1 -1
  70. package/dist/templates/charts-values/opencrvs-services/values.yaml +4 -6
  71. package/dist/templates/charts-values/traefik/values.yaml +2 -0
  72. package/opencrvs-toolkit-2.2.0-rc.9dfc125.tgz +0 -0
  73. package/package.json +2 -2
  74. package/tsconfig.build.tsbuildinfo +1 -1
  75. package/dist/migrations/add-translations.d.ts.map +0 -1
  76. package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts +0 -3
  77. package/dist/migrations/v2.1/add-explicit-correction-flags.d.ts.map +0 -1
  78. package/dist/migrations/v2.1/add-explicit-correction-flags.js +0 -234
  79. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +0 -3
  80. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +0 -1
  81. package/dist/migrations/v2.1/add-recovery-link-notifications.js +0 -511
  82. package/dist/migrations/v2.1/enable-telemetry.d.ts +0 -3
  83. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +0 -1
  84. package/dist/migrations/v2.1/enable-telemetry.js +0 -455
  85. package/dist/migrations/v2.1/index.d.ts +0 -6
  86. package/dist/migrations/v2.1/index.d.ts.map +0 -1
  87. package/dist/migrations/v2.1/index.js +0 -50
  88. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +0 -17
  89. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +0 -1
  90. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +0 -348
  91. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +0 -2
  92. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +0 -1
  93. package/dist/migrations/v2.1/remove-metabase-package-installs.js +0 -161
  94. package/dist/migrations/v2.1/remove-sentry.d.ts +0 -3
  95. package/dist/migrations/v2.1/remove-sentry.d.ts.map +0 -1
  96. package/dist/migrations/v2.1/remove-sentry.js +0 -354
  97. package/dist/migrations/v2.1/rename-trigger-paths.d.ts +0 -3
  98. package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +0 -1
  99. package/dist/migrations/v2.1/rename-trigger-paths.js +0 -216
  100. package/dist/migrations/v2.1/template-files.d.ts +0 -8
  101. package/dist/migrations/v2.1/template-files.d.ts.map +0 -1
  102. package/dist/migrations/v2.1/template-files.js +0 -49
  103. package/dist/migrations/v2.1/upgrade-tilt.d.ts +0 -11
  104. package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +0 -1
  105. package/dist/migrations/v2.1/upgrade-tilt.js +0 -139
  106. package/dist/migrations/v2.2/index.d.ts +0 -6
  107. package/dist/migrations/v2.2/index.d.ts.map +0 -1
  108. package/dist/migrations/v2.2/index.js +0 -456
  109. package/dist/migrations/v2.2/read-declaration-through-helper.d.ts.map +0 -1
  110. package/dist/templates/countryconfig-template/.tiltignore +0 -1
  111. package/dist/templates/countryconfig-template/Dockerfile.assets +0 -7
  112. package/dist/templates/countryconfig-template/Tiltfile +0 -112
  113. package/dist/templates/countryconfig-template/assets/README.md +0 -1
  114. package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +0 -61
  115. package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +0 -455
  116. package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +0 -168
  117. package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +0 -67
  118. package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +0 -168
  119. package/dist/templates/countryconfig-template/assets/metabase/README.md +0 -34
  120. package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +0 -36
  121. package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +0 -46
  122. package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +0 -27737
  123. package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +0 -21
  124. package/dist/templates/countryconfig-template/assets/metabase/package.json +0 -13
  125. package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +0 -108
  126. package/dist/templates/countryconfig-template/assets/metabase/run.sh +0 -120
  127. package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +0 -40
  128. package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +0 -135
  129. package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +0 -108
  130. package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +0 -50
  131. package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +0 -35
  132. package/dist/templates/countryconfig-template/tilt/common.tilt +0 -145
  133. package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +0 -15
  134. package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +0 -56
  135. package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +0 -21
  136. package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +0 -38
  137. package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +0 -17
  138. package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +0 -16
  139. package/dist/templates/countryconfig-template/tilt/lib.tilt +0 -95
  140. package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +0 -136
  141. package/opencrvs-toolkit-2.2.0-rc.90ed9cd.tgz +0 -0
@@ -1,112 +0,0 @@
1
- ##########################################################################
2
- # Tiltfile: OpenCRVS Country config developer
3
- # For more information about variables, please check:
4
- # https://github.com/opencrvs/infrastructure/blob/develop/Tiltfile
5
-
6
- # OpenCRVS core images tag:
7
- core_images_tag = os.getenv("OPENCRVS_CORE_IMAGE_TAG", "v2.1.0")
8
-
9
- core_ref = os.getenv("OPENCRVS_CORE_REF", "release/2.1.0")
10
-
11
- # Build countryconfig image in local registry (use any name and tag you want)
12
- countryconfig_image_name="opencrvs/ocrvs-countryconfig"
13
- countryconfig_image_tag="local"
14
-
15
-
16
- # Internal variable for helm charts checkout
17
- core_charts_dir = ".opencrvs-core-charts"
18
-
19
- core_repo_url = 'https://github.com/opencrvs/opencrvs-core.git'
20
-
21
- # Tilt re-evaluates this file on every reload, so clone only once per ref.
22
- # Delete the directory (or change OPENCRVS_CORE_REF) to fetch the charts again.
23
- core_charts_marker = "{}/.tilt-ref-{}".format(core_charts_dir, core_ref.replace("/", "_"))
24
- if not os.path.exists(core_charts_marker):
25
- print("Cloning OpenCRVS Helm charts ({}) from {}...".format(core_ref, core_repo_url))
26
- # set -e and git -C: a failed clone must never leave git running in the country config repository
27
- local("""
28
- set -e
29
- rm -rf {core_charts_dir}
30
- git clone \
31
- --depth 1 \
32
- --filter=blob:none \
33
- --sparse \
34
- --branch {core_ref} \
35
- {core_repo_url} \
36
- {core_charts_dir}
37
- git -C {core_charts_dir} sparse-checkout set charts
38
- touch {core_charts_marker}
39
- """.format(
40
- core_ref=core_ref,
41
- core_charts_dir=core_charts_dir,
42
- core_repo_url=core_repo_url,
43
- core_charts_marker=core_charts_marker
44
- ))
45
- else:
46
- print("Using OpenCRVS Helm charts ({}) from {}".format(core_ref, core_charts_dir))
47
-
48
- if not os.path.exists('{core_charts_dir}/charts/dependencies'.format(core_charts_dir=core_charts_dir)) or not os.path.exists('{core_charts_dir}/charts/opencrvs-services'.format(core_charts_dir=core_charts_dir)):
49
- fail('Something went wrong while cloning infrastructure repository!')
50
-
51
- load('./tilt/opencrvs.tilt', 'setup_opencrvs')
52
-
53
- # FIXME: in future releases remove this check and require pnpm only, as yarn is deprecated
54
- # Package manager follows the lockfile, so country configs still on yarn keep working
55
- if os.path.exists('pnpm-lock.yaml'):
56
- package_manager = 'pnpm'
57
- startup_command = 'start:tilt'
58
- lockfile = 'pnpm-lock.yaml'
59
- elif os.path.exists('yarn.lock'):
60
- package_manager = 'yarn'
61
- startup_command = 'start:prod'
62
- lockfile = 'yarn.lock'
63
- else:
64
- fail('No pnpm-lock.yaml or yarn.lock found, install dependencies before running Tilt')
65
-
66
- dependency_files = ['./' + lockfile]
67
- if os.path.exists('.pnpmfile.cjs'):
68
- dependency_files.append('./.pnpmfile.cjs')
69
-
70
- # Build countryconfig image
71
- docker_build(
72
- "{0}:{1}".format(countryconfig_image_name, countryconfig_image_tag),
73
- ".",
74
- dockerfile="Dockerfile",
75
- network="host",
76
- entrypoint=[package_manager, startup_command],
77
- only=[
78
- './src',
79
- './package.json',
80
- './tsconfig.json',
81
- './Dockerfile'
82
- ] + dependency_files,
83
- live_update=[
84
- # Fallback to full rebuild if dependencies change
85
- fall_back_on(['package.json', lockfile, 'Dockerfile']),
86
- # Sync source code changes
87
- sync('./src', '/usr/src/app/src'),
88
- ]
89
- )
90
-
91
-
92
- # Build image with postgres and metabase assets
93
- docker_build("{0}:{1}-assets".format(countryconfig_image_name, countryconfig_image_tag), ".",
94
- dockerfile="Dockerfile.assets",
95
- network="host",
96
- only=[
97
- 'assets/metabase',
98
- 'assets/postgres',
99
- 'assets/deployment',
100
- 'assets/elasticsearch',
101
- './Dockerfile.assets'
102
- ]
103
- )
104
-
105
- setup_opencrvs(
106
- opencrvs_chart_repo=core_charts_dir,
107
- core_images_tag=core_images_tag,
108
- countryconfig_image_name=countryconfig_image_name,
109
- countryconfig_image_tag=countryconfig_image_tag,
110
- )
111
-
112
- print("✅ Tiltfile configuration loaded successfully.")
@@ -1 +0,0 @@
1
- Put custom assets and scripts to extend Country Configuration
@@ -1,61 +0,0 @@
1
- #!/bin/bash
2
- # This Source Code Form is subject to the terms of the Mozilla Public
3
- # License, v. 2.0. If a copy of the MPL was not distributed with this
4
- # file, You can obtain one at https://mozilla.org/MPL/2.0/.
5
- #
6
- # OpenCRVS is also distributed under the terms of the Civil Registration
7
- # & Healthcare Disclaimer located at http://opencrvs.org/license.
8
- #
9
- # Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
10
-
11
- set -e
12
-
13
- echo "🧹 Clearing all development data..."
14
-
15
- # Default PostgreSQL connection parameters for development
16
- POSTGRES_HOST=${POSTGRES_HOST:-localhost}
17
- POSTGRES_PORT=${POSTGRES_PORT:-5432}
18
- POSTGRES_USER=${POSTGRES_USER:-postgres}
19
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD:-postgres}
20
- ANALYTICS_POSTGRES_USER=${ANALYTICS_POSTGRES_USER:-events_analytics}
21
-
22
- print_usage_and_exit() {
23
- echo 'Usage: ./clear-all-data-dev.sh'
24
- echo ""
25
- echo "Environment variables (with defaults for development):"
26
- echo "POSTGRES_HOST=${POSTGRES_HOST}"
27
- echo "POSTGRES_PORT=${POSTGRES_PORT}"
28
- echo "POSTGRES_USER=${POSTGRES_USER}"
29
- echo "POSTGRES_PASSWORD=${POSTGRES_PASSWORD}"
30
- echo "ANALYTICS_POSTGRES_USER=${ANALYTICS_POSTGRES_USER}"
31
- echo ""
32
- echo "This script clears all development databases including:"
33
- echo "- PostgreSQL analytics schema and data"
34
- echo "- Metabase configuration database (H2)"
35
- echo "- Any additional custom databases (can be extended by country configurations)"
36
- exit 1
37
- }
38
-
39
- # Check if PostgreSQL is accessible
40
- if ! PGPASSWORD="$POSTGRES_PASSWORD" psql -h "$POSTGRES_HOST" -p "$POSTGRES_PORT" -U "$POSTGRES_USER" -d postgres -c '\q' 2>/dev/null; then
41
- echo "❌ Cannot connect to PostgreSQL at ${POSTGRES_HOST}:${POSTGRES_PORT}"
42
- echo " Make sure PostgreSQL is running and credentials are correct."
43
- print_usage_and_exit
44
- fi
45
-
46
- # Clear PostgreSQL analytics schema
47
- echo "🗑️ Clearing PostgreSQL analytics schema..."
48
- PGPASSWORD="$POSTGRES_PASSWORD" psql -h "$POSTGRES_HOST" -p "$POSTGRES_PORT" -U "$POSTGRES_USER" -d events -v ON_ERROR_STOP=1 <<EOSQL || echo "⚠️ Analytics schema may not exist yet"
49
- -- Drop analytics schema and recreate it
50
- DROP SCHEMA IF EXISTS analytics CASCADE;
51
- CREATE SCHEMA analytics;
52
-
53
- -- Drop and recreate analytics user
54
- DROP ROLE IF EXISTS "$ANALYTICS_POSTGRES_USER";
55
- EOSQL
56
-
57
- echo "✅ PostgreSQL analytics data cleared"
58
-
59
- echo ""
60
- echo "🎉 All development data cleared successfully!"
61
- echo ""
@@ -1,455 +0,0 @@
1
- # This Source Code Form is subject to the terms of the Mozilla Public
2
- # License, v. 2.0. If a copy of the MPL was not distributed with this
3
- # file, You can obtain one at https://mozilla.org/MPL/2.0/.
4
- #
5
- # OpenCRVS is also distributed under the terms of the Civil Registration
6
- # & Healthcare Disclaimer located at http://opencrvs.org/license.
7
- #
8
- # Copyright (C) The OpenCRVS Authors located at https://github.com/opencrvs/opencrvs-core/blob/master/AUTHORS.
9
- set -e
10
-
11
- BASEDIR=$(dirname $(realpath $0))
12
- INFRASTRUCTURE_DIRECTORY=$(dirname $BASEDIR)
13
- PROJECT_ROOT=$(pwd)
14
-
15
- while [ "$PROJECT_ROOT" != "/" ]; do
16
- if [ -f "$PROJECT_ROOT/package.json" ]; then
17
- break
18
- fi
19
- PROJECT_ROOT=$(dirname "$PROJECT_ROOT")
20
- done
21
-
22
- # Reading Names parameters
23
- for i in "$@"; do
24
- case $i in
25
- --host=*)
26
- HOST="${i#*=}"
27
- shift
28
- ;;
29
- --ssh_host=*)
30
- SSH_HOST="${i#*=}"
31
- shift
32
- ;;
33
- --ssh_user=*)
34
- SSH_USER="${i#*=}"
35
- shift
36
- ;;
37
- --ssh_port=*)
38
- SSH_PORT="${i#*=}"
39
- shift
40
- ;;
41
- --environment=*)
42
- ENV="${i#*=}"
43
- shift
44
- ;;
45
- --version=*)
46
- export VERSION="${i#*=}"
47
- shift
48
- ;;
49
- --country_config_version=*)
50
- # Exported so that it can be used in the docker-compose files
51
- export COUNTRY_CONFIG_VERSION="${i#*=}"
52
- shift
53
- ;;
54
- --replicas=*)
55
- # Exported so that it can be used in the docker-compose files
56
- export REPLICAS="${i#*=}"
57
- shift
58
- ;;
59
- *) ;;
60
-
61
- esac
62
- done
63
-
64
-
65
- # Default values
66
- SSH_ARGS=${SSH_ARGS:-}
67
- LOG_LOCATION=${LOG_LOCATION:-/var/log}
68
-
69
- COMPOSE_FILES_DOWNLOADED_FROM_CORE="/tmp/docker-compose.deps.yml /tmp/docker-compose.yml"
70
- ENVIRONMENT_COMPOSE="$INFRASTRUCTURE_DIRECTORY/docker-compose.$ENV-deploy.yml"
71
- COMPOSE_FILES_USED="$COMPOSE_FILES_DOWNLOADED_FROM_CORE $INFRASTRUCTURE_DIRECTORY/docker-compose.deploy.yml $ENVIRONMENT_COMPOSE"
72
-
73
- echo $COMPOSE_FILES_USED
74
-
75
- # Read environment variable file for the environment
76
- # .env.qa
77
- # .env.development
78
- # .env.production
79
- if [ -f $PROJECT_ROOT/.env.$ENV ]
80
- then
81
- while IFS='' read -r line || [[ -n "$line" ]]; do
82
- eval "export $line"
83
- done < $PROJECT_ROOT/.env.$ENV
84
- fi
85
-
86
- trap trapint SIGINT SIGTERM
87
- function trapint {
88
- exit 0
89
- }
90
-
91
- print_usage_and_exit () {
92
- echo 'Usage: ./deploy.sh --host --environment --ssh_host --ssh_port --ssh_user --version --country_config_version --replicas'
93
- echo " --environment can be 'production', 'development', 'qa' or similar"
94
- echo ' --host is the server to deploy to'
95
- echo " --version can be any OpenCRVS Core docker image tag or 'latest'"
96
- echo " --country_config_version can be any OpenCRVS Country Configuration docker image tag or 'latest'"
97
- echo " --replicas number of supported mongo databases in your replica set. Can be 1, 3 or 5"
98
- exit 1
99
- }
100
-
101
- validate_options() {
102
- if [ -z "$ENV" ] ; then
103
- echo 'Error: Argument --environment is required.'
104
- print_usage_and_exit
105
- fi
106
-
107
- if [ -z "$HOST" ] ; then
108
- echo 'Error: Argument --host is required'
109
- print_usage_and_exit
110
- fi
111
-
112
- if [ -z "$VERSION" ] ; then
113
- echo 'Error: Argument --version is required.'
114
- print_usage_and_exit
115
- fi
116
-
117
- if [ -z "$SSH_HOST" ] ; then
118
- echo 'Error: Argument --ssh_host is required.'
119
- print_usage_and_exit
120
- fi
121
-
122
- if [ -z "$SSH_PORT" ] ; then
123
- echo 'Error: Argument --ssh_port is required.'
124
- print_usage_and_exit
125
- fi
126
-
127
- if [ -z "$SSH_USER" ] ; then
128
- echo 'Error: Argument --ssh_user is required.'
129
- print_usage_and_exit
130
- fi
131
-
132
- if [ -z "$COUNTRY_CONFIG_VERSION" ] ; then
133
- echo 'Error: Argument --country_config_version is required.'
134
- print_usage_and_exit
135
- fi
136
-
137
- if [ -z "$REPLICAS" ] ; then
138
- echo 'Error: Argument --replicas is required in position 8.'
139
- print_usage_and_exit
140
- fi
141
- }
142
-
143
- validate_environment_variables() {
144
- # These ones are directly required by this script
145
- # and thus should be set in the environment variables even
146
- # if not required by compose files
147
- if [ -z "$ALERT_EMAIL" ] ; then
148
- echo 'Error: Missing environment variable ALERT_EMAIL.'
149
- print_usage_and_exit
150
- fi
151
-
152
- if [ -z "$MINIO_ROOT_USER" ] ; then
153
- echo 'Error: Missing environment variable MINIO_ROOT_USER.'
154
- print_usage_and_exit
155
- fi
156
-
157
- if [ -z "$MINIO_ROOT_PASSWORD" ] ; then
158
- echo 'Error: Missing environment variable MINIO_ROOT_PASSWORD.'
159
- print_usage_and_exit
160
- fi
161
-
162
- npx tsx $BASEDIR/validate-required-variables-in-compose-files.ts $COMPOSE_FILES_USED
163
- }
164
-
165
- configured_rsync() {
166
- rsync -e "ssh -p $SSH_PORT $SSH_ARGS" "$@"
167
- }
168
-
169
- get_environment_variables() {
170
- local env_vars=""
171
- # Define an array of variables to exclude
172
- local exclude_vars=("PATH" "SSH_ARGS" "HOME" "LANG" "USER" "SHELL" "PWD")
173
-
174
- while IFS='=' read -r name value; do
175
- # Check if the variable is in the exclude list
176
- if printf '%s\n' "${exclude_vars[@]}" | grep -qx "$name"; then
177
- # Skip the variable if it's in the exclude list
178
- continue
179
- fi
180
-
181
- # Exclude variables that start with specified patterns
182
- if [[ ! $name =~ ^(npm_|RUNNER_TOOL_CACHE|GITHUB_) ]]; then
183
- # Safely escape and quote the value
184
- printf -v escaped_value "%q" "$value"
185
- env_vars+="${name}=\"${escaped_value}\" "
186
- fi
187
- done < <(printenv)
188
-
189
- echo "$env_vars"
190
- }
191
-
192
- configured_ssh() {
193
- ssh $SSH_USER@$SSH_HOST -p $SSH_PORT $SSH_ARGS "export $(get_environment_variables); $@"
194
- }
195
-
196
- # Rotate MongoDB credentials
197
- # https://unix.stackexchange.com/a/230676
198
- generate_password() {
199
- local password=`openssl rand -base64 25 | tr -cd '[:alnum:]._-' ; echo ''`
200
- echo $password
201
- }
202
-
203
- to_remote_paths() {
204
- paths=$@
205
- echo "$paths" | sed "s|/tmp/|/opt/opencrvs/infrastructure/|g" | sed "s|$INFRASTRUCTURE_DIRECTORY/docker-compose|/opt/opencrvs/infrastructure/docker-compose|g"
206
- }
207
-
208
- rotate_secrets() {
209
- files_to_rotate=$(to_remote_paths $COMPOSE_FILES_USED)
210
- configured_ssh '/opt/opencrvs/infrastructure/rotate-secrets.sh '$files_to_rotate' | tee -a '$LOG_LOCATION'/rotate-secrets.log'
211
- }
212
-
213
- # Take generated passwords and save them to a file
214
- # File is taken from github runner and transferred to the server
215
- # Later docker secret is created from this file and used by docker-compose
216
- save_redis_acl(){
217
- echo "Saving redis acl"
218
- printf """
219
- user default on >$DEFAULT_REDIS_PASSWORD ~* +@all
220
- user $GATEWAY_REDIS_USERNAME on >$GATEWAY_REDIS_PASSWORD ~* +@all
221
- user $AUTH_REDIS_USERNAME on >$AUTH_REDIS_PASSWORD ~* +@all
222
- """ > $INFRASTRUCTURE_DIRECTORY/redis-acl.conf
223
- echo "Redis acl saved to $INFRASTRUCTURE_DIRECTORY/redis-acl.conf"
224
- }
225
-
226
- # Takes in a space separated string of docker-compose.yml files
227
- # returns a new line separated list of images defined in those files
228
- # This function gets a clean list of images and substitutes environment variables
229
- # So that we have a clean list to download
230
- get_docker_tags_from_compose_files() {
231
- COMPOSE_FILES=$1
232
-
233
- SPACE_SEPARATED_COMPOSE_FILE_LIST=$(printf " %s" "${COMPOSE_FILES[@]}")
234
- SPACE_SEPARATED_COMPOSE_FILE_LIST=${SPACE_SEPARATED_COMPOSE_FILE_LIST:1}
235
-
236
- IMAGE_TAG_LIST=$(cat $SPACE_SEPARATED_COMPOSE_FILE_LIST \
237
- `# Select rows with the image tag` \
238
- | grep image: \
239
- `# Ignore the baseimage file as its not used directly` \
240
- | grep -v ocrvs-base \
241
- `# Only keep the image version` \
242
- | sed "s/image://")
243
-
244
- # SOME_VARIABLE:-some-default VERSION:-latest
245
- IMAGE_TAGS_WITH_VARIABLE_SUBSTITUTIONS_WITH_DEFAULTS=$(echo $IMAGE_TAG_LIST \
246
- `# Matches variables with default values like VERSION:-latest` \
247
- | grep -o "[A-Za-z_0-9]\+:-[A-Za-z_0-9.-]\+" \
248
- | sort --unique)
249
-
250
- # This reads Docker image tag definitions with a variable substitution
251
- # and defines the environment variables with the defaults unles the variable is already present.
252
- # Done as a preprosessing step for envsubs
253
- for VARIABLE_NAME_WITH_DEFAULT_VALUE in ${IMAGE_TAGS_WITH_VARIABLE_SUBSTITUTIONS_WITH_DEFAULTS[@]}; do
254
- IFS=':' read -r -a variable_and_default <<< "$VARIABLE_NAME_WITH_DEFAULT_VALUE"
255
- VARIABLE_NAME="${variable_and_default[0]}"
256
- # Read default value and remove the leading hyphen
257
- DEFAULT_VALUE=$(echo ${variable_and_default[1]} | sed "s/^-//")
258
- CURRENT_VALUE=$(echo "${!VARIABLE_NAME}")
259
-
260
- if [ -z "${!VARIABLE_NAME}" ]; then
261
- IMAGE_TAG_LIST=$(echo $IMAGE_TAG_LIST | sed "s/\${$VARIABLE_NAME:-$DEFAULT_VALUE}/$DEFAULT_VALUE/g")
262
- else
263
- IMAGE_TAG_LIST=$(echo $IMAGE_TAG_LIST | sed "s/\${$VARIABLE_NAME:-$DEFAULT_VALUE}/$CURRENT_VALUE/g")
264
- fi
265
- done
266
-
267
- IMAGE_TAG_LIST_WITHOUT_VARIABLE_SUBSTITUTION_DEFAULT_VALUES=$(echo $IMAGE_TAG_LIST \
268
- | sed -E "s/:-[A-Za-z_0-9]+//g" \
269
- | sed -E "s/[{}]//g")
270
-
271
- echo $IMAGE_TAG_LIST_WITHOUT_VARIABLE_SUBSTITUTION_DEFAULT_VALUES \
272
- | envsubst \
273
- | sed 's/ /\n/g'
274
- }
275
-
276
- split_and_join() {
277
- separator_for_splitting=$1
278
- separator_for_joining=$2
279
- text=$3
280
- SPLIT=$(echo $text | sed -e "s/$separator_for_splitting/$separator_for_joining/g")
281
- echo $SPLIT
282
- }
283
- cleanup_docker_images()
284
- {
285
- echo "Cleaning up the docker images"
286
- configured_ssh "/usr/bin/docker system prune -af | sudo tee -a /var/log/docker-prune.log > /dev/null"
287
- }
288
-
289
- docker_stack_deploy() {
290
- echo "Deploying this environment: $ENVIRONMENT_COMPOSE"
291
-
292
- echo "Pulling all docker images. This might take a while"
293
-
294
- EXISTING_IMAGES=$(configured_ssh "docker images --format '{{.Repository}}:{{.Tag}}'")
295
- IMAGE_TAGS_TO_DOWNLOAD=$(get_docker_tags_from_compose_files "$COMPOSE_FILES_USED")
296
-
297
- for tag in ${IMAGE_TAGS_TO_DOWNLOAD[@]}; do
298
- if [[ $EXISTING_IMAGES == *"$tag"* ]]; then
299
- echo "$tag already exists on the machine. Skipping..."
300
- continue
301
- fi
302
-
303
- echo "Downloading $tag"
304
-
305
- until configured_ssh "cd /opt/opencrvs && docker pull $tag"
306
- do
307
- echo "Server failed to download $tag. Retrying..."
308
- sleep 5
309
- done &
310
- done
311
- wait
312
- echo "Images are successfully downloaded"
313
- echo "Updating docker swarm stack with new compose files"
314
-
315
- configured_ssh 'cd /opt/opencrvs && \
316
- docker stack deploy --prune -c '$(split_and_join " " " -c " "$(to_remote_paths $COMPOSE_FILES_USED)")' --with-registry-auth opencrvs'
317
- }
318
-
319
- get_opencrvs_version() {
320
- PREVIOUS_VERSION=$(configured_ssh "docker service ls | grep opencrvs_base | cut -d ':' -f 2")
321
- echo "Previous opencrvs version: $PREVIOUS_VERSION"
322
- echo "Current opencrvs version: $VERSION"
323
- }
324
-
325
- validate_options
326
-
327
- get_opencrvs_version
328
-
329
- # Create new passwords for all MongoDB users created in
330
- # infrastructure/mongodb/docker-entrypoint-initdb.d/create-mongo-users.sh
331
- #
332
- # If you're adding a new MongoDB user, you'll need to also create a new update statement in
333
- # infrastructure/mongodb/on-deploy.sh
334
-
335
- export USER_MGNT_MONGODB_PASSWORD=`generate_password`
336
- export HEARTH_MONGODB_PASSWORD=`generate_password`
337
- export METRICS_MONGODB_PASSWORD=`generate_password`
338
- export PERFORMANCE_MONGODB_PASSWORD=`generate_password`
339
- export OPENHIM_MONGODB_PASSWORD=`generate_password`
340
- export EVENTS_MONGODB_PASSWORD=`generate_password`
341
-
342
- export DEFAULT_REDIS_PASSWORD=`generate_password`
343
- export GATEWAY_REDIS_USERNAME=`generate_password`
344
- export GATEWAY_REDIS_PASSWORD=`generate_password`
345
- export AUTH_REDIS_USERNAME=`generate_password`
346
- export AUTH_REDIS_PASSWORD=`generate_password`
347
-
348
- export EVENTS_APP_POSTGRES_PASSWORD=`generate_password`
349
- export EVENTS_MIGRATOR_POSTGRES_PASSWORD=`generate_password`
350
- export ANALYTICS_POSTGRES_PASSWORD=`generate_password`
351
-
352
- #
353
- # Elasticsearch credentials
354
- #
355
- # Notice that all of these passwords change on each deployment.
356
-
357
- # Application password for OpenCRVS Search
358
- export ROTATING_SEARCH_ELASTIC_PASSWORD=`generate_password`
359
- # If new applications require access to ElasticSearch, new passwords should be generated here.
360
- # Remember to add the user to infrastructure/elasticsearch/setup-users.sh so it is created when you deploy.
361
-
362
- # Used by Metricsbeat when writing data to ElasticSearch
363
- export ROTATING_METRICBEAT_ELASTIC_PASSWORD=`generate_password`
364
-
365
- # Used by APM for writing data to ElasticSearch
366
- export ROTATING_APM_ELASTIC_PASSWORD=`generate_password`
367
-
368
- # Download core compose files to /tmp/
369
- for compose_file in ${COMPOSE_FILES_DOWNLOADED_FROM_CORE[@]}; do
370
- if [ ! -f $compose_file ]; then
371
- echo "Downloading $compose_file from https://raw.githubusercontent.com/opencrvs/opencrvs-core/$VERSION/$(basename $compose_file)"
372
- curl -o $compose_file https://raw.githubusercontent.com/opencrvs/opencrvs-core/$VERSION/$(basename $compose_file)
373
- fi
374
- done
375
-
376
- validate_environment_variables
377
- save_redis_acl
378
-
379
- if [ "$SSH_PORT" -eq 22 ]; then
380
- SSH_HOST_TO_CHECK="$SSH_HOST"
381
- else
382
- SSH_HOST_TO_CHECK="[$SSH_HOST]:$SSH_PORT"
383
- fi
384
-
385
- if ! ssh-keygen -l -F "$SSH_HOST_TO_CHECK" -f "$INFRASTRUCTURE_DIRECTORY/known-hosts"; then
386
- echo "Host key for [$SSH_HOST]:$SSH_PORT not found in $INFRASTRUCTURE_DIRECTORY/known-hosts. Please add the host key to the known-hosts file."
387
- echo "You can do this by running the following command:"
388
- echo "sh ./infrastructure/environments/update-known-hosts.sh <YOUR DOMAIN>"
389
- echo ""
390
- echo "or"
391
- echo ""
392
- echo "sh ./infrastructure/environments/update-known-hosts.sh <YOUR SERVER IP>"
393
- exit 1
394
- fi
395
-
396
- echo
397
- echo "Deploying VERSION $VERSION to $SSH_HOST..."
398
- echo
399
- echo "Deploying COUNTRY_CONFIG_VERSION $COUNTRY_CONFIG_VERSION to $SSH_HOST..."
400
- echo
401
- echo "Syncing configuration files to the target server"
402
-
403
-
404
- configured_rsync -rlD $PROJECT_ROOT/infrastructure $SSH_USER@$SSH_HOST:/opt/opencrvs/ --delete --no-perms --omit-dir-times --verbose
405
- configured_rsync -rlD /tmp/docker-compose.yml /tmp/docker-compose.deps.yml $SSH_USER@$SSH_HOST:/opt/opencrvs/infrastructure --no-perms --omit-dir-times --verbose
406
-
407
- echo "Logging to Dockerhub"
408
-
409
- configured_ssh "docker login -u $DOCKER_USERNAME -p $DOCKER_TOKEN"
410
-
411
- # Setup configuration files and compose file for the deployment domain
412
- configured_ssh "/opt/opencrvs/infrastructure/setup-deploy-config.sh $HOST"
413
-
414
- rotate_secrets
415
-
416
- cleanup_docker_images
417
-
418
- docker_stack_deploy
419
-
420
- echo
421
- echo "This script doesnt ensure that all docker containers successfully start, just that docker_stack_deploy ran successfully."
422
- echo
423
- echo "Waiting 2 mins for mongo to deploy before working with data. Please note it can take up to 10 minutes for the entire stack to deploy in some scenarios."
424
- echo
425
-
426
- echo 'Setting up elastalert indices'
427
-
428
- while true; do
429
- if configured_ssh "/opt/opencrvs/infrastructure/elasticsearch/setup-elastalert-indices.sh"; then
430
- break
431
- fi
432
- sleep 5
433
- done
434
-
435
- echo "Setting up Kibana config & alerts"
436
-
437
- while true; do
438
- if configured_ssh "HOST=kibana.$HOST /opt/opencrvs/infrastructure/monitoring/kibana/setup-config.sh"; then
439
- break
440
- fi
441
- sleep 5
442
- done
443
-
444
- # Send a notification email to confirm emails are working
445
- EMAIL_PAYLOAD='{
446
- "subject": "🚀 Deployment to '$ENV' finished",
447
- "html": "Deployment to '$ENV' was successful with images '$VERSION' for core and '$COUNTRY_CONFIG_VERSION' for country config.",
448
- "from": "{{SENDER_EMAIL_ADDRESS}}",
449
- "to": "{{ALERT_EMAIL}}"
450
- }'
451
-
452
- configured_ssh "docker run --rm --network=opencrvs_overlay_net appropriate/curl \
453
- -X POST 'http://countryconfig:3040/email' \
454
- -H 'Content-Type: application/json' \
455
- -d '$EMAIL_PAYLOAD'"