Making sure deployment object is used everywhere to hide all underlying deployment properties.
This commit is contained in:
parent
364eb3c433
commit
a381463c33
|
@ -1,13 +1,14 @@
|
||||||
const { getAppQuota } = require("./quota")
|
const { getAppQuota } = require("./quota")
|
||||||
const env = require("../../../environment")
|
const env = require("../../../environment")
|
||||||
|
const newid = require("../../../db/newid")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This is used to pass around information about the deployment that is occurring
|
* This is used to pass around information about the deployment that is occurring
|
||||||
*/
|
*/
|
||||||
class Deployment {
|
class Deployment {
|
||||||
constructor(id, appId) {
|
constructor(appId, id = null) {
|
||||||
this._id = id
|
|
||||||
this.appId = appId
|
this.appId = appId
|
||||||
|
this._id = id || newid()
|
||||||
}
|
}
|
||||||
|
|
||||||
// purely so that we can do quota stuff outside the main deployment context
|
// purely so that we can do quota stuff outside the main deployment context
|
||||||
|
@ -30,6 +31,9 @@ class Deployment {
|
||||||
}
|
}
|
||||||
|
|
||||||
setVerification(verification) {
|
setVerification(verification) {
|
||||||
|
if (this.verification.quota) {
|
||||||
|
this.quota = this.verification.quota
|
||||||
|
}
|
||||||
this.verification = verification
|
this.verification = verification
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +48,18 @@ class Deployment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fromJSON(json) {
|
||||||
|
if (json.verification) {
|
||||||
|
this.setVerification(json.verification)
|
||||||
|
}
|
||||||
|
if (json.quota) {
|
||||||
|
this.setQuota(json.quota)
|
||||||
|
}
|
||||||
|
if (json.status) {
|
||||||
|
this.setStatus(json.status, json.err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
getJSON() {
|
getJSON() {
|
||||||
const obj = {
|
const obj = {
|
||||||
_id: this._id,
|
_id: this._id,
|
||||||
|
@ -56,8 +72,8 @@ class Deployment {
|
||||||
if (this.verification && this.verification.cfDistribution) {
|
if (this.verification && this.verification.cfDistribution) {
|
||||||
obj.cfDistribution = this.verification.cfDistribution
|
obj.cfDistribution = this.verification.cfDistribution
|
||||||
}
|
}
|
||||||
if (this.verification && this.verification.quota) {
|
if (this.quota) {
|
||||||
obj.quota = this.verification.quota
|
obj.quota = this.quota
|
||||||
}
|
}
|
||||||
return obj
|
return obj
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const CouchDB = require("pouchdb")
|
const CouchDB = require("pouchdb")
|
||||||
const PouchDB = require("../../../db")
|
const PouchDB = require("../../../db")
|
||||||
const newid = require("../../../db/newid")
|
|
||||||
const env = require("../../../environment")
|
const env = require("../../../environment")
|
||||||
const deployment = env.SELF_HOSTED
|
const deployment = env.SELF_HOSTED
|
||||||
? require("./selfDeploy")
|
? require("./selfDeploy")
|
||||||
|
@ -69,7 +69,7 @@ async function storeLocalDeploymentHistory(deployment) {
|
||||||
deploymentDoc = { _id: "_local/deployments", history: {} }
|
deploymentDoc = { _id: "_local/deployments", history: {} }
|
||||||
}
|
}
|
||||||
|
|
||||||
const deploymentId = deploymentJSON._id || newid()
|
const deploymentId = deploymentJSON._id
|
||||||
|
|
||||||
// first time deployment
|
// first time deployment
|
||||||
if (!deploymentDoc.history[deploymentId])
|
if (!deploymentDoc.history[deploymentId])
|
||||||
|
@ -82,14 +82,12 @@ async function storeLocalDeploymentHistory(deployment) {
|
||||||
}
|
}
|
||||||
|
|
||||||
await db.put(deploymentDoc)
|
await db.put(deploymentDoc)
|
||||||
return {
|
deployment.fromJSON(deploymentDoc.history[deploymentId])
|
||||||
_id: deploymentId,
|
return deployment
|
||||||
...deploymentDoc.history[deploymentId],
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function deployApp({ appId, deploymentId }) {
|
async function deployApp(deployment) {
|
||||||
const deployment = new Deployment(deploymentId, appId)
|
const appId = deployment.getAppId()
|
||||||
try {
|
try {
|
||||||
await deployment.init()
|
await deployment.init()
|
||||||
deployment.setVerification(await preDeployment(deployment))
|
deployment.setVerification(await preDeployment(deployment))
|
||||||
|
@ -144,15 +142,11 @@ exports.deploymentProgress = async function(ctx) {
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.deployApp = async function(ctx) {
|
exports.deployApp = async function(ctx) {
|
||||||
const deployment = await storeLocalDeploymentHistory({
|
let deployment = new Deployment(ctx.user.appId)
|
||||||
appId: ctx.user.appId,
|
deployment.setStatus(DeploymentStatus.PENDING)
|
||||||
status: DeploymentStatus.PENDING,
|
deployment = await storeLocalDeploymentHistory(deployment)
|
||||||
})
|
|
||||||
|
|
||||||
await deployApp({
|
await deployApp(deployment)
|
||||||
...ctx.user,
|
|
||||||
deploymentId: deployment._id,
|
|
||||||
})
|
|
||||||
|
|
||||||
ctx.body = deployment
|
ctx.body = deployment
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue