@opencrvs/toolkit 2.1.0-rc.1f71eca → 2.1.0-rc.268cfbe

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 (242) hide show
  1. package/README.md +3 -12
  2. package/build.sh +22 -4
  3. package/create-countryconfig/index.js +441 -59
  4. package/create-countryconfig/node_modules/.bin/degit +21 -0
  5. package/create-countryconfig/package.json +4 -1
  6. package/dist/application-config/index.js +361 -284
  7. package/dist/authentication/index.d.ts +66 -0
  8. package/dist/authentication/index.d.ts.map +1 -0
  9. package/dist/authentication/index.js +765 -0
  10. package/dist/cli.js +3751 -1232
  11. package/dist/commons/api/router.d.ts +663 -365
  12. package/dist/commons/application-config/index.d.ts +0 -2
  13. package/dist/commons/conditionals/conditionals.d.ts +6 -6
  14. package/dist/commons/conditionals/validate.d.ts +34 -8
  15. package/dist/commons/events/ActionConfig.d.ts +5 -14
  16. package/dist/commons/events/ActionDocument.d.ts +35 -15
  17. package/dist/commons/events/ActionInput.d.ts +4 -4
  18. package/dist/commons/events/ActionStatus.d.ts +14 -0
  19. package/dist/commons/events/AdvancedSearchConfig.d.ts +42 -12
  20. package/dist/commons/events/AuditLog.d.ts +1 -0
  21. package/dist/commons/events/Draft.d.ts +1 -21
  22. package/dist/commons/events/EventConfig.d.ts +3 -0
  23. package/dist/commons/events/EventDocument.d.ts +472 -4
  24. package/dist/commons/events/EventIndex.d.ts +3 -26
  25. package/dist/commons/events/EventMetadata.d.ts +1 -11
  26. package/dist/commons/events/EventStatus.d.ts +19 -0
  27. package/dist/commons/events/FieldConfig.d.ts +104 -63
  28. package/dist/commons/events/FieldTypeMapping.d.ts +17 -17
  29. package/dist/commons/events/FieldValue.d.ts +3 -2
  30. package/dist/commons/events/Flag.d.ts +42 -0
  31. package/dist/commons/events/FormConfig.d.ts +6 -0
  32. package/dist/commons/events/PageConfig.d.ts +4 -0
  33. package/dist/commons/events/PlainDate.d.ts +8 -0
  34. package/dist/commons/events/SummaryConfig.d.ts +249 -0
  35. package/dist/commons/events/WorkqueueConfig.d.ts +17 -14
  36. package/dist/commons/events/event.d.ts +12 -0
  37. package/dist/commons/events/locations.d.ts +162 -26
  38. package/dist/commons/events/mocks.test.utils.d.ts +30 -0
  39. package/dist/commons/events/scopes.d.ts +21 -1
  40. package/dist/commons/events/test.utils.d.ts +78 -25
  41. package/dist/commons/events/utils.d.ts +39 -4
  42. package/dist/commons/notification/UserNotifications.d.ts +28 -13
  43. package/dist/commons/notification/dispatch.d.ts +10 -0
  44. package/dist/commons/notification/index.d.ts +1 -0
  45. package/dist/conditionals/index.js +348 -65
  46. package/dist/csv.d.ts +25 -0
  47. package/dist/csv.d.ts.map +1 -0
  48. package/dist/csv.js +120 -0
  49. package/dist/environment/index.d.ts +1 -0
  50. package/dist/environment/index.d.ts.map +1 -1
  51. package/dist/environment/index.js +12 -1
  52. package/dist/environment/logger.d.ts +15 -3
  53. package/dist/environment/logger.d.ts.map +1 -1
  54. package/dist/environment/manage-users.js +1 -1
  55. package/dist/environment/paths.d.ts +7 -0
  56. package/dist/environment/paths.d.ts.map +1 -0
  57. package/dist/environment/paths.js +72 -0
  58. package/dist/environment/questions.d.ts.map +1 -1
  59. package/dist/environment/questions.js +20 -14
  60. package/dist/environment/setup-environment.d.ts +1 -1
  61. package/dist/environment/setup-environment.d.ts.map +1 -1
  62. package/dist/environment/setup-environment.js +594 -562
  63. package/dist/environment/swarm-to-k8s.js +3 -4
  64. package/dist/environment/templates.d.ts +0 -1
  65. package/dist/environment/templates.d.ts.map +1 -1
  66. package/dist/environment/templates.js +5 -9
  67. package/dist/environment/update-workflows.d.ts.map +1 -1
  68. package/dist/environment/update-workflows.js +21 -5
  69. package/dist/environment/upgrade.d.ts +2 -0
  70. package/dist/environment/upgrade.d.ts.map +1 -0
  71. package/dist/environment/upgrade.js +82 -0
  72. package/dist/environment/users.js +11 -13
  73. package/dist/environment/utils.d.ts +0 -12
  74. package/dist/environment/utils.d.ts.map +1 -1
  75. package/dist/environment/utils.js +1 -28
  76. package/dist/events/index.js +7177 -6696
  77. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts +3 -0
  78. package/dist/migrations/v2.1/add-recovery-link-notifications.d.ts.map +1 -0
  79. package/dist/migrations/v2.1/add-recovery-link-notifications.js +511 -0
  80. package/dist/migrations/v2.1/add-translations.d.ts +9 -0
  81. package/dist/migrations/v2.1/add-translations.d.ts.map +1 -0
  82. package/dist/migrations/v2.1/add-translations.js +149 -0
  83. package/dist/migrations/{v2.0/rename-api-paths.d.ts → v2.1/enable-telemetry.d.ts} +1 -1
  84. package/dist/migrations/v2.1/enable-telemetry.d.ts.map +1 -0
  85. package/dist/migrations/v2.1/enable-telemetry.js +455 -0
  86. package/dist/migrations/v2.1/index.d.ts.map +1 -1
  87. package/dist/migrations/v2.1/index.js +1952 -0
  88. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts +14 -0
  89. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.d.ts.map +1 -0
  90. package/dist/migrations/v2.1/migrate-infrastructure-to-assets.js +345 -0
  91. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts +2 -0
  92. package/dist/migrations/v2.1/remove-metabase-package-installs.d.ts.map +1 -0
  93. package/dist/migrations/v2.1/remove-metabase-package-installs.js +161 -0
  94. package/dist/migrations/{v2.0/migrate-scopes.d.ts → v2.1/remove-sentry.d.ts} +1 -1
  95. package/dist/migrations/v2.1/remove-sentry.d.ts.map +1 -0
  96. package/dist/migrations/v2.1/remove-sentry.js +354 -0
  97. package/dist/migrations/{v2.0/create-events-index.d.ts → v2.1/rename-trigger-paths.d.ts} +1 -1
  98. package/dist/migrations/v2.1/rename-trigger-paths.d.ts.map +1 -0
  99. package/dist/migrations/{v2.0/rename-api-paths.js → v2.1/rename-trigger-paths.js} +69 -40
  100. package/dist/migrations/v2.1/template-files.d.ts +8 -0
  101. package/dist/migrations/v2.1/template-files.d.ts.map +1 -0
  102. package/dist/migrations/v2.1/template-files.js +49 -0
  103. package/dist/migrations/v2.1/upgrade-tilt.d.ts +8 -0
  104. package/dist/migrations/v2.1/upgrade-tilt.d.ts.map +1 -0
  105. package/dist/migrations/v2.1/upgrade-tilt.js +139 -0
  106. package/dist/notification/index.js +1831 -1513
  107. package/dist/scopes/index.d.ts +612 -36
  108. package/dist/scopes/index.js +350 -65
  109. package/dist/telemetry/index.d.ts +45 -0
  110. package/dist/telemetry/index.d.ts.map +1 -0
  111. package/dist/telemetry/index.js +43 -0
  112. package/dist/templates/charts-values/dependencies/values.yaml +8 -0
  113. package/dist/templates/charts-values/opencrvs-services/values.yaml +10 -3
  114. package/dist/templates/charts-values/opentelemetry/values.yaml +102 -0
  115. package/dist/templates/charts-values/traefik/values.yaml +23 -9
  116. package/dist/templates/countryconfig-template/.tiltignore +1 -0
  117. package/dist/templates/countryconfig-template/Dockerfile.assets +7 -0
  118. package/dist/templates/countryconfig-template/Tiltfile +112 -0
  119. package/dist/templates/countryconfig-template/assets/README.md +1 -0
  120. package/dist/templates/countryconfig-template/assets/clear-all-data-dev.sh +61 -0
  121. package/dist/templates/countryconfig-template/assets/deployment/deploy.sh +455 -0
  122. package/dist/templates/countryconfig-template/assets/deployment/reindex.sh +168 -0
  123. package/dist/templates/countryconfig-template/assets/deployment/validate-required-variables-in-compose-files.ts +67 -0
  124. package/dist/templates/countryconfig-template/assets/elasticsearch/reindex.sh +168 -0
  125. package/dist/templates/countryconfig-template/assets/metabase/README.md +34 -0
  126. package/dist/templates/countryconfig-template/assets/metabase/environment-configuration.sql +36 -0
  127. package/dist/templates/countryconfig-template/assets/metabase/initialize-database.sh +46 -0
  128. package/dist/templates/countryconfig-template/assets/metabase/metabase.init.db.sql +27737 -0
  129. package/dist/templates/countryconfig-template/assets/metabase/open-shell.sh +21 -0
  130. package/dist/templates/countryconfig-template/assets/metabase/package.json +13 -0
  131. package/dist/templates/countryconfig-template/assets/metabase/run-dev.sh +108 -0
  132. package/dist/templates/countryconfig-template/assets/metabase/run.sh +120 -0
  133. package/dist/templates/countryconfig-template/assets/metabase/update-database.sh +40 -0
  134. package/dist/templates/countryconfig-template/assets/postgres/setup-analytics.sh +135 -0
  135. package/dist/templates/countryconfig-template/assets/postgres/setup-reference-data.sh +108 -0
  136. package/dist/templates/countryconfig-template/tilt/clear-all-data.ps1 +50 -0
  137. package/dist/templates/countryconfig-template/tilt/clear-all-data.sh +35 -0
  138. package/dist/templates/countryconfig-template/tilt/common.tilt +145 -0
  139. package/dist/templates/countryconfig-template/tilt/examples/dependencies/values.yaml +15 -0
  140. package/dist/templates/countryconfig-template/tilt/examples/opencrvs-services/values.yaml +56 -0
  141. package/dist/templates/countryconfig-template/tilt/examples/traefik/values-minikube.yaml +21 -0
  142. package/dist/templates/countryconfig-template/tilt/examples/traefik/values.yaml +38 -0
  143. package/dist/templates/countryconfig-template/tilt/helm/dependencies/values.yaml +17 -0
  144. package/dist/templates/countryconfig-template/tilt/helm/opencrvs-services/values.yaml +16 -0
  145. package/dist/templates/countryconfig-template/tilt/lib.tilt +95 -0
  146. package/dist/templates/countryconfig-template/tilt/opencrvs.tilt +136 -0
  147. package/dist/templates/inventory/inventory.template.yml +1 -3
  148. package/dist/translations/template.d.ts +11 -0
  149. package/dist/translations/template.d.ts.map +1 -0
  150. package/dist/translations/template.js +100 -0
  151. package/dist/verify/endpoints.d.ts +2 -0
  152. package/dist/verify/endpoints.d.ts.map +1 -0
  153. package/dist/verify/endpoints.js +510 -0
  154. package/opencrvs-toolkit-2.1.0-rc.268cfbe.tgz +0 -0
  155. package/package.json +13 -7
  156. package/tsconfig.build.json +11 -0
  157. package/tsconfig.build.tsbuildinfo +1 -0
  158. package/tsconfig.json +3 -0
  159. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts +0 -3
  160. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.d.ts.map +0 -1
  161. package/dist/migrations/v2.0/add-birth-certificate-issuance-flag.js +0 -429
  162. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts +0 -3
  163. package/dist/migrations/v2.0/add-resend-invite-notification.d.ts.map +0 -1
  164. package/dist/migrations/v2.0/add-resend-invite-notification.js +0 -373
  165. package/dist/migrations/v2.0/checkout-upstream-files.d.ts +0 -22
  166. package/dist/migrations/v2.0/checkout-upstream-files.d.ts.map +0 -1
  167. package/dist/migrations/v2.0/checkout-upstream-files.js +0 -146
  168. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts +0 -2
  169. package/dist/migrations/v2.0/convert-config-files-to-ts.d.ts.map +0 -1
  170. package/dist/migrations/v2.0/convert-config-files-to-ts.js +0 -838
  171. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts +0 -3
  172. package/dist/migrations/v2.0/convert-paragraph-to-heading.d.ts.map +0 -1
  173. package/dist/migrations/v2.0/convert-paragraph-to-heading.js +0 -158
  174. package/dist/migrations/v2.0/create-events-index.d.ts.map +0 -1
  175. package/dist/migrations/v2.0/create-events-index.js +0 -325
  176. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts +0 -11
  177. package/dist/migrations/v2.0/delete-infrastructure-directory.d.ts.map +0 -1
  178. package/dist/migrations/v2.0/delete-infrastructure-directory.js +0 -123
  179. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts +0 -3
  180. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.d.ts.map +0 -1
  181. package/dist/migrations/v2.0/fix-accept-requested-registration-function-type.js +0 -110
  182. package/dist/migrations/v2.0/index.d.ts +0 -13
  183. package/dist/migrations/v2.0/index.d.ts.map +0 -1
  184. package/dist/migrations/v2.0/index.js +0 -103
  185. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts +0 -3
  186. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.d.ts.map +0 -1
  187. package/dist/migrations/v2.0/make-built-in-validate-actions-custom.js +0 -432
  188. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts +0 -13
  189. package/dist/migrations/v2.0/merge-infrastructure-directory.d.ts.map +0 -1
  190. package/dist/migrations/v2.0/merge-infrastructure-directory.js +0 -222
  191. package/dist/migrations/v2.0/migrate-application-config-url.d.ts +0 -3
  192. package/dist/migrations/v2.0/migrate-application-config-url.d.ts.map +0 -1
  193. package/dist/migrations/v2.0/migrate-application-config-url.js +0 -343
  194. package/dist/migrations/v2.0/migrate-scopes.d.ts.map +0 -1
  195. package/dist/migrations/v2.0/migrate-scopes.js +0 -305
  196. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts +0 -3
  197. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.d.ts.map +0 -1
  198. package/dist/migrations/v2.0/migrate-validated-workqueue-status-to-flag.js +0 -267
  199. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts +0 -3
  200. package/dist/migrations/v2.0/migrate-workqueue-configs.d.ts.map +0 -1
  201. package/dist/migrations/v2.0/migrate-workqueue-configs.js +0 -317
  202. package/dist/migrations/v2.0/remove-delete-actions.d.ts +0 -3
  203. package/dist/migrations/v2.0/remove-delete-actions.d.ts.map +0 -1
  204. package/dist/migrations/v2.0/remove-delete-actions.js +0 -156
  205. package/dist/migrations/v2.0/remove-demo-scope.d.ts +0 -3
  206. package/dist/migrations/v2.0/remove-demo-scope.d.ts.map +0 -1
  207. package/dist/migrations/v2.0/remove-demo-scope.js +0 -74
  208. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts +0 -3
  209. package/dist/migrations/v2.0/remove-deprecated-imports.d.ts.map +0 -1
  210. package/dist/migrations/v2.0/remove-deprecated-imports.js +0 -96
  211. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts +0 -3
  212. package/dist/migrations/v2.0/remove-fhir-url-helpers.d.ts.map +0 -1
  213. package/dist/migrations/v2.0/remove-fhir-url-helpers.js +0 -163
  214. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts +0 -3
  215. package/dist/migrations/v2.0/remove-hearth-migrations.d.ts.map +0 -1
  216. package/dist/migrations/v2.0/remove-hearth-migrations.js +0 -87
  217. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts +0 -3
  218. package/dist/migrations/v2.0/remove-old-statistics-service.d.ts.map +0 -1
  219. package/dist/migrations/v2.0/remove-old-statistics-service.js +0 -356
  220. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts +0 -3
  221. package/dist/migrations/v2.0/remove-pending-certification-flag.d.ts.map +0 -1
  222. package/dist/migrations/v2.0/remove-pending-certification-flag.js +0 -109
  223. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts +0 -3
  224. package/dist/migrations/v2.0/remove-review-from-register-action.d.ts.map +0 -1
  225. package/dist/migrations/v2.0/remove-review-from-register-action.js +0 -163
  226. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts +0 -3
  227. package/dist/migrations/v2.0/remove-unused-environment-variables.d.ts.map +0 -1
  228. package/dist/migrations/v2.0/remove-unused-environment-variables.js +0 -186
  229. package/dist/migrations/v2.0/rename-api-paths.d.ts.map +0 -1
  230. package/dist/migrations/v2.0/rename-location-parent-id.d.ts +0 -3
  231. package/dist/migrations/v2.0/rename-location-parent-id.d.ts.map +0 -1
  232. package/dist/migrations/v2.0/rename-location-parent-id.js +0 -180
  233. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts +0 -3
  234. package/dist/migrations/v2.0/simplify-analytics-precalculations.d.ts.map +0 -1
  235. package/dist/migrations/v2.0/simplify-analytics-precalculations.js +0 -195
  236. package/dist/migrations/v2.0/update-package-json.d.ts +0 -3
  237. package/dist/migrations/v2.0/update-package-json.d.ts.map +0 -1
  238. package/dist/migrations/v2.0/update-package-json.js +0 -105
  239. package/dist/templates/inventory/production.example.yml +0 -77
  240. package/dist/templates/inventory/qa.example.yml +0 -48
  241. package/opencrvs-toolkit-2.1.0-rc.1f71eca.tgz +0 -0
  242. package/tsconfig.tsbuildinfo +0 -1
