From 406cd53d11c1aad7e55210d9e0ea34c76c23956a Mon Sep 17 00:00:00 2001 From: mike12345567 Date: Wed, 26 Oct 2022 18:51:58 +0100 Subject: [PATCH] Some fixes for CLI to get exporting/importing with different ports working, as well as a fix for access to minio through proxy. --- hosting/nginx.prod.conf.hbs | 2 ++ packages/cli/src/backups/objectStore.js | 5 +++++ packages/cli/src/backups/utils.js | 16 +++++++++++----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/hosting/nginx.prod.conf.hbs b/hosting/nginx.prod.conf.hbs index f3202ad4a4..114a4575d0 100644 --- a/hosting/nginx.prod.conf.hbs +++ b/hosting/nginx.prod.conf.hbs @@ -171,11 +171,13 @@ http { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; + proxy_set_header Host $http_host; proxy_connect_timeout 300; proxy_http_version 1.1; proxy_set_header Connection ""; chunked_transfer_encoding off; + proxy_pass http://$minio:9000; } diff --git a/packages/cli/src/backups/objectStore.js b/packages/cli/src/backups/objectStore.js index b0bf99891d..8d616d276a 100644 --- a/packages/cli/src/backups/objectStore.js +++ b/packages/cli/src/backups/objectStore.js @@ -16,16 +16,21 @@ exports.exportObjects = async () => { const path = join(TEMP_DIR, MINIO_DIR) fs.mkdirSync(path) let fullList = [] + let errorCount = 0 for (let bucket of bucketList) { const client = ObjectStore(bucket) try { await client.headBucket().promise() } catch (err) { + errorCount++ continue } const list = await client.listObjectsV2().promise() fullList = fullList.concat(list.Contents.map(el => ({ ...el, bucket }))) } + if (errorCount === bucketList.length) { + throw new Error("Unable to access MinIO/S3 - check environment config.") + } const bar = progressBar(fullList.length) let count = 0 for (let object of fullList) { diff --git a/packages/cli/src/backups/utils.js b/packages/cli/src/backups/utils.js index 5d941aa17c..645b90379b 100644 --- a/packages/cli/src/backups/utils.js +++ b/packages/cli/src/backups/utils.js @@ -2,17 +2,19 @@ const dotenv = require("dotenv") const fs = require("fs") const { string } = require("../questions") const { getPouch } = require("../core/db") +const { env: environment } = require("@budibase/backend-core") -exports.DEFAULT_COUCH = "http://budibase:budibase@localhost:10000/db/" -exports.DEFAULT_MINIO = "http://localhost:10000/" exports.TEMP_DIR = ".temp" exports.COUCH_DIR = "couchdb" exports.MINIO_DIR = "minio" const REQUIRED = [ { value: "MAIN_PORT", default: "10000" }, - { value: "COUCH_DB_URL", default: exports.DEFAULT_COUCH }, - { value: "MINIO_URL", default: exports.DEFAULT_MINIO }, + { + value: "COUCH_DB_URL", + default: "http://budibase:budibase@localhost:10000/db/", + }, + { value: "MINIO_URL", default: "http://localhost:10000" }, { value: "MINIO_ACCESS_KEY" }, { value: "MINIO_SECRET_KEY" }, ] @@ -27,7 +29,7 @@ exports.checkURLs = config => { ] = `http://${username}:${password}@localhost:${mainPort}/db/` } if (!config["MINIO_URL"]) { - config["MINIO_URL"] = exports.DEFAULT_MINIO + config["MINIO_URL"] = `http://localhost:${mainPort}/` } return config } @@ -65,6 +67,10 @@ exports.getConfig = async (envFile = true) => { } else { config = await exports.askQuestions() } + // fill out environment + for (let key of Object.keys(config)) { + environment._set(key, config[key]) + } return config }