2021-03-22 18:05:00 +01:00
|
|
|
#!/usr/bin/env node
|
|
|
|
const compose = require("docker-compose")
|
|
|
|
const path = require("path")
|
2023-12-13 13:14:13 +01:00
|
|
|
const { parsed: existingConfig } = require("dotenv").config()
|
|
|
|
const updateDotEnv = require("update-dotenv")
|
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() {
|
2023-12-13 13:14:13 +01:00
|
|
|
let config = {
|
|
|
|
PORT: "4001",
|
|
|
|
MINIO_URL: "http://localhost:4004",
|
|
|
|
COUCH_DB_URL: "http://budibase:budibase@localhost:4005",
|
|
|
|
REDIS_URL: "localhost:6379",
|
|
|
|
WORKER_URL: "http://localhost:4002",
|
|
|
|
INTERNAL_API_KEY: "budibase",
|
|
|
|
ACCOUNT_PORTAL_URL: "http://localhost:10001",
|
|
|
|
ACCOUNT_PORTAL_API_KEY: "budibase",
|
|
|
|
PLATFORM_URL: "http://localhost:10000",
|
|
|
|
JWT_SECRET: "testsecret",
|
|
|
|
ENCRYPTION_KEY: "testsecret",
|
|
|
|
REDIS_PASSWORD: "budibase",
|
|
|
|
MINIO_ACCESS_KEY: "budibase",
|
|
|
|
MINIO_SECRET_KEY: "budibase",
|
|
|
|
COUCH_DB_PASSWORD: "budibase",
|
|
|
|
COUCH_DB_USER: "budibase",
|
|
|
|
SELF_HOSTED: "1",
|
|
|
|
DISABLE_ACCOUNT_PORTAL: "1",
|
|
|
|
MULTI_TENANCY: "",
|
|
|
|
SERVICE: "app-service",
|
|
|
|
DEPLOYMENT_ENVIRONMENT: "development",
|
|
|
|
BB_ADMIN_USER_EMAIL: "",
|
|
|
|
BB_ADMIN_USER_PASSWORD: "",
|
|
|
|
PLUGINS_DIR: "",
|
|
|
|
HTTP_MIGRATIONS: "0",
|
|
|
|
HTTP_LOGGING: "0",
|
|
|
|
VERSION: "0.0.0+local",
|
2024-01-03 10:12:22 +01:00
|
|
|
PASSWORD_MIN_LENGTH: "1",
|
2024-06-06 17:10:58 +02:00
|
|
|
SQS_SEARCH_ENABLE: "1",
|
2021-03-23 16:37:11 +01:00
|
|
|
}
|
2023-12-13 13:14:13 +01:00
|
|
|
|
|
|
|
config = { ...config, ...existingConfig }
|
|
|
|
|
|
|
|
await updateDotEnv(config)
|
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()
|
2022-09-16 10:25:14 +02:00
|
|
|
await compose.upAll(CONFIG)
|
2022-09-15 17:31:29 +02:00
|
|
|
|
|
|
|
// We always ensure to restart the proxy service in case of nginx conf changes
|
|
|
|
await compose.restartOne("proxy-service", 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
|
|
|
})
|