Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

Added check-env script.

Mike Cao19ac0fce3632
diff --git a/package.json b/package.json
index 0db07f49c..02820f229 100644
--- a/package.json
+++ b/package.json
@@ -11,7 +11,7 @@
},
"scripts": {
"dev": "next dev -p 3000",
- "build": "npm-run-all build-db check-db build-tracker build-geo build-app",
+ "build": "npm-run-all check-env build-db check-db build-tracker build-geo build-app",
"start": "next start",
"build-docker": "npm-run-all build-db build-tracker build-geo build-app",
"start-docker": "npm-run-all check-db update-tracker start-server",
@@ -27,6 +27,7 @@
"update-tracker": "node scripts/update-tracker.js",
"update-db": "prisma migrate deploy",
"check-db": "node scripts/check-db.js",
+ "check-env": "node scripts/check-env.js",
"copy-db-files": "node scripts/copy-db-files.js",
"extract-messages": "formatjs extract \"{pages,components}/**/*.js\" --out-file build/messages.json",
"merge-messages": "node scripts/merge-messages.js",
diff --git a/scripts/check-env.js b/scripts/check-env.js
new file mode 100644
index 000000000..612e658c7
--- /dev/null
+++ b/scripts/check-env.js
@@ -0,0 +1,32 @@
+/* eslint-disable no-console */
+require('dotenv').config();
+
+function checkMissing(vars) {
+ const missing = vars.reduce((arr, key) => {
+ if (!process.env[key]) {
+ arr.push(key);
+ }
+ }, []);
+
+ if (missing.length) {
+ console.log(`The following environment variables are not defined:`);
+ for (const item of missing) {
+ console.log(' - ', item);
+ }
+ process.exit(1);
+ }
+}
+
+checkMissing(['DATABASE_URL']);
+
+if (process.env.CLICKHOUSE_URL) {
+ checkMissing(['CA_CERT', 'CLIENT_CERT', 'CLIENT_KEY', 'KAFKA_BROKER', 'KAFKA_URL', 'REDIS_URL']);
+}
+
+if (process.env.CLOUD_MODE) {
+ checkMissing(['CLOUD_URL']);
+}
+
+if (process.env.ENABLE_BLOCKER) {
+ checkMissing(['REDIS_URL']);
+}