2021-03-22 18:05:00 +01:00
|
|
|
#!/usr/bin/env node
|
|
|
|
const compose = require("docker-compose")
|
|
|
|
const path = require("path")
|
2021-03-23 16:37:11 +01:00
|
|
|
const fs = require("fs")
|
2021-04-07 18:13:19 +02:00
|
|
|
const { processStringSync } = require("@budibase/string-templates")
|
|
|
|
|
|
|
|
function isLinux() {
|
|
|
|
return process.platform !== "darwin" && process.platform !== "win32"
|
|
|
|
}
|
2021-03-22 18:05:00 +01:00
|
|
|
|
|
|
|
// This script wraps docker-compose allowing you to manage your dev infrastructure with simple commands.
|
|
|
|
const CONFIG = {
|
|
|
|
cwd: path.resolve(process.cwd(), "../../hosting"),
|
|
|
|
config: "docker-compose.dev.yaml",
|
|
|
|
log: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
const Commands = {
|
|
|
|
Up: "up",
|
|
|
|
Down: "down",
|
|
|
|
Nuke: "nuke",
|
|
|
|
}
|
|
|
|
|
2021-03-23 16:37:11 +01:00
|
|
|
async function init() {
|
2021-04-07 18:13:19 +02:00
|
|
|
// generate envoy file, always do this incase it has changed
|
|
|
|
const hostingPath = path.join(process.cwd(), "..", "..", "hosting")
|
2022-01-11 20:33:22 +01:00
|
|
|
const envoyHbsPath = path.join(hostingPath, "nginx.dev.conf.hbs")
|
|
|
|
const envoyOutputPath = path.join(hostingPath, ".generated-nginx.dev.conf")
|
2021-04-07 18:13:19 +02:00
|
|
|
const contents = fs.readFileSync(envoyHbsPath, "utf8")
|
|
|
|
const config = {
|
|
|
|
address: isLinux() ? "172.17.0.1" : "host.docker.internal",
|
2021-03-23 16:37:11 +01:00
|
|
|
}
|
2021-04-07 18:13:19 +02:00
|
|
|
fs.writeFileSync(envoyOutputPath, processStringSync(contents, config))
|
|
|
|
|
2021-03-23 16:37:11 +01:00
|
|
|
const envFilePath = path.join(process.cwd(), ".env")
|
2021-08-05 10:59:08 +02:00
|
|
|
if (!fs.existsSync(envFilePath)) {
|
|
|
|
const envFileJson = {
|
|
|
|
PORT: 4001,
|
2022-01-30 21:25:56 +01:00
|
|
|
MINIO_URL: "http://localhost:4004",
|
2021-09-28 19:05:52 +02:00
|
|
|
COUCH_DB_URL: "http://budibase:budibase@localhost:10000/db/",
|
2021-08-05 10:59:08 +02:00
|
|
|
REDIS_URL: "localhost:6379",
|
|
|
|
WORKER_URL: "http://localhost:4002",
|
|
|
|
INTERNAL_API_KEY: "budibase",
|
|
|
|
JWT_SECRET: "testsecret",
|
|
|
|
REDIS_PASSWORD: "budibase",
|
|
|
|
MINIO_ACCESS_KEY: "budibase",
|
|
|
|
MINIO_SECRET_KEY: "budibase",
|
|
|
|
COUCH_DB_PASSWORD: "budibase",
|
|
|
|
COUCH_DB_USER: "budibase",
|
|
|
|
SELF_HOSTED: 1,
|
2021-09-29 17:55:59 +02:00
|
|
|
DISABLE_ACCOUNT_PORTAL: "",
|
2021-08-05 10:59:08 +02:00
|
|
|
MULTI_TENANCY: "",
|
2021-11-22 18:42:41 +01:00
|
|
|
DISABLE_THREADING: 1,
|
2021-08-05 10:59:08 +02:00
|
|
|
}
|
|
|
|
let envFile = ""
|
|
|
|
Object.keys(envFileJson).forEach(key => {
|
|
|
|
envFile += `${key}=${envFileJson[key]}\n`
|
|
|
|
})
|
|
|
|
fs.writeFileSync(envFilePath, envFile)
|
2021-03-23 16:37:11 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-22 18:05:00 +01:00
|
|
|
async function up() {
|
|
|
|
console.log("Spinning up your budibase dev environment... 🔧✨")
|
2021-03-23 16:37:11 +01:00
|
|
|
await init()
|
2021-03-23 12:01:33 +01:00
|
|
|
await compose.upAll(CONFIG)
|
2021-03-22 18:05:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async function down() {
|
|
|
|
console.log("Spinning down your budibase dev environment... 🌇")
|
2021-03-23 12:01:33 +01:00
|
|
|
await compose.stop(CONFIG)
|
2021-03-22 18:05:00 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async function nuke() {
|
|
|
|
console.log(
|
|
|
|
"Clearing down your budibase dev environment, including all containers and volumes... 💥"
|
|
|
|
)
|
2021-04-08 19:18:53 +02:00
|
|
|
await compose.down({
|
|
|
|
...CONFIG,
|
|
|
|
// stop containers, delete volumes
|
|
|
|
commandOptions: ["-v", "--remove-orphans"],
|
|
|
|
})
|
2021-03-22 18:05:00 +01:00
|
|
|
}
|
|
|
|
|
2021-03-22 20:35:29 +01:00
|
|
|
const managementCommand = process.argv.slice(2)[0]
|
|
|
|
|
|
|
|
if (
|
|
|
|
!managementCommand ||
|
2021-05-04 12:32:22 +02:00
|
|
|
!Object.values(Commands).some(command => managementCommand === command)
|
2021-03-22 20:35:29 +01:00
|
|
|
) {
|
|
|
|
throw new Error(
|
|
|
|
"You must supply either an 'up', 'down' or 'nuke' commmand to manage the budibase development environment."
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2021-03-22 18:05:00 +01:00
|
|
|
let command
|
|
|
|
switch (managementCommand) {
|
|
|
|
case Commands.Up:
|
|
|
|
command = up
|
|
|
|
break
|
|
|
|
case Commands.Down:
|
|
|
|
command = down
|
|
|
|
break
|
|
|
|
case Commands.Nuke:
|
|
|
|
command = nuke
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
command = up
|
|
|
|
}
|
|
|
|
|
|
|
|
command()
|
|
|
|
.then(() => {
|
|
|
|
console.log("Done! 🎉")
|
|
|
|
})
|
2021-05-04 12:32:22 +02:00
|
|
|
.catch(err => {
|
2021-03-23 12:01:33 +01:00
|
|
|
console.error(
|
|
|
|
"Something went wrong while managing budibase dev environment:",
|
|
|
|
err.message
|
|
|
|
)
|
2021-03-22 18:05:00 +01:00
|
|
|
})
|