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

View File

@ -15,7 +15,8 @@ const BB_COMPOSE_SERVICES = ["app-service", "worker-service", "proxy-service"]
const BB_SINGLE_SERVICE = ["budibase"] const BB_SINGLE_SERVICE = ["budibase"]
exports.update = async () => { 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() await checkDockerConfigured()
checkInitComplete() checkInitComplete()
if ( if (

View File

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

View File

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