Added check-env script.

This commit is contained in:
Mike Cao 2023-05-16 20:41:20 -07:00
parent c567eddff9
commit 19ac0fce36
2 changed files with 34 additions and 1 deletions

View File

@ -11,7 +11,7 @@
}, },
"scripts": { "scripts": {
"dev": "next dev -p 3000", "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", "start": "next start",
"build-docker": "npm-run-all build-db build-tracker build-geo build-app", "build-docker": "npm-run-all build-db build-tracker build-geo build-app",
"start-docker": "npm-run-all check-db update-tracker start-server", "start-docker": "npm-run-all check-db update-tracker start-server",
@ -27,6 +27,7 @@
"update-tracker": "node scripts/update-tracker.js", "update-tracker": "node scripts/update-tracker.js",
"update-db": "prisma migrate deploy", "update-db": "prisma migrate deploy",
"check-db": "node scripts/check-db.js", "check-db": "node scripts/check-db.js",
"check-env": "node scripts/check-env.js",
"copy-db-files": "node scripts/copy-db-files.js", "copy-db-files": "node scripts/copy-db-files.js",
"extract-messages": "formatjs extract \"{pages,components}/**/*.js\" --out-file build/messages.json", "extract-messages": "formatjs extract \"{pages,components}/**/*.js\" --out-file build/messages.json",
"merge-messages": "node scripts/merge-messages.js", "merge-messages": "node scripts/merge-messages.js",

32
scripts/check-env.js Normal file
View File

@ -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']);
}