|
|
|
@ -4,7 +4,6 @@ const { |
|
|
|
uploadAppAssets, |
|
|
|
verifyDeployment, |
|
|
|
updateDeploymentQuota, |
|
|
|
isInvalidationComplete, |
|
|
|
} = require("./aws") |
|
|
|
const { DocumentTypes, SEPARATOR, UNICODE_MAX } = require("../../../db/utils") |
|
|
|
const newid = require("../../../db/newid") |
|
|
|
@ -20,12 +19,10 @@ const DeploymentStatus = { |
|
|
|
} |
|
|
|
|
|
|
|
// checks that deployments are in a good state, any pending will be updated
|
|
|
|
async function checkAllDeployments(deployments, user) { |
|
|
|
async function checkAllDeployments(deployments) { |
|
|
|
let updated = false |
|
|
|
function update(deployment, status) { |
|
|
|
deployment.status = status |
|
|
|
delete deployment.invalidationId |
|
|
|
delete deployment.cfDistribution |
|
|
|
updated = true |
|
|
|
} |
|
|
|
|
|
|
|
@ -37,37 +34,6 @@ async function checkAllDeployments(deployments, user) { |
|
|
|
) { |
|
|
|
update(deployment, DeploymentStatus.FAILURE) |
|
|
|
} |
|
|
|
// if pending but not past failure point need to update them
|
|
|
|
else if (deployment.status === DeploymentStatus.PENDING) { |
|
|
|
let complete = false |
|
|
|
try { |
|
|
|
complete = await isInvalidationComplete( |
|
|
|
deployment.cfDistribution, |
|
|
|
deployment.invalidationId |
|
|
|
) |
|
|
|
} catch (err) { |
|
|
|
// system may have restarted, need to re-verify
|
|
|
|
if ( |
|
|
|
err !== undefined && |
|
|
|
err.code === "InvalidClientTokenId" && |
|
|
|
deployment.quota |
|
|
|
) { |
|
|
|
await verifyDeployment({ |
|
|
|
...user, |
|
|
|
quota: deployment.quota, |
|
|
|
}) |
|
|
|
complete = await isInvalidationComplete( |
|
|
|
deployment.cfDistribution, |
|
|
|
deployment.invalidationId |
|
|
|
) |
|
|
|
} else { |
|
|
|
throw err |
|
|
|
} |
|
|
|
} |
|
|
|
if (complete) { |
|
|
|
update(deployment, DeploymentStatus.SUCCESS) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return { updated, deployments } |
|
|
|
} |
|
|
|
@ -157,7 +123,7 @@ async function deployApp({ appId, deploymentId }) { |
|
|
|
|
|
|
|
console.log(`Uploading assets for appID ${appId} assets to s3..`) |
|
|
|
|
|
|
|
const invalidationId = await uploadAppAssets({ |
|
|
|
await uploadAppAssets({ |
|
|
|
appId, |
|
|
|
...verification, |
|
|
|
}) |
|
|
|
@ -174,10 +140,9 @@ async function deployApp({ appId, deploymentId }) { |
|
|
|
await storeLocalDeploymentHistory({ |
|
|
|
_id: deploymentId, |
|
|
|
appId, |
|
|
|
invalidationId, |
|
|
|
cfDistribution: verification.cfDistribution, |
|
|
|
quota: verification.quota, |
|
|
|
status: DeploymentStatus.PENDING, |
|
|
|
status: DeploymentStatus.SUCCESS, |
|
|
|
}) |
|
|
|
} catch (err) { |
|
|
|
await storeLocalDeploymentHistory({ |
|
|
|
@ -226,7 +191,7 @@ exports.deployApp = async function(ctx) { |
|
|
|
status: DeploymentStatus.PENDING, |
|
|
|
}) |
|
|
|
|
|
|
|
await deployApp({ |
|
|
|
deployApp({ |
|
|
|
...ctx.user, |
|
|
|
deploymentId: deployment._id, |
|
|
|
}) |
|
|
|
|