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.
This commit is contained in:
parent
8cb88024c0
commit
a7e34c0829
|
@ -4,6 +4,8 @@ import {
|
||||||
downloadDockerCompose,
|
downloadDockerCompose,
|
||||||
handleError,
|
handleError,
|
||||||
getServices,
|
getServices,
|
||||||
|
getServiceImage,
|
||||||
|
setServiceImage,
|
||||||
} from "./utils"
|
} from "./utils"
|
||||||
import { confirmation } from "../questions"
|
import { confirmation } from "../questions"
|
||||||
import compose from "docker-compose"
|
import compose from "docker-compose"
|
||||||
|
@ -23,7 +25,11 @@ export async function update() {
|
||||||
!isSingle &&
|
!isSingle &&
|
||||||
(await confirmation("Do you wish to update you docker-compose.yaml?"))
|
(await confirmation("Do you wish to update you docker-compose.yaml?"))
|
||||||
) {
|
) {
|
||||||
|
// get current MinIO image
|
||||||
|
const image = await getServiceImage("minio")
|
||||||
await downloadDockerCompose()
|
await downloadDockerCompose()
|
||||||
|
// replace MinIO image
|
||||||
|
setServiceImage("minio", image)
|
||||||
}
|
}
|
||||||
await handleError(async () => {
|
await handleError(async () => {
|
||||||
const status = await compose.ps()
|
const status = await compose.ps()
|
||||||
|
|
|
@ -9,10 +9,44 @@ const ERROR_FILE = "docker-error.log"
|
||||||
const COMPOSE_URL =
|
const COMPOSE_URL =
|
||||||
"https://raw.githubusercontent.com/Budibase/budibase/master/hosting/docker-compose.yaml"
|
"https://raw.githubusercontent.com/Budibase/budibase/master/hosting/docker-compose.yaml"
|
||||||
|
|
||||||
export async function downloadDockerCompose() {
|
function composeFilename() {
|
||||||
const fileName = COMPOSE_URL.split("/").slice(-1)[0]
|
return COMPOSE_URL.split("/").slice(-1)[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getServiceImage(service: string) {
|
||||||
|
const filename = composeFilename()
|
||||||
try {
|
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) {
|
} catch (err) {
|
||||||
console.error(error(`Failed to retrieve compose file - ${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) {
|
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 dockerYaml = fs.readFileSync(path, "utf8")
|
||||||
const parsedYaml = yaml.parse(dockerYaml)
|
const parsedYaml = yaml.parse(dockerYaml)
|
||||||
return { yaml: parsedYaml, services: parsedYaml.services }
|
return { yaml: parsedYaml, services: parsedYaml.services }
|
||||||
|
|
Loading…
Reference in New Issue