budibase/packages/cli/src/hosting/index.js

74 lines
2.0 KiB
JavaScript
Raw Normal View History

const Command = require("../structures/Command")
const { CommandWords } = require("../constants")
2021-02-26 14:30:24 +01:00
const { spawn } = require("child_process")
const { lookpath } = require("lookpath")
const { downloadFile } = require("../utils")
const { confirmation } = require("../questions")
const FILE_URLS = [
"https://raw.githubusercontent.com/Budibase/budibase/master/hosting/docker-compose.yaml",
"https://raw.githubusercontent.com/Budibase/budibase/master/hosting/envoy.yaml",
"https://github.com/Budibase/budibase/blob/master/hosting/hosting.properties"
]
async function checkDockerConfigured() {
const error = "docker/docker-compose has not been installed, please follow instructions at: https://docs.budibase.com/self-hosting/hosting-methods/docker-compose#installing-docker"
const docker = await lookpath("docker")
const compose = await lookpath("docker-compose")
if (!docker || !compose) {
throw error
}
}
2021-02-24 18:32:45 +01:00
async function init() {
2021-02-26 14:30:24 +01:00
await checkDockerConfigured()
const shouldContinue = await confirmation("This will create multiple files in current directory, should continue?")
if (!shouldContinue) {
console.log("Stopping.")
return
}
const promises = []
for (let url of FILE_URLS) {
promises.push(downloadFile(url, __dirname))
}
await Promise.all(promises)
console.log("Files have been downloaded, ready to start.")
}
async function start() {
console.log("START")
}
async function stop() {
console.log("STOP")
}
async function update() {
console.log("UPDATE")
}
const command = new Command(`${CommandWords.HOSTING}`)
2021-02-25 15:42:50 +01:00
.addHelp("Controls self hosting on the Budibase platform.")
.addSubOption(
"--init",
"Configure a self hosted platform in current directory.",
init
)
.addSubOption(
"--start",
"Start the configured platform in current directory.",
start
)
.addSubOption(
"--stop",
"Stop the configured platform in the current directory.",
stop
)
.addSubOption(
"--update",
"Updates the Budibase images to the latest version.",
update
)
2021-02-25 15:42:50 +01:00
exports.command = command