Fixing an issue with single image docker-compose generation.

This commit is contained in:
mike12345567 2022-09-29 14:00:16 +01:00
parent a464aceffb
commit 2a2d5ca19e
4 changed files with 22 additions and 18 deletions

View File

@ -11,19 +11,24 @@ const VOL_NAME = "budibase_data"
const COMPOSE_PATH = path.resolve("./docker-compose.yaml")
const ENV_PATH = path.resolve("./.env")
function getSecrets() {
function getSecrets(opts = { single: false }) {
const secrets = [
"JWT_SECRET",
"MINIO_ACCESS_KEY",
"MINIO_SECRET_KEY",
"COUCH_DB_PASSWORD",
"REDIS_PASSWORD",
"INTERNAL_API_KEY",
]
const obj = {}
secrets.forEach(secret => (obj[secret] = randomString.generate()))
// hard code to admin
obj["COUCH_DB_USER"] = "admin"
// setup couch creds separately
if (opts && opts.single) {
obj["COUCHDB_USER"] = "admin"
obj["COUCHDB_PASSWORD"] = randomString.generate()
} else {
obj["COUCH_DB_USER"] = "admin"
obj["COUCH_DB_PASSWORD"] = randomString.generate()
}
return obj
}
@ -35,7 +40,7 @@ function getSingleCompose(port) {
restart: "unless-stopped",
image: SINGLE_IMAGE,
ports: [`${port}:80`],
environment: getSecrets(),
environment: getSecrets({ single: true }),
volumes: [`${VOL_NAME}:/data`],
},
},
@ -119,12 +124,12 @@ module.exports.getEnvProperty = property => {
}
module.exports.getComposeProperty = property => {
const appService = getAppService(COMPOSE_PATH)
if (property === "port" && Array.isArray(appService.ports)) {
const port = appService.ports[0]
const { service } = getAppService(COMPOSE_PATH)
if (property === "port" && Array.isArray(service.ports)) {
const port = service.ports[0]
return port.split(":")[0]
} else if (appService.environment) {
return appService.environment[property]
} else if (service.environment) {
return service.environment[property]
}
return null
}

View File

@ -15,7 +15,8 @@ const BB_COMPOSE_SERVICES = ["app-service", "worker-service", "proxy-service"]
const BB_SINGLE_SERVICE = ["budibase"]
exports.update = async () => {
const isSingle = Object.keys(getServices(COMPOSE_PATH)).length === 1
const { services } = getServices(COMPOSE_PATH)
const isSingle = Object.keys(services).length === 1
await checkDockerConfigured()
checkInitComplete()
if (

View File

@ -51,11 +51,11 @@ exports.handleError = async func => {
exports.getServices = path => {
const dockerYaml = fs.readFileSync(path, "utf8")
const parsedYaml = yaml.parse(dockerYaml)
return parsedYaml.services
return { yaml: parsedYaml, services: parsedYaml.services }
}
exports.getAppService = path => {
const services = exports.getServices(path),
const { yaml, services } = exports.getServices(path),
serviceList = Object.keys(services)
let service
if (services["app-service"]) {
@ -63,5 +63,5 @@ exports.getAppService = path => {
} else if (serviceList.length === 1) {
service = services[serviceList[0]]
}
return service
return { yaml, service }
}

View File

@ -1,7 +1,7 @@
const { resolve } = require("path")
const fs = require("fs")
const { error, success } = require("../utils")
const yaml = require("yaml")
const { error, success } = require("../utils")
const { getAppService } = require("./utils")
exports.watchPlugins = async pluginPath => {
@ -22,9 +22,7 @@ exports.watchPlugins = async pluginPath => {
console.log(error("Unable to locate docker-compose YAML."))
return
}
const dockerYaml = fs.readFileSync(dockerFilePath, "utf8")
const parsedYaml = yaml.parse(dockerYaml)
const service = getAppService(dockerFilePath)
const { yaml: parsedYaml, service } = getAppService(dockerFilePath)
if (!service) {
console.log(
error(