2022-09-28 01:04:26 +02:00
|
|
|
const { number } = require("../questions")
|
2022-09-28 01:16:04 +02:00
|
|
|
const { success, stringifyToDotEnv } = require("../utils")
|
2022-09-28 01:04:26 +02:00
|
|
|
const fs = require("fs")
|
|
|
|
const path = require("path")
|
|
|
|
const randomString = require("randomstring")
|
|
|
|
const yaml = require("yaml")
|
2022-09-28 20:11:22 +02:00
|
|
|
const { getAppService } = require("./utils")
|
2022-09-28 01:04:26 +02:00
|
|
|
|
|
|
|
const SINGLE_IMAGE = "budibase/budibase:latest"
|
|
|
|
const VOL_NAME = "budibase_data"
|
|
|
|
const COMPOSE_PATH = path.resolve("./docker-compose.yaml")
|
|
|
|
const ENV_PATH = path.resolve("./.env")
|
|
|
|
|
2022-09-29 15:00:16 +02:00
|
|
|
function getSecrets(opts = { single: false }) {
|
2022-09-28 01:17:46 +02:00
|
|
|
const secrets = [
|
|
|
|
"JWT_SECRET",
|
|
|
|
"MINIO_ACCESS_KEY",
|
|
|
|
"MINIO_SECRET_KEY",
|
|
|
|
"REDIS_PASSWORD",
|
|
|
|
"INTERNAL_API_KEY",
|
|
|
|
]
|
|
|
|
const obj = {}
|
|
|
|
secrets.forEach(secret => (obj[secret] = randomString.generate()))
|
2022-09-29 15:00:16 +02:00
|
|
|
// setup couch creds separately
|
|
|
|
if (opts && opts.single) {
|
|
|
|
obj["COUCHDB_USER"] = "admin"
|
|
|
|
obj["COUCHDB_PASSWORD"] = randomString.generate()
|
|
|
|
} else {
|
|
|
|
obj["COUCH_DB_USER"] = "admin"
|
|
|
|
obj["COUCH_DB_PASSWORD"] = randomString.generate()
|
|
|
|
}
|
2022-09-28 01:17:46 +02:00
|
|
|
return obj
|
|
|
|
}
|
|
|
|
|
2022-09-28 01:04:26 +02:00
|
|
|
function getSingleCompose(port) {
|
|
|
|
const singleComposeObj = {
|
|
|
|
version: "3",
|
|
|
|
services: {
|
|
|
|
budibase: {
|
|
|
|
restart: "unless-stopped",
|
|
|
|
image: SINGLE_IMAGE,
|
|
|
|
ports: [`${port}:80`],
|
2022-09-29 15:00:16 +02:00
|
|
|
environment: getSecrets({ single: true }),
|
2022-09-28 01:04:26 +02:00
|
|
|
volumes: [`${VOL_NAME}:/data`],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
volumes: {
|
|
|
|
[VOL_NAME]: {
|
|
|
|
driver: "local",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return yaml.stringify(singleComposeObj)
|
|
|
|
}
|
|
|
|
|
|
|
|
function getEnv(port) {
|
2022-09-28 01:16:04 +02:00
|
|
|
const partOne = stringifyToDotEnv({
|
|
|
|
MAIN_PORT: port,
|
|
|
|
})
|
2022-09-28 01:17:46 +02:00
|
|
|
const partTwo = stringifyToDotEnv(getSecrets())
|
2022-09-28 01:16:04 +02:00
|
|
|
const partThree = stringifyToDotEnv({
|
|
|
|
APP_PORT: 4002,
|
|
|
|
WORKER_PORT: 4003,
|
|
|
|
MINIO_PORT: 4004,
|
|
|
|
COUCH_DB_PORT: 4005,
|
|
|
|
REDIS_PORT: 6379,
|
|
|
|
WATCHTOWER_PORT: 6161,
|
|
|
|
BUDIBASE_ENVIRONMENT: "PRODUCTION",
|
|
|
|
})
|
|
|
|
return [
|
|
|
|
"# Use the main port in the builder for your self hosting URL, e.g. localhost:10000",
|
|
|
|
partOne,
|
|
|
|
"# This section contains all secrets pertaining to the system",
|
|
|
|
partTwo,
|
|
|
|
"# This section contains variables that do not need to be altered under normal circumstances",
|
|
|
|
partThree,
|
|
|
|
].join("\n")
|
2022-09-28 01:04:26 +02:00
|
|
|
}
|
|
|
|
|
2022-09-28 20:11:22 +02:00
|
|
|
exports.ENV_PATH = ENV_PATH
|
|
|
|
exports.COMPOSE_PATH = COMPOSE_PATH
|
|
|
|
|
2022-09-28 01:04:26 +02:00
|
|
|
module.exports.ConfigMap = {
|
|
|
|
MAIN_PORT: "port",
|
|
|
|
}
|
2022-09-28 20:11:22 +02:00
|
|
|
|
2022-09-28 01:04:26 +02:00
|
|
|
module.exports.QUICK_CONFIG = {
|
|
|
|
key: "budibase",
|
|
|
|
port: 10000,
|
|
|
|
}
|
|
|
|
|
|
|
|
async function make(path, contentsFn, inputs = {}) {
|
|
|
|
const port =
|
|
|
|
inputs.port ||
|
|
|
|
(await number(
|
|
|
|
"Please enter the port on which you want your installation to run: ",
|
|
|
|
10000
|
|
|
|
))
|
|
|
|
const fileContents = contentsFn(port)
|
|
|
|
fs.writeFileSync(path, fileContents)
|
|
|
|
console.log(
|
|
|
|
success(
|
|
|
|
`Configuration has been written successfully - please check ${path} for more details.`
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.makeEnv = async (inputs = {}) => {
|
|
|
|
return make(ENV_PATH, getEnv, inputs)
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.makeSingleCompose = async (inputs = {}) => {
|
|
|
|
return make(COMPOSE_PATH, getSingleCompose, inputs)
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.getEnvProperty = property => {
|
|
|
|
const props = fs.readFileSync(ENV_PATH, "utf8").split(property)
|
|
|
|
if (props[0].charAt(0) === "=") {
|
|
|
|
property = props[0]
|
|
|
|
} else {
|
|
|
|
property = props[1]
|
|
|
|
}
|
|
|
|
return property.split("=")[1].split("\n")[0]
|
|
|
|
}
|
2022-09-28 20:11:22 +02:00
|
|
|
|
|
|
|
module.exports.getComposeProperty = property => {
|
2022-09-29 15:00:16 +02:00
|
|
|
const { service } = getAppService(COMPOSE_PATH)
|
|
|
|
if (property === "port" && Array.isArray(service.ports)) {
|
|
|
|
const port = service.ports[0]
|
2022-09-28 20:11:22 +02:00
|
|
|
return port.split(":")[0]
|
2022-09-29 15:00:16 +02:00
|
|
|
} else if (service.environment) {
|
|
|
|
return service.environment[property]
|
2022-09-28 20:11:22 +02:00
|
|
|
}
|
|
|
|
return null
|
|
|
|
}
|