From a7e34c0829751ed0dc3f8f1d94028db744d678cc Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Thu, 9 Mar 2023 13:52:35 +0000 Subject: [PATCH] Minor fix for CLI - to preserve the MinIO image, meaning that new installations will always use the minio/minio image, whereas older installations can use the RELEASE.2022-10-24T18-35-07Z version which still supports the FS system. --- packages/cli/src/hosting/update.ts | 6 +++++ packages/cli/src/hosting/utils.ts | 43 +++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 3 deletions(-) diff --git a/packages/cli/src/hosting/update.ts b/packages/cli/src/hosting/update.ts index 161cc04ae1..ca0ecce615 100644 --- a/packages/cli/src/hosting/update.ts +++ b/packages/cli/src/hosting/update.ts @@ -4,6 +4,8 @@ import { downloadDockerCompose, handleError, getServices, + getServiceImage, + setServiceImage, } from "./utils" import { confirmation } from "../questions" import compose from "docker-compose" @@ -23,7 +25,11 @@ export async function update() { !isSingle && (await confirmation("Do you wish to update you docker-compose.yaml?")) ) { + // get current MinIO image + const image = await getServiceImage("minio") await downloadDockerCompose() + // replace MinIO image + setServiceImage("minio", image) } await handleError(async () => { const status = await compose.ps() diff --git a/packages/cli/src/hosting/utils.ts b/packages/cli/src/hosting/utils.ts index 9e5bd367ed..93e31b8aea 100644 --- a/packages/cli/src/hosting/utils.ts +++ b/packages/cli/src/hosting/utils.ts @@ -9,10 +9,44 @@ const ERROR_FILE = "docker-error.log" const COMPOSE_URL = "https://raw.githubusercontent.com/Budibase/budibase/master/hosting/docker-compose.yaml" -export async function downloadDockerCompose() { - const fileName = COMPOSE_URL.split("/").slice(-1)[0] +function composeFilename() { + return COMPOSE_URL.split("/").slice(-1)[0] +} + +export function getServiceImage(service: string) { + const filename = composeFilename() try { - await downloadFile(COMPOSE_URL, `./${fileName}`) + const { services } = getServices(filename) + const serviceKey = Object.keys(services).find(name => + name.includes(service) + ) + if (serviceKey) { + return services[serviceKey].image + } else { + return null + } + } catch (err) { + return null + } +} + +export function setServiceImage(service: string, image: string) { + const filename = composeFilename() + if (!fs.existsSync(filename)) { + throw new Error( + `File ${filename} not found, cannot update ${service} image.` + ) + } + const current = getServiceImage(service)! + let contents = fs.readFileSync(filename, "utf8") + contents = contents.replace(`image: ${current}`, `image: ${image}`) + fs.writeFileSync(filename, contents) +} + +export async function downloadDockerCompose() { + const filename = composeFilename() + try { + await downloadFile(COMPOSE_URL, `./${filename}`) } catch (err) { console.error(error(`Failed to retrieve compose file - ${err}`)) } @@ -49,6 +83,9 @@ export async function handleError(func: Function) { } export function getServices(path: string) { + if (!fs.existsSync(path)) { + throw new Error(`No yaml found at path: ${path}`) + } const dockerYaml = fs.readFileSync(path, "utf8") const parsedYaml = yaml.parse(dockerYaml) return { yaml: parsedYaml, services: parsedYaml.services }