@@ -0,0 +1,455 @@
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'"
@@ -0,0 +1,168 @@
1
+ #!/usr/bin/env sh
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 -eu
12
+
13
+ EVENTS_URL="${EVENTS_URL:-http://localhost:5555/}"
14
+ AUTH_URL="${AUTH_URL:-http://localhost:4040/}"
15
+ POLL_INTERVAL="${POLL_INTERVAL:-10}"
16
+ MAX_POLLS="${MAX_POLLS:-1080}"
17
+
18
+ get_reindexing_token() {
19
+ curl -s "${AUTH_URL%/}/internal/reindexing-token" | jq -r '.token'
20
+ }
21
+
22
+ fire_trigger() {
23
+ local token=$1
24
+ curl -s -o /dev/null \
25
+ -X POST \
26
+ -H "Authorization: Bearer ${token}" \
27
+ -H "Content-Type: application/json" \
28
+ -d '{"waitForCompletion": false}' \
29
+ "${EVENTS_URL%/}/events/reindex"
30
+ }
31
+
32
+ fetch_latest_run_since() {
33
+ local token=$1
34
+ local since
35
+ local response
36
+ local tmp
37
+ local json_type
38
+ local code
39
+
40
+ since=$(echo "$2" | cut -c1-19)
41
+ tmp=$(mktemp)
42
+
43
+ response=$(curl -sS \
44
+ -H "Authorization: Bearer ${token}" \
45
+ -H "Content-Type: application/json" \
46
+ "${EVENTS_URL%/}/events/reindex" 2>&1) || {
47
+ echo "ERROR: failed to fetch reindex status:" >&2
48
+ echo "$response" >&2
49
+ rm -f "$tmp"
50
+ return 1
51
+ }
52
+
53
+ printf '%s' "$response" > "$tmp"
54
+
55
+ json_type=$(jq -r 'type' "$tmp" 2>/dev/null) || {
56
+ echo "ERROR: reindex status response is not valid JSON:" >&2
57
+ cat "$tmp" >&2
58
+ rm -f "$tmp"
59
+ return 1
60
+ }
61
+
62
+ if [ "$json_type" != "array" ]; then
63
+ code=$(jq -r '.code // .data.code // empty' "$tmp")
64
+
65
+ if [ "$code" = "UNAUTHORIZED" ]; then
66
+ echo "WARN: reindex status token expired; refreshing token..." >&2
67
+ rm -f "$tmp"
68
+ return 2
69
+ fi
70
+
71
+ echo "ERROR: unexpected reindex status response:" >&2
72
+ jq -c '.' "$tmp" >&2
73
+ rm -f "$tmp"
74
+ return 1
75
+ fi
76
+
77
+ jq -c --arg since "$since" \
78
+ 'map(select(.timestamp[0:19] >= $since)) | sort_by(.timestamp) | reverse | .[0] // empty' \
79
+ "$tmp"
80
+
81
+ rm -f "$tmp"
82
+ }
83
+
84
+ TRIGGER_TIME=$(date -u +"%Y-%m-%dT%H:%M:%S")
85
+
86
+ echo "Requesting reindex token..."
87
+ TOKEN=$(get_reindexing_token)
88
+
89
+ echo "Triggering reindex..."
90
+ fire_trigger "$TOKEN"
91
+
92
+ echo "Polling reindex status..."
93
+ polls=0
94
+ first_poll=true
95
+ while true; do
96
+ if [ "$first_poll" = true ]; then
97
+ sleep 3
98
+ first_poll=false
99
+ else
100
+ sleep "${POLL_INTERVAL}"
101
+ fi
102
+ polls=$(( ${polls:-0} + 1 ))
103
+
104
+ if RUN=$(fetch_latest_run_since "$TOKEN" "$TRIGGER_TIME"); then
105
+ :
106
+ else
107
+ rc=$?
108
+
109
+ if [ "$rc" -eq 2 ]; then
110
+ echo " Token expired, refreshing token..."
111
+ TOKEN=$(get_reindexing_token)
112
+
113
+ if RUN=$(fetch_latest_run_since "$TOKEN" "$TRIGGER_TIME"); then
114
+ :
115
+ else
116
+ echo "ERROR: failed to fetch reindex status after refreshing token."
117
+ exit 1
118
+ fi
119
+ else
120
+ echo "ERROR: failed to fetch reindex status."
121
+ exit 1
122
+ fi
123
+ fi
124
+
125
+ if [ -z "$RUN" ]; then
126
+ echo " Waiting for reindex to start... (${polls})"
127
+ if [ "${polls}" -gt "${MAX_POLLS}" ]; then
128
+ echo "ERROR: timed out waiting for reindex to start."
129
+ exit 1
130
+ fi
131
+ continue
132
+ fi
133
+
134
+ STATUS=$(echo "$RUN" | jq -r '.status')
135
+ PROCESSED=$(echo "$RUN" | jq -r '.progress.processed')
136
+
137
+ case "$STATUS" in
138
+ running)
139
+ echo " Running... ${PROCESSED} events processed so far"
140
+ if [ "${polls}" -gt "${MAX_POLLS}" ]; then
141
+ timeout_secs=$(( ${polls:-0} * ${POLL_INTERVAL:-10} ))
142
+ echo "ERROR: reindex timed out after ${timeout_secs} seconds."
143
+ exit 1
144
+ fi
145
+ ;;
146
+ completed)
147
+ SKIPPED=$(echo "$RUN" | jq -r '.progress.skipped // 0')
148
+ echo " Reindex completed — ${PROCESSED} events processed."
149
+ if [ "${SKIPPED}" -gt 0 ]; then
150
+ echo " WARNING: ${SKIPPED} records were skipped because they could not be read:"
151
+ echo "$RUN" | jq -r '.progress.errors[]? | " - " + .'
152
+ echo " Please fix the errors and run the reindex again."
153
+ fi
154
+ exit 0
155
+ ;;
156
+ failed)
157
+ ERROR=$(echo "$RUN" | jq -r '.error_message // "unknown error"')
158
+ echo " ERROR: reindex failed: ${ERROR}"
159
+ exit 1
160
+ ;;
161
+ *)
162
+ echo " Unknown status '${STATUS}' — continuing to poll..."
163
+ if [ "${polls}" -gt "${MAX_POLLS}" ]; then
164
+ exit 1
165
+ fi
166
+ ;;
167
+ esac
168
+ done
@@ -0,0 +1,67 @@
1
+ /*
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
+
12
+ import * as fs from 'fs'
13
+ import { basename } from 'path'
14
+
15
+ function extractEnvVars(content: string): string[] {
16
+ const regex = /(?<!\$)\$\{(.*?)\}/g
17
+ let match: RegExpExecArray | null
18
+ const envVars: Set<string> = new Set()
19
+
20
+ while ((match = regex.exec(content)) !== null) {
21
+ envVars.add(match[1])
22
+ }
23
+
24
+ return Array.from(envVars)
25
+ }
26
+
27
+ function getAllVariableNames(filePaths: string[]) {
28
+ const allVars = new Set<string>()
29
+ filePaths.forEach((filePath) => {
30
+ const content = fs.readFileSync(filePath, 'utf8')
31
+ const envVars = extractEnvVars(content)
32
+ envVars.forEach((envVar) => allVars.add(envVar))
33
+ })
34
+ return Array.from(allVars)
35
+ }
36
+
37
+ // Main function to start the process
38
+ function main(): void {
39
+ // Taking file paths from command line arguments
40
+ const filePaths = process.argv.slice(2)
41
+ if (filePaths.length === 0) {
42
+ console.error('Please provide YAML file paths as arguments.')
43
+ process.exit(1)
44
+ }
45
+
46
+ const requiredValues = getAllVariableNames(filePaths).filter(
47
+ (name) => !name.includes(':-')
48
+ )
49
+
50
+ const missingValues = requiredValues.filter((name) => !process.env[name])
51
+
52
+ if (missingValues.length > 0) {
53
+ console.log('\n\n')
54
+ console.error(
55
+ 'Missing secrets or variables for values found in docker compose files:'
56
+ )
57
+ console.error(missingValues)
58
+ console.error(
59
+ '\nCheck the following files for more details:\n',
60
+ filePaths.map((path) => `- ${basename(path)}`).join('\n')
61
+ )
62
+ console.log('\n')
63
+ process.exit(1)
64
+ }
65
+ }
66
+
67
+ main()