Some changes to how environment is loaded to make the init process by default flesh out some good settings.
This commit is contained in:
parent
091782389a
commit
d7497aa989
|
@ -14,10 +14,14 @@ services:
|
||||||
CLOUD: 1
|
CLOUD: 1
|
||||||
COUCH_DB_URL: http://${COUCH_DB_USER}:${COUCH_DB_PASSWORD}@couchdb-service:5984
|
COUCH_DB_URL: http://${COUCH_DB_USER}:${COUCH_DB_PASSWORD}@couchdb-service:5984
|
||||||
WORKER_URL: http://worker-service:4003
|
WORKER_URL: http://worker-service:4003
|
||||||
|
MINIO_URL: http://minio-service:9000
|
||||||
HOSTING_KEY: ${HOSTING_KEY}
|
HOSTING_KEY: ${HOSTING_KEY}
|
||||||
BUDIBASE_ENVIRONMENT: ${BUDIBASE_ENVIRONMENT}
|
BUDIBASE_ENVIRONMENT: ${BUDIBASE_ENVIRONMENT}
|
||||||
PORT: 4002
|
PORT: 4002
|
||||||
JWT_SECRET: ${JWT_SECRET}
|
JWT_SECRET: ${JWT_SECRET}
|
||||||
|
LOG_LEVEL: info
|
||||||
|
SENTRY_DSN: https://a34ae347621946bf8acded18e5b7d4b8@o420233.ingest.sentry.io/5338131
|
||||||
|
ENABLE_ANALYTICS: true
|
||||||
depends_on:
|
depends_on:
|
||||||
- worker-service
|
- worker-service
|
||||||
|
|
||||||
|
@ -28,7 +32,7 @@ services:
|
||||||
ports:
|
ports:
|
||||||
- "${WORKER_PORT}:4003"
|
- "${WORKER_PORT}:4003"
|
||||||
environment:
|
environment:
|
||||||
SELF_HOSTED: 1,
|
SELF_HOSTED: 1
|
||||||
PORT: 4003
|
PORT: 4003
|
||||||
MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY}
|
MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY}
|
||||||
MINIO_SECRET_KEY: ${MINIO_SECRET_KEY}
|
MINIO_SECRET_KEY: ${MINIO_SECRET_KEY}
|
||||||
|
|
|
@ -1,17 +0,0 @@
|
||||||
# url of couch db, including username and password
|
|
||||||
# http://admin:password@localhost:5984
|
|
||||||
COUCH_DB_URL={{couchDbUrl}}
|
|
||||||
|
|
||||||
# identifies a client database - i.e. group of apps
|
|
||||||
CLIENT_ID={{clientId}}
|
|
||||||
|
|
||||||
# used to create cookie hashes
|
|
||||||
JWT_SECRET={{cookieKey1}}
|
|
||||||
|
|
||||||
# error level for koa-pino
|
|
||||||
LOG_LEVEL=info
|
|
||||||
|
|
||||||
DEPLOYMENT_CREDENTIALS_URL="https://dt4mpwwap8.execute-api.eu-west-1.amazonaws.com/prod/"
|
|
||||||
DEPLOYMENT_DB_URL="https://couchdb.budi.live:5984"
|
|
||||||
SENTRY_DSN=https://a34ae347621946bf8acded18e5b7d4b8@o420233.ingest.sentry.io/5338131
|
|
||||||
ENABLE_ANALYTICS="true"
|
|
|
@ -1 +0,0 @@
|
||||||
PORT=4001
|
|
|
@ -39,7 +39,7 @@
|
||||||
"dev:stack:up": "node scripts/dev/manage.js up",
|
"dev:stack:up": "node scripts/dev/manage.js up",
|
||||||
"dev:stack:down": "node scripts/dev/manage.js down",
|
"dev:stack:down": "node scripts/dev/manage.js down",
|
||||||
"dev:stack:nuke": "node scripts/dev/manage.js nuke",
|
"dev:stack:nuke": "node scripts/dev/manage.js nuke",
|
||||||
"dev:builder": "npm run dev:stack:up && env-cmd -f dev.env nodemon src/index.js",
|
"dev:builder": "npm run dev:stack:up && nodemon src/index.js",
|
||||||
"electron": "electron src/electron.js",
|
"electron": "electron src/electron.js",
|
||||||
"build:electron": "electron-builder --dir",
|
"build:electron": "electron-builder --dir",
|
||||||
"publish:electron": "electron-builder -mwl --publish always",
|
"publish:electron": "electron-builder -mwl --publish always",
|
||||||
|
@ -141,7 +141,6 @@
|
||||||
"electron": "10.1.3",
|
"electron": "10.1.3",
|
||||||
"electron-builder": "^22.9.1",
|
"electron-builder": "^22.9.1",
|
||||||
"electron-builder-notarize": "^1.1.2",
|
"electron-builder-notarize": "^1.1.2",
|
||||||
"env-cmd": "^10.1.0",
|
|
||||||
"eslint": "^6.8.0",
|
"eslint": "^6.8.0",
|
||||||
"jest": "^24.8.0",
|
"jest": "^24.8.0",
|
||||||
"nodemon": "^2.0.4",
|
"nodemon": "^2.0.4",
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#!/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")
|
||||||
|
|
||||||
// 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 = {
|
||||||
|
@ -26,8 +27,34 @@ if (
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function init() {
|
||||||
|
const envFilePath = path.join(process.cwd(), ".env")
|
||||||
|
if (fs.existsSync(envFilePath)) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
const envFileJson = {
|
||||||
|
PORT: 4001,
|
||||||
|
MINIO_URL: "http://localhost:10000/",
|
||||||
|
COUCH_DB_URL: "http://budibase:budibase@localhost:10000/db/",
|
||||||
|
WORKER_URL: "http://localhost:4002",
|
||||||
|
JWT_SECRET: "testsecret",
|
||||||
|
MINIO_ACCESS_KEY: "budibase",
|
||||||
|
MINIO_SECRET_KEY: "budibase",
|
||||||
|
COUCH_DB_PASSWORD: "budibase",
|
||||||
|
COUCH_DB_USER: "budibase",
|
||||||
|
SELF_HOSTED: 1,
|
||||||
|
CLOUD: 1,
|
||||||
|
}
|
||||||
|
let envFile = ""
|
||||||
|
Object.keys(envFileJson).forEach(key => {
|
||||||
|
envFile += `${key}=${envFileJson[key]}\n`
|
||||||
|
})
|
||||||
|
fs.writeFileSync(envFilePath, envFile)
|
||||||
|
}
|
||||||
|
|
||||||
async function up() {
|
async function up() {
|
||||||
console.log("Spinning up your budibase dev environment... 🔧✨")
|
console.log("Spinning up your budibase dev environment... 🔧✨")
|
||||||
|
await init()
|
||||||
try {
|
try {
|
||||||
await compose.upAll(CONFIG)
|
await compose.upAll(CONFIG)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
|
@ -18,12 +18,6 @@ async function startApp() {
|
||||||
}
|
}
|
||||||
// evict environment from cache, so it reloads when next asked
|
// evict environment from cache, so it reloads when next asked
|
||||||
delete require.cache[require.resolve("./environment")]
|
delete require.cache[require.resolve("./environment")]
|
||||||
// store the port incase its going to get overridden
|
|
||||||
const port = process.env.PORT
|
|
||||||
require("dotenv").config({ path: envFile })
|
|
||||||
// overwrite the port - don't want to use dotenv for the port
|
|
||||||
require("./environment")._set("PORT", port)
|
|
||||||
|
|
||||||
unhandled({
|
unhandled({
|
||||||
showDialog: true,
|
showDialog: true,
|
||||||
reportButton: error => {
|
reportButton: error => {
|
||||||
|
|
|
@ -1,38 +1,45 @@
|
||||||
const { resolve, join } = require("./utilities/centralPath")
|
function isDev() {
|
||||||
const { homedir } = require("os")
|
return (
|
||||||
const { app } = require("electron")
|
!process.env.CLOUD &&
|
||||||
|
process.env.NODE_ENV !== "production" &&
|
||||||
|
process.env.NODE_ENV !== "jest" &&
|
||||||
|
process.env.NODE_ENV !== "cypress" &&
|
||||||
|
process.env.JEST_WORKER_ID == null
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
let LOADED = false
|
let LOADED = false
|
||||||
|
if (!LOADED && isDev()) {
|
||||||
if (!LOADED) {
|
require("dotenv").config()
|
||||||
const homeDir = app ? app.getPath("home") : homedir()
|
|
||||||
const budibaseDir = join(homeDir, ".budibase")
|
|
||||||
process.env.BUDIBASE_DIR = budibaseDir
|
|
||||||
require("dotenv").config({ path: resolve(budibaseDir, ".env") })
|
|
||||||
LOADED = true
|
LOADED = true
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
CLIENT_ID: process.env.CLIENT_ID,
|
// important
|
||||||
NODE_ENV: process.env.NODE_ENV,
|
|
||||||
JWT_SECRET: process.env.JWT_SECRET,
|
|
||||||
BUDIBASE_DIR: process.env.BUDIBASE_DIR,
|
|
||||||
PORT: process.env.PORT,
|
PORT: process.env.PORT,
|
||||||
|
JWT_SECRET: process.env.JWT_SECRET,
|
||||||
COUCH_DB_URL: process.env.COUCH_DB_URL,
|
COUCH_DB_URL: process.env.COUCH_DB_URL,
|
||||||
|
MINIO_URL: process.env.MINIO_URL,
|
||||||
|
WORKER_URL: process.env.WORKER_URL,
|
||||||
|
CLOUD: process.env.CLOUD,
|
||||||
|
SELF_HOSTED: process.env.SELF_HOSTED,
|
||||||
|
AWS_REGION: process.env.AWS_REGION,
|
||||||
|
ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS,
|
||||||
|
// environment
|
||||||
|
NODE_ENV: process.env.NODE_ENV,
|
||||||
|
JEST_WORKER_ID: process.env.JEST_WORKER_ID,
|
||||||
|
BUDIBASE_ENVIRONMENT: process.env.BUDIBASE_ENVIRONMENT,
|
||||||
|
// minor
|
||||||
SALT_ROUNDS: process.env.SALT_ROUNDS,
|
SALT_ROUNDS: process.env.SALT_ROUNDS,
|
||||||
LOGGER: process.env.LOGGER,
|
LOGGER: process.env.LOGGER,
|
||||||
LOG_LEVEL: process.env.LOG_LEVEL,
|
LOG_LEVEL: process.env.LOG_LEVEL,
|
||||||
AUTOMATION_DIRECTORY: process.env.AUTOMATION_DIRECTORY,
|
AUTOMATION_DIRECTORY: process.env.AUTOMATION_DIRECTORY,
|
||||||
AUTOMATION_BUCKET: process.env.AUTOMATION_BUCKET,
|
AUTOMATION_BUCKET: process.env.AUTOMATION_BUCKET,
|
||||||
BUDIBASE_ENVIRONMENT: process.env.BUDIBASE_ENVIRONMENT,
|
|
||||||
SENDGRID_API_KEY: process.env.SENDGRID_API_KEY,
|
SENDGRID_API_KEY: process.env.SENDGRID_API_KEY,
|
||||||
CLOUD: process.env.CLOUD,
|
|
||||||
SELF_HOSTED: process.env.SELF_HOSTED,
|
|
||||||
WORKER_URL: process.env.WORKER_URL,
|
|
||||||
DYNAMO_ENDPOINT: process.env.DYNAMO_ENDPOINT,
|
DYNAMO_ENDPOINT: process.env.DYNAMO_ENDPOINT,
|
||||||
AWS_REGION: process.env.AWS_REGION,
|
// old - to remove
|
||||||
ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS,
|
CLIENT_ID: process.env.CLIENT_ID,
|
||||||
// TODO: remove all below - single stack conversion
|
BUDIBASE_DIR: process.env.BUDIBASE_DIR,
|
||||||
DEPLOYMENT_DB_URL: process.env.DEPLOYMENT_DB_URL,
|
DEPLOYMENT_DB_URL: process.env.DEPLOYMENT_DB_URL,
|
||||||
BUDIBASE_API_KEY: process.env.BUDIBASE_API_KEY,
|
BUDIBASE_API_KEY: process.env.BUDIBASE_API_KEY,
|
||||||
USERID_API_KEY: process.env.USERID_API_KEY,
|
USERID_API_KEY: process.env.USERID_API_KEY,
|
||||||
|
@ -42,4 +49,5 @@ module.exports = {
|
||||||
process.env[key] = value
|
process.env[key] = value
|
||||||
module.exports[key] = value
|
module.exports[key] = value
|
||||||
},
|
},
|
||||||
|
isDev,
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,14 +13,7 @@ function confirmAppId(possibleAppId) {
|
||||||
|
|
||||||
exports.wait = ms => new Promise(resolve => setTimeout(resolve, ms))
|
exports.wait = ms => new Promise(resolve => setTimeout(resolve, ms))
|
||||||
|
|
||||||
exports.isDev = () => {
|
exports.isDev = env.isDev
|
||||||
return (
|
|
||||||
!env.CLOUD &&
|
|
||||||
env.NODE_ENV !== "production" &&
|
|
||||||
env.NODE_ENV !== "jest" &&
|
|
||||||
env.NODE_ENV !== "cypress"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a request tries to find the appId, which can be located in various places
|
* Given a request tries to find the appId, which can be located in various places
|
||||||
|
|
Loading…
Reference in New Issue