1
0
Fork 0
mirror of synced 2024-06-29 19:41:03 +12:00

Updating for consistent use of chalk and logs, as well as adding an option to update docker-compose and envoy files.

This commit is contained in:
mike12345567 2021-02-26 17:08:28 +00:00
parent b22684163c
commit 3669e59bc3
5 changed files with 37 additions and 19 deletions

View file

@ -3,3 +3,4 @@ docker-compose.yaml
envoy.yaml
hosting.properties
build/
docker-error.log

View file

@ -1,12 +1,11 @@
const Command = require("../structures/Command")
const { CommandWords } = require("../constants")
const { lookpath } = require("lookpath")
const { downloadFile, logErrorToFile } = require("../utils")
const { downloadFile, logErrorToFile, success, info } = require("../utils")
const { confirmation } = require("../questions")
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"
@ -15,6 +14,15 @@ const FILE_URLS = [
"https://raw.githubusercontent.com/Budibase/budibase/master/hosting/envoy.yaml"
]
async function downloadFiles() {
const promises = []
for (let url of FILE_URLS) {
const fileName = url.split("/").slice(-1)[0]
promises.push(downloadFile(url, `./${fileName}`))
}
await Promise.all(promises)
}
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")
@ -48,28 +56,25 @@ async function init() {
console.log("Stopping.")
return
}
const promises = []
for (let url of FILE_URLS) {
const fileName = url.split("/").slice(-1)[0]
promises.push(downloadFile(url, `./${fileName}`))
}
await Promise.all(promises)
await downloadFiles()
await envFile.make()
}
async function start() {
await checkDockerConfigured()
checkInitComplete()
console.log(info("Starting services, this may take a moment."))
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.`))
console.log(success(`Services started, please go to http://localhost:${port} for next steps.`))
}
async function status() {
await checkDockerConfigured()
checkInitComplete()
console.log(info("Budibase status"))
await handleError(async () => {
const response = await compose.ps()
console.log(response.out)
@ -79,23 +84,31 @@ async function status() {
async function stop() {
await checkDockerConfigured()
checkInitComplete()
console.log(info("Stopping services, this may take a moment."))
await handleError(async () => {
await compose.stop()
})
console.log(success("Services have been stopped successfully."))
}
async function update() {
await checkDockerConfigured()
checkInitComplete()
if (await confirmation("Do you wish to update you docker-compose.yaml and envoy.yaml?")) {
await downloadFiles()
}
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."))
if (isUp) {
console.log(info("Stopping services, this may take a moment."))
await compose.stop()
}
console.log(info("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..."))
console.log(success("Update complete, restarting services..."))
await start()
}
})

View file

@ -1,5 +1,5 @@
const { string, number } = require("../questions")
const { getSuccess } = require("../utils")
const { success } = require("../utils")
const fs = require("fs")
const path = require("path")
const randomString = require("randomstring")
@ -36,7 +36,7 @@ module.exports.make = async () => {
const hostingPort = await number("Please enter the port on which you want your installation to run: ", 10000)
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."))
console.log(success("Configuration has been written successfully - please check .env file for more details."))
}
module.exports.get = property => {

View file

@ -1,7 +1,7 @@
const {
getSubHelpDescription,
getHelpDescription,
getError,
error,
} = require("../utils")
class Command {
@ -52,11 +52,11 @@ class Command {
}
}
if (!executed) {
console.log(getError(`Unknown ${this.command} option.`))
console.log(error(`Unknown ${this.command} option.`))
command.help()
}
} catch (err) {
console.log(getError(err))
console.log(error(err))
}
})
}

View file

@ -29,14 +29,18 @@ exports.getSubHelpDescription = string => {
return chalk.green(string)
}
exports.getError = error => {
exports.error = error => {
return chalk.red(`Error - ${error}`)
}
exports.getSuccess = success => {
exports.success = success => {
return chalk.green(success)
}
exports.info = info => {
return chalk.cyan(info)
}
exports.logErrorToFile = (file, error) => {
fs.writeFileSync(path.resolve(`./${file}`), `Budiase Error\n${error}`)
}