Some cleanup.
This commit is contained in:
parent
479b5870dd
commit
330f92ff7c
|
@ -1,80 +0,0 @@
|
||||||
const AWS = require("aws-sdk")
|
|
||||||
const fetch = require("node-fetch")
|
|
||||||
const env = require("../../../environment")
|
|
||||||
const {
|
|
||||||
deployToObjectStore,
|
|
||||||
performReplication,
|
|
||||||
fetchCredentials,
|
|
||||||
} = require("./utils")
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Verifies the users API key and
|
|
||||||
* Verifies that the deployment fits within the quota of the user
|
|
||||||
* Links to the "check-api-key" lambda.
|
|
||||||
* @param {object} deployment - information about the active deployment, including the appId and quota.
|
|
||||||
*/
|
|
||||||
exports.preDeployment = async function (deployment) {
|
|
||||||
const json = await fetchCredentials(env.DEPLOYMENT_CREDENTIALS_URL, {
|
|
||||||
apiKey: env.BUDIBASE_API_KEY,
|
|
||||||
appId: deployment.getAppId(),
|
|
||||||
quota: deployment.getQuota(),
|
|
||||||
})
|
|
||||||
|
|
||||||
// set credentials here, means any time we're verified we're ready to go
|
|
||||||
if (json.credentials) {
|
|
||||||
AWS.config.update({
|
|
||||||
accessKeyId: json.credentials.AccessKeyId,
|
|
||||||
secretAccessKey: json.credentials.SecretAccessKey,
|
|
||||||
sessionToken: json.credentials.SessionToken,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
return json
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Finalises the deployment, updating the quota for the user API key
|
|
||||||
* The verification process returns the levels to update to.
|
|
||||||
* Calls the "deployment-success" lambda.
|
|
||||||
* @param {object} deployment information about the active deployment, including the quota info.
|
|
||||||
* @returns {Promise<object>} The usage has been updated against the user API key.
|
|
||||||
*/
|
|
||||||
exports.postDeployment = async function (deployment) {
|
|
||||||
const DEPLOYMENT_SUCCESS_URL =
|
|
||||||
env.DEPLOYMENT_CREDENTIALS_URL + "deploy/success"
|
|
||||||
|
|
||||||
const response = await fetch(DEPLOYMENT_SUCCESS_URL, {
|
|
||||||
method: "POST",
|
|
||||||
body: JSON.stringify({
|
|
||||||
apiKey: env.BUDIBASE_API_KEY,
|
|
||||||
quota: deployment.getQuota(),
|
|
||||||
}),
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
Accept: "application/json",
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
if (response.status !== 200) {
|
|
||||||
throw new Error(`Error updating deployment quota for API Key`)
|
|
||||||
}
|
|
||||||
|
|
||||||
return await response.json()
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.deploy = async function (deployment) {
|
|
||||||
const appId = deployment.getAppId()
|
|
||||||
const { bucket, accountId } = deployment.getVerification()
|
|
||||||
const metadata = { accountId }
|
|
||||||
await deployToObjectStore(appId, bucket, metadata)
|
|
||||||
}
|
|
||||||
|
|
||||||
exports.replicateDb = async function (deployment) {
|
|
||||||
const appId = deployment.getAppId()
|
|
||||||
const verification = deployment.getVerification()
|
|
||||||
return performReplication(
|
|
||||||
appId,
|
|
||||||
verification.couchDbSession,
|
|
||||||
env.DEPLOYMENT_DB_URL
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -1,9 +1,6 @@
|
||||||
const PouchDB = require("../../../db")
|
const PouchDB = require("../../../db")
|
||||||
const Deployment = require("./Deployment")
|
const Deployment = require("./Deployment")
|
||||||
const {
|
const deploymentService = require("./selfDeploy")
|
||||||
getHostingInfo,
|
|
||||||
HostingTypes,
|
|
||||||
} = require("../../../utilities/builder/hosting")
|
|
||||||
// the max time we can wait for an invalidation to complete before considering it failed
|
// the max time we can wait for an invalidation to complete before considering it failed
|
||||||
const MAX_PENDING_TIME_MS = 30 * 60000
|
const MAX_PENDING_TIME_MS = 30 * 60000
|
||||||
const DeploymentStatus = {
|
const DeploymentStatus = {
|
||||||
|
@ -12,9 +9,6 @@ const DeploymentStatus = {
|
||||||
FAILURE: "FAILURE",
|
FAILURE: "FAILURE",
|
||||||
}
|
}
|
||||||
|
|
||||||
// default to AWS deployment, this will be updated before use (if required)
|
|
||||||
let deploymentService = require("./awsDeploy")
|
|
||||||
|
|
||||||
// checks that deployments are in a good state, any pending will be updated
|
// checks that deployments are in a good state, any pending will be updated
|
||||||
async function checkAllDeployments(deployments) {
|
async function checkAllDeployments(deployments) {
|
||||||
let updated = false
|
let updated = false
|
||||||
|
@ -122,12 +116,6 @@ exports.deploymentProgress = async function (ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.deployApp = async function (ctx) {
|
exports.deployApp = async function (ctx) {
|
||||||
// start by checking whether to deploy local or to cloud
|
|
||||||
const hostingInfo = await getHostingInfo()
|
|
||||||
deploymentService =
|
|
||||||
hostingInfo.type === HostingTypes.CLOUD
|
|
||||||
? require("./awsDeploy")
|
|
||||||
: require("./selfDeploy")
|
|
||||||
let deployment = new Deployment(ctx.appId)
|
let deployment = new Deployment(ctx.appId)
|
||||||
deployment.setStatus(DeploymentStatus.PENDING)
|
deployment.setStatus(DeploymentStatus.PENDING)
|
||||||
deployment = await storeLocalDeploymentHistory(deployment)
|
deployment = await storeLocalDeploymentHistory(deployment)
|
||||||
|
|
|
@ -95,10 +95,14 @@ exports.serveComponentLibrary = async function (ctx) {
|
||||||
if (env.isDev() || env.isTest()) {
|
if (env.isDev() || env.isTest()) {
|
||||||
const componentLibraryPath = join(
|
const componentLibraryPath = join(
|
||||||
budibaseTempDir(),
|
budibaseTempDir(),
|
||||||
decodeURI(ctx.query.library),
|
appId,
|
||||||
|
"node_modules",
|
||||||
|
"@budibase",
|
||||||
|
"standard-components",
|
||||||
|
"package",
|
||||||
"dist"
|
"dist"
|
||||||
)
|
)
|
||||||
return send(ctx, "/awsDeploy.js", { root: componentLibraryPath })
|
return send(ctx, "/index.js", { root: componentLibraryPath })
|
||||||
}
|
}
|
||||||
const db = new CouchDB(appId)
|
const db = new CouchDB(appId)
|
||||||
const appInfo = await db.get(appId)
|
const appInfo = await db.get(appId)
|
||||||
|
|
Loading…
Reference in New Issue