tidy up
This commit is contained in:
parent
ee73c7f418
commit
3994816c69
|
@ -22,19 +22,20 @@ async function invalidateCDN(cfDistribution, appId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.updateDeploymentQuota = async function(quota) {
|
exports.updateDeploymentQuota = async function(quota) {
|
||||||
const response = await fetch(
|
const DEPLOYMENT_SUCCESS_URL =
|
||||||
`${process.env.DEPLOYMENT_CREDENTIALS_URL}/deploy/success`,
|
process.env.DEPLOYMENT_CREDENTIALS_URL + "deploy/success"
|
||||||
{
|
|
||||||
|
console.log(DEPLOYMENT_SUCCESS_URL)
|
||||||
|
const response = await fetch(DEPLOYMENT_SUCCESS_URL, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
apiKey: process.env.BUDIBASE_API_KEY,
|
apiKey: process.env.BUDIBASE_API_KEY,
|
||||||
quota,
|
quota,
|
||||||
}),
|
}),
|
||||||
}
|
})
|
||||||
)
|
|
||||||
|
|
||||||
if (response.status !== 200) {
|
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()
|
const json = await response.json()
|
||||||
|
@ -163,8 +164,13 @@ exports.uploadAppAssets = async function({
|
||||||
|
|
||||||
// Upload file attachments
|
// Upload file attachments
|
||||||
const db = new PouchDB(instanceId)
|
const db = new PouchDB(instanceId)
|
||||||
const fileUploads = await db.get("_local/fileuploads")
|
let fileUploads
|
||||||
if (fileUploads) {
|
try {
|
||||||
|
fileUploads = await db.get("_local/fileuploads")
|
||||||
|
} catch (err) {
|
||||||
|
fileUploads = { _id: "_local/fileuploads", uploads: [] }
|
||||||
|
}
|
||||||
|
|
||||||
for (let file of fileUploads.uploads) {
|
for (let file of fileUploads.uploads) {
|
||||||
if (file.uploaded) continue
|
if (file.uploaded) continue
|
||||||
|
|
||||||
|
@ -182,11 +188,9 @@ exports.uploadAppAssets = async function({
|
||||||
}
|
}
|
||||||
|
|
||||||
db.put(fileUploads)
|
db.put(fileUploads)
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Promise.all(uploads)
|
await Promise.all(uploads)
|
||||||
// TODO: update dynamoDB with a synopsis of the app deployment for historical purposes
|
|
||||||
await invalidateCDN(cfDistribution, appId)
|
await invalidateCDN(cfDistribution, appId)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error uploading budibase app assets to s3", err)
|
console.error("Error uploading budibase app assets to s3", err)
|
||||||
|
|
|
@ -5,13 +5,10 @@ const {
|
||||||
verifyDeployment,
|
verifyDeployment,
|
||||||
updateDeploymentQuota,
|
updateDeploymentQuota,
|
||||||
} = require("./aws")
|
} = require("./aws")
|
||||||
const { getRecordParams } = require("../../db/utils")
|
|
||||||
|
|
||||||
function replicate(local, remote) {
|
function replicate(local, remote) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const replication = local.sync(remote, {
|
const replication = local.sync(remote)
|
||||||
retry: true,
|
|
||||||
})
|
|
||||||
|
|
||||||
replication.on("complete", () => resolve())
|
replication.on("complete", () => resolve())
|
||||||
replication.on("error", err => reject(err))
|
replication.on("error", err => reject(err))
|
||||||
|
@ -40,11 +37,10 @@ async function replicateCouch({ instanceId, clientId, credentials }) {
|
||||||
|
|
||||||
async function getCurrentInstanceQuota(instanceId) {
|
async function getCurrentInstanceQuota(instanceId) {
|
||||||
const db = new PouchDB(instanceId)
|
const db = new PouchDB(instanceId)
|
||||||
const records = await db.allDocs(
|
const records = await db.allDocs({
|
||||||
getRecordParams("", null, {
|
startkey: "record:",
|
||||||
include_docs: true,
|
endkey: `record:\ufff0`,
|
||||||
})
|
})
|
||||||
)
|
|
||||||
const existingRecords = records.rows.length
|
const existingRecords = records.rows.length
|
||||||
|
|
||||||
const designDoc = await db.get("_design/database")
|
const designDoc = await db.get("_design/database")
|
||||||
|
|
Loading…
Reference in New Issue