Some changes after testing, needed to update object store client creation.

This commit is contained in:
mike12345567 2021-03-24 12:54:59 +00:00
parent 9708957646
commit 9c0a4ab4fb
4 changed files with 30 additions and 22 deletions

View File

@ -15,6 +15,8 @@ services:
COUCH_DB_URL: http://${COUCH_DB_USER}:${COUCH_DB_PASSWORD}@couchdb-service:5984 COUCH_DB_URL: http://${COUCH_DB_USER}:${COUCH_DB_PASSWORD}@couchdb-service:5984
WORKER_URL: http://worker-service:4003 WORKER_URL: http://worker-service:4003
MINIO_URL: http://minio-service:9000 MINIO_URL: http://minio-service:9000
MINIO_ACCESS_KEY: ${MINIO_ACCESS_KEY}
MINIO_SECRET_KEY: ${MINIO_SECRET_KEY}
HOSTING_KEY: ${HOSTING_KEY} HOSTING_KEY: ${HOSTING_KEY}
BUDIBASE_ENVIRONMENT: ${BUDIBASE_ENVIRONMENT} BUDIBASE_ENVIRONMENT: ${BUDIBASE_ENVIRONMENT}
PORT: 4002 PORT: 4002

View File

@ -68,8 +68,6 @@ for (let route of mainRoutes) {
router.use(staticRoutes.routes()) router.use(staticRoutes.routes())
router.use(staticRoutes.allowedMethods()) router.use(staticRoutes.allowedMethods())
if (!env.SELF_HOSTED && !env.CLOUD) { router.redirect("/", "/_builder")
router.redirect("/", "/_builder")
}
module.exports = router module.exports = router

View File

@ -25,6 +25,8 @@ module.exports = {
SELF_HOSTED: process.env.SELF_HOSTED, SELF_HOSTED: process.env.SELF_HOSTED,
AWS_REGION: process.env.AWS_REGION, AWS_REGION: process.env.AWS_REGION,
ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS, ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS,
MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
// environment // environment
NODE_ENV: process.env.NODE_ENV, NODE_ENV: process.env.NODE_ENV,
JEST_WORKER_ID: process.env.JEST_WORKER_ID, JEST_WORKER_ID: process.env.JEST_WORKER_ID,

View File

@ -6,7 +6,6 @@ const tar = require("tar-fs")
const zlib = require("zlib") const zlib = require("zlib")
const { promisify } = require("util") const { promisify } = require("util")
const { join } = require("path") const { join } = require("path")
const { streamUpload } = require("./utilities")
const fs = require("fs") const fs = require("fs")
const { budibaseTempDir } = require("../budibaseDir") const { budibaseTempDir } = require("../budibaseDir")
const env = require("../../environment") const env = require("../../environment")
@ -50,8 +49,12 @@ const PUBLIC_BUCKETS = [ObjectStoreBuckets.APPS]
* @constructor * @constructor
*/ */
exports.ObjectStore = bucket => { exports.ObjectStore = bucket => {
AWS.config.update({
accessKeyId: env.MINIO_ACCESS_KEY,
secretAccessKey: env.MINIO_SECRET_KEY,
})
const config = { const config = {
s3ForcePathStyle: true, // needed with minio? s3ForcePathStyle: true,
signatureVersion: "v4", signatureVersion: "v4",
params: { params: {
Bucket: bucket, Bucket: bucket,
@ -161,8 +164,10 @@ exports.deleteFolder = async (bucket, folder) => {
Prefix: folder, Prefix: folder,
} }
const data = await client.listObjects(listParams).promise() let response = await client.listObjects(listParams).promise()
if (data.Contents.length > 0) { if (response.Contents.length === 0) {
return
}
const deleteParams = { const deleteParams = {
Bucket: bucket, Bucket: bucket,
Delete: { Delete: {
@ -170,16 +175,15 @@ exports.deleteFolder = async (bucket, folder) => {
}, },
} }
data.Contents.forEach(content => { response.Contents.forEach(content => {
deleteParams.Delete.Objects.push({ Key: content.Key }) deleteParams.Delete.Objects.push({ Key: content.Key })
}) })
const data = await client.deleteObjects(deleteParams).promise() response = await client.deleteObjects(deleteParams).promise()
// can only empty 1000 items at once // can only empty 1000 items at once
if (data.Contents.length === 1000) { if (response.Deleted.length === 1000) {
return exports.deleteFolder(bucket, folder) return exports.deleteFolder(bucket, folder)
} }
}
} }
exports.uploadDirectory = async (bucket, localPath, bucketPath) => { exports.uploadDirectory = async (bucket, localPath, bucketPath) => {
@ -191,7 +195,9 @@ exports.uploadDirectory = async (bucket, localPath, bucketPath) => {
if (file.isDirectory()) { if (file.isDirectory()) {
uploads.push(exports.uploadDirectory(bucket, local, path)) uploads.push(exports.uploadDirectory(bucket, local, path))
} else { } else {
uploads.push(streamUpload(bucket, path, fs.createReadStream(local))) uploads.push(
exports.streamUpload(bucket, path, fs.createReadStream(local))
)
} }
} }
await Promise.all(uploads) await Promise.all(uploads)