diff --git a/packages/server/src/api/controllers/deploy/aws.js b/packages/server/src/api/controllers/deploy/aws.js index b56d3c7788..f421e2f4fc 100644 --- a/packages/server/src/api/controllers/deploy/aws.js +++ b/packages/server/src/api/controllers/deploy/aws.js @@ -22,19 +22,20 @@ async function invalidateCDN(cfDistribution, appId) { } exports.updateDeploymentQuota = async function(quota) { - const response = await fetch( - `${process.env.DEPLOYMENT_CREDENTIALS_URL}/deploy/success`, - { - method: "POST", - body: JSON.stringify({ - apiKey: process.env.BUDIBASE_API_KEY, - quota, - }), - } - ) + const DEPLOYMENT_SUCCESS_URL = + process.env.DEPLOYMENT_CREDENTIALS_URL + "deploy/success" + + console.log(DEPLOYMENT_SUCCESS_URL) + const response = await fetch(DEPLOYMENT_SUCCESS_URL, { + method: "POST", + body: JSON.stringify({ + apiKey: process.env.BUDIBASE_API_KEY, + quota, + }), + }) if (response.status !== 200) { - throw new Error(`Error updating deployment quota for app`) + throw new Error(`Error updating deployment quota for API Key`) } const json = await response.json() @@ -163,30 +164,33 @@ exports.uploadAppAssets = async function({ // Upload file attachments const db = new PouchDB(instanceId) - const fileUploads = await db.get("_local/fileuploads") - if (fileUploads) { - for (let file of fileUploads.uploads) { - if (file.uploaded) continue - - const attachmentUpload = prepareUploadForS3({ - file, - s3Key: `assets/${appId}/attachments/${file.processedFileName}`, - s3, - metadata: { accountId }, - }) - - uploads.push(attachmentUpload) - - // mark file as uploaded - file.uploaded = true - } - - db.put(fileUploads) + let fileUploads + try { + fileUploads = await db.get("_local/fileuploads") + } catch (err) { + fileUploads = { _id: "_local/fileuploads", uploads: [] } } + for (let file of fileUploads.uploads) { + if (file.uploaded) continue + + const attachmentUpload = prepareUploadForS3({ + file, + s3Key: `assets/${appId}/attachments/${file.processedFileName}`, + s3, + metadata: { accountId }, + }) + + uploads.push(attachmentUpload) + + // mark file as uploaded + file.uploaded = true + } + + db.put(fileUploads) + try { await Promise.all(uploads) - // TODO: update dynamoDB with a synopsis of the app deployment for historical purposes await invalidateCDN(cfDistribution, appId) } catch (err) { console.error("Error uploading budibase app assets to s3", err) diff --git a/packages/server/src/api/controllers/deploy/index.js b/packages/server/src/api/controllers/deploy/index.js index 7f6e4588a5..2b433140fe 100644 --- a/packages/server/src/api/controllers/deploy/index.js +++ b/packages/server/src/api/controllers/deploy/index.js @@ -5,13 +5,10 @@ const { verifyDeployment, updateDeploymentQuota, } = require("./aws") -const { getRecordParams } = require("../../db/utils") function replicate(local, remote) { return new Promise((resolve, reject) => { - const replication = local.sync(remote, { - retry: true, - }) + const replication = local.sync(remote) replication.on("complete", () => resolve()) replication.on("error", err => reject(err)) @@ -40,11 +37,10 @@ async function replicateCouch({ instanceId, clientId, credentials }) { async function getCurrentInstanceQuota(instanceId) { const db = new PouchDB(instanceId) - const records = await db.allDocs( - getRecordParams("", null, { - include_docs: true, - }) - ) + const records = await db.allDocs({ + startkey: "record:", + endkey: `record:\ufff0`, + }) const existingRecords = records.rows.length const designDoc = await db.get("_design/database")