Merge pull request #12566 from Budibase/fix-dotenv-order-issues

Chore - Ensure .env is created properly for dev
This commit is contained in:
Adria Navarro 2023-12-13 13:31:31 +01:00 committed by GitHub
commit 63f5a962d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 69 additions and 76 deletions

View File

@ -1,7 +1,8 @@
#!/usr/bin/env node #!/usr/bin/env node
const compose = require("docker-compose") const compose = require("docker-compose")
const path = require("path") const path = require("path")
const fs = require("fs") const { parsed: existingConfig } = require("dotenv").config()
const updateDotEnv = require("update-dotenv")
// This script wraps docker-compose allowing you to manage your dev infrastructure with simple commands. // This script wraps docker-compose allowing you to manage your dev infrastructure with simple commands.
const CONFIG = { const CONFIG = {
@ -17,45 +18,41 @@ const Commands = {
} }
async function init() { async function init() {
const envFilePath = path.join(process.cwd(), ".env") let config = {
if (!fs.existsSync(envFilePath)) { PORT: "4001",
const envFileJson = { MINIO_URL: "http://localhost:4004",
PORT: 4001, COUCH_DB_URL: "http://budibase:budibase@localhost:4005",
MINIO_URL: "http://localhost:4004", REDIS_URL: "localhost:6379",
COUCH_DB_URL: "http://budibase:budibase@localhost:4005", WORKER_URL: "http://localhost:4002",
REDIS_URL: "localhost:6379", INTERNAL_API_KEY: "budibase",
WORKER_URL: "http://localhost:4002", ACCOUNT_PORTAL_URL: "http://localhost:10001",
INTERNAL_API_KEY: "budibase", ACCOUNT_PORTAL_API_KEY: "budibase",
ACCOUNT_PORTAL_URL: "http://localhost:10001", PLATFORM_URL: "http://localhost:10000",
ACCOUNT_PORTAL_API_KEY: "budibase", JWT_SECRET: "testsecret",
PLATFORM_URL: "http://localhost:10000", ENCRYPTION_KEY: "testsecret",
JWT_SECRET: "testsecret", REDIS_PASSWORD: "budibase",
ENCRYPTION_KEY: "testsecret", MINIO_ACCESS_KEY: "budibase",
REDIS_PASSWORD: "budibase", MINIO_SECRET_KEY: "budibase",
MINIO_ACCESS_KEY: "budibase", COUCH_DB_PASSWORD: "budibase",
MINIO_SECRET_KEY: "budibase", COUCH_DB_USER: "budibase",
COUCH_DB_PASSWORD: "budibase", SELF_HOSTED: "1",
COUCH_DB_USER: "budibase", DISABLE_ACCOUNT_PORTAL: "1",
SELF_HOSTED: 1, MULTI_TENANCY: "",
DISABLE_ACCOUNT_PORTAL: 1, DISABLE_THREADING: "1",
MULTI_TENANCY: "", SERVICE: "app-service",
DISABLE_THREADING: 1, DEPLOYMENT_ENVIRONMENT: "development",
SERVICE: "app-service", BB_ADMIN_USER_EMAIL: "",
DEPLOYMENT_ENVIRONMENT: "development", BB_ADMIN_USER_PASSWORD: "",
BB_ADMIN_USER_EMAIL: "", PLUGINS_DIR: "",
BB_ADMIN_USER_PASSWORD: "", TENANT_FEATURE_FLAGS: "*:LICENSING,*:USER_GROUPS,*:ONBOARDING_TOUR",
PLUGINS_DIR: "", HTTP_MIGRATIONS: "0",
TENANT_FEATURE_FLAGS: "*:LICENSING,*:USER_GROUPS,*:ONBOARDING_TOUR", HTTP_LOGGING: "0",
HTTP_MIGRATIONS: "0", VERSION: "0.0.0+local",
HTTP_LOGGING: "0",
VERSION: "0.0.0+local",
}
let envFile = ""
Object.keys(envFileJson).forEach(key => {
envFile += `${key}=${envFileJson[key]}\n`
})
fs.writeFileSync(envFilePath, envFile)
} }
config = { ...config, ...existingConfig }
await updateDotEnv(config)
} }
async function up() { async function up() {

View File

@ -1,44 +1,40 @@
#!/usr/bin/env node #!/usr/bin/env node
const path = require("path") const { parsed: existingConfig } = require("dotenv").config()
const fs = require("fs") const updateDotEnv = require("update-dotenv")
async function init() { async function init() {
const envFilePath = path.join(process.cwd(), ".env") let config = {
if (!fs.existsSync(envFilePath)) { SELF_HOSTED: "1",
const envFileJson = { PORT: "4002",
SELF_HOSTED: 1, CLUSTER_PORT: "10000",
PORT: 4002, JWT_SECRET: "testsecret",
CLUSTER_PORT: 10000, INTERNAL_API_KEY: "budibase",
JWT_SECRET: "testsecret", MINIO_ACCESS_KEY: "budibase",
INTERNAL_API_KEY: "budibase", MINIO_SECRET_KEY: "budibase",
MINIO_ACCESS_KEY: "budibase", REDIS_URL: "localhost:6379",
MINIO_SECRET_KEY: "budibase", REDIS_PASSWORD: "budibase",
REDIS_URL: "localhost:6379", MINIO_URL: "http://localhost:4004",
REDIS_PASSWORD: "budibase", COUCH_DB_URL: "http://budibase:budibase@localhost:4005",
MINIO_URL: "http://localhost:4004", COUCH_DB_USERNAME: "budibase",
COUCH_DB_URL: "http://budibase:budibase@localhost:4005", COUCH_DB_PASSWORD: "budibase",
COUCH_DB_USERNAME: "budibase", // empty string is false
COUCH_DB_PASSWORD: "budibase", MULTI_TENANCY: "",
// empty string is false DISABLE_ACCOUNT_PORTAL: "1",
MULTI_TENANCY: "", ACCOUNT_PORTAL_URL: "http://localhost:10001",
DISABLE_ACCOUNT_PORTAL: 1, ACCOUNT_PORTAL_API_KEY: "budibase",
ACCOUNT_PORTAL_URL: "http://localhost:10001", PLATFORM_URL: "http://localhost:10000",
ACCOUNT_PORTAL_API_KEY: "budibase", APPS_URL: "http://localhost:4001",
PLATFORM_URL: "http://localhost:10000", SERVICE: "worker-service",
APPS_URL: "http://localhost:4001", DEPLOYMENT_ENVIRONMENT: "development",
SERVICE: "worker-service", TENANT_FEATURE_FLAGS: "*:LICENSING,*:USER_GROUPS,*:ONBOARDING_TOUR",
DEPLOYMENT_ENVIRONMENT: "development", ENABLE_EMAIL_TEST_MODE: "1",
TENANT_FEATURE_FLAGS: "*:LICENSING,*:USER_GROUPS,*:ONBOARDING_TOUR", HTTP_LOGGING: "0",
ENABLE_EMAIL_TEST_MODE: 1, VERSION: "0.0.0+local",
HTTP_LOGGING: 0,
VERSION: "0.0.0+local",
}
let envFile = ""
Object.keys(envFileJson).forEach(key => {
envFile += `${key}=${envFileJson[key]}\n`
})
fs.writeFileSync(envFilePath, envFile)
} }
config = { ...config, ...existingConfig }
await updateDotEnv(config)
} }
// if more than init required use this to determine the command type // if more than init required use this to determine the command type