2021-03-24 21:11:14 +00:00
|
|
|
const dayjs = require('dayjs')
|
|
|
|
|
|
|
|
|
|
const { cleanupTmp } = require('../common')
|
|
|
|
|
|
|
|
|
|
const { saveAppLog } = require('../logging')
|
|
|
|
|
const copyFiles = require('./deploy/copyFiles')
|
|
|
|
|
const buildContainer = require('./build/container')
|
|
|
|
|
const deploy = require('./deploy/deploy')
|
|
|
|
|
const Deployment = require('../../models/Deployment')
|
2021-04-19 07:46:05 +00:00
|
|
|
const { purgeImagesContainers } = require('./cleanup')
|
2021-03-24 21:11:14 +00:00
|
|
|
const { updateServiceLabels } = require('./configuration')
|
|
|
|
|
|
2021-04-15 20:40:44 +00:00
|
|
|
async function queueAndBuild (configuration, imageChanged) {
|
2021-03-24 21:11:14 +00:00
|
|
|
const { id, organization, name, branch } = configuration.repository
|
|
|
|
|
const { domain } = configuration.publish
|
|
|
|
|
const { deployId, nickname, workdir } = configuration.general
|
2021-04-19 07:46:05 +00:00
|
|
|
await new Deployment({
|
|
|
|
|
repoId: id, branch, deployId, domain, organization, name, nickname
|
|
|
|
|
}).save()
|
|
|
|
|
await saveAppLog(`${dayjs().format('YYYY-MM-DD HH:mm:ss.SSS')} Queued.`, configuration)
|
|
|
|
|
await copyFiles(configuration)
|
|
|
|
|
await buildContainer(configuration)
|
|
|
|
|
await deploy(configuration, imageChanged)
|
|
|
|
|
await Deployment.findOneAndUpdate(
|
|
|
|
|
{ repoId: id, branch, deployId, organization, name, domain },
|
|
|
|
|
{ repoId: id, branch, deployId, organization, name, domain, progress: 'done' })
|
|
|
|
|
await updateServiceLabels(configuration)
|
|
|
|
|
cleanupTmp(workdir)
|
|
|
|
|
await purgeImagesContainers()
|
2021-03-24 21:11:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
module.exports = { queueAndBuild }
|