Updating with pkg to make the CLI run anywhere easily.
This commit is contained in:
parent
3747b41452
commit
7b528db449
|
@ -2,3 +2,4 @@ node_modules/
|
|||
docker-compose.yaml
|
||||
envoy.yaml
|
||||
hosting.properties
|
||||
build/
|
||||
|
|
|
@ -3,14 +3,20 @@
|
|||
"version": "0.7.8",
|
||||
"description": "Budibase CLI, for developers, self hosting and migrations.",
|
||||
"main": "src/index.js",
|
||||
"bin": "src/index.js",
|
||||
"author": "Budibase",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"scripts": {
|
||||
"build": "pkg . --out-path build"
|
||||
},
|
||||
"dependencies": {
|
||||
"axios": "^0.21.1",
|
||||
"chalk": "^4.1.0",
|
||||
"commander": "^7.1.0",
|
||||
"docker-compose": "^0.23.6",
|
||||
"inquirer": "^8.0.0",
|
||||
"lookpath": "^1.1.0",
|
||||
"pkg": "^4.4.9",
|
||||
"randomstring": "^1.1.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -1,11 +1,15 @@
|
|||
const Command = require("../structures/Command")
|
||||
const { CommandWords } = require("../constants")
|
||||
const { spawn } = require("child_process")
|
||||
const { lookpath } = require("lookpath")
|
||||
const { downloadFile } = require("../utils")
|
||||
const { downloadFile, logErrorToFile } = require("../utils")
|
||||
const { confirmation } = require("../questions")
|
||||
const makeEnvFile = require("./makeEnv")
|
||||
const fs = require("fs")
|
||||
const compose = require("docker-compose")
|
||||
const envFile = require("./makeEnv")
|
||||
const chalk = require("chalk")
|
||||
|
||||
const BUDIBASE_SERVICES = ["app-service", "worker-service"]
|
||||
const ERROR_FILE = "docker-error.log"
|
||||
const FILE_URLS = [
|
||||
"https://raw.githubusercontent.com/Budibase/budibase/master/hosting/docker-compose.yaml",
|
||||
"https://raw.githubusercontent.com/Budibase/budibase/master/hosting/envoy.yaml"
|
||||
|
@ -20,6 +24,23 @@ async function checkDockerConfigured() {
|
|||
}
|
||||
}
|
||||
|
||||
function checkInitComplete() {
|
||||
if (!fs.existsSync(envFile.filePath)) {
|
||||
throw "Please run the hosting --init command before any other hosting command."
|
||||
}
|
||||
}
|
||||
|
||||
async function handleError(func) {
|
||||
try {
|
||||
await func()
|
||||
} catch (err) {
|
||||
if (err && err.err) {
|
||||
logErrorToFile(ERROR_FILE, err.err)
|
||||
}
|
||||
throw `Failed to start - logs written to file: ${ERROR_FILE}`
|
||||
}
|
||||
}
|
||||
|
||||
async function init() {
|
||||
await checkDockerConfigured()
|
||||
const shouldContinue = await confirmation("This will create multiple files in current directory, should continue?")
|
||||
|
@ -33,19 +54,51 @@ async function init() {
|
|||
promises.push(downloadFile(url, `./${fileName}`))
|
||||
}
|
||||
await Promise.all(promises)
|
||||
await makeEnvFile()
|
||||
await envFile.make()
|
||||
}
|
||||
|
||||
async function start() {
|
||||
console.log("START")
|
||||
await checkDockerConfigured()
|
||||
checkInitComplete()
|
||||
const port = envFile.get("MAIN_PORT")
|
||||
await handleError(async () => {
|
||||
await compose.upAll({cwd: "./", log: false})
|
||||
})
|
||||
console.log(chalk.green(`Services started, please go to http://localhost:${port} for next steps.`))
|
||||
}
|
||||
|
||||
async function status() {
|
||||
await checkDockerConfigured()
|
||||
checkInitComplete()
|
||||
await handleError(async () => {
|
||||
const response = await compose.ps()
|
||||
console.log(response.out)
|
||||
})
|
||||
}
|
||||
|
||||
async function stop() {
|
||||
console.log("STOP")
|
||||
await checkDockerConfigured()
|
||||
checkInitComplete()
|
||||
await handleError(async () => {
|
||||
await compose.stop()
|
||||
})
|
||||
}
|
||||
|
||||
async function update() {
|
||||
console.log("UPDATE")
|
||||
await checkDockerConfigured()
|
||||
checkInitComplete()
|
||||
await handleError(async () => {
|
||||
const status = await compose.ps()
|
||||
const parts = status.out.split("\n")
|
||||
const isUp = parts[2] && parts[2].indexOf("Up") !== -1
|
||||
await compose.stop()
|
||||
console.log(chalk.cyan("Beginning update, this may take a few minutes."))
|
||||
await compose.pullMany(BUDIBASE_SERVICES, {log: true})
|
||||
if (isUp) {
|
||||
console.log(chalk.green("Update complete, restarting services..."))
|
||||
await start()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
const command = new Command(`${CommandWords.HOSTING}`)
|
||||
|
@ -60,6 +113,11 @@ const command = new Command(`${CommandWords.HOSTING}`)
|
|||
"Start the configured platform in current directory.",
|
||||
start
|
||||
)
|
||||
.addSubOption(
|
||||
"--status",
|
||||
"Check the status of currently running services.",
|
||||
status
|
||||
)
|
||||
.addSubOption(
|
||||
"--stop",
|
||||
"Stop the configured platform in the current directory.",
|
||||
|
|
|
@ -29,10 +29,22 @@ COUCH_DB_PORT=4005
|
|||
BUDIBASE_ENVIRONMENT=PRODUCTION`
|
||||
}
|
||||
|
||||
module.exports = async () => {
|
||||
module.exports.filePath = FILE_PATH
|
||||
|
||||
module.exports.make = async () => {
|
||||
const hostingKey = await string("Please input the password you'd like to use as your hosting key: ")
|
||||
const hostingPort = await number("Please enter the port on which you want your installation to run: ", 10000)
|
||||
const fileContents = getContents(hostingKey, hostingPort)
|
||||
const fileContents = getContents(hostingPort, hostingKey)
|
||||
fs.writeFileSync(FILE_PATH, fileContents)
|
||||
console.log(getSuccess("Configuration has been written successfully - please check .env file for more details."))
|
||||
}
|
||||
}
|
||||
|
||||
module.exports.get = property => {
|
||||
const props = fs.readFileSync(FILE_PATH, "utf8").split(property)
|
||||
if (props[0].charAt(0) === "=") {
|
||||
property = props[0]
|
||||
} else {
|
||||
property = props[1]
|
||||
}
|
||||
return property.split("=")[1].split("\n")[0]
|
||||
}
|
||||
|
|
|
@ -36,3 +36,7 @@ exports.getError = error => {
|
|||
exports.getSuccess = success => {
|
||||
return chalk.green(success)
|
||||
}
|
||||
|
||||
exports.logErrorToFile = (file, error) => {
|
||||
fs.writeFileSync(path.resolve(`./${file}`), `Budiase Error\n${error}`)
|
||||
}
|
||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue