Skip to content

Commit

Permalink
Upload large template files to s3 (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
gpoitch authored Mar 30, 2020
1 parent c7f875f commit ba3930c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
12 changes: 9 additions & 3 deletions src/commands/deploy.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
const { join } = require('path')
const { statSync } = require('fs')
const validate = require('./validate')
const packageProject = require('./package')
const log = require('../log')
const { spawnAsync, deleteFileAsync } = require('../utils')

async function deployStack(templatePathPackaged, stackName, capabilities, parameters) {
async function deployStack(templatePathPackaged, stackName, bucketName, capabilities, parameters) {
const parametersFlag = parameters && parameters.length && parameters.join(' ')
const templateStats = statSync(join(process.cwd(), templatePathPackaged))
const command =
`aws cloudformation deploy ` +
`--template-file ${templatePathPackaged} ` +
`--stack-name ${stackName} ` +
`--capabilities ${capabilities || 'CAPABILITY_IAM'} ` +
`${templateStats.size > 51200 ? '--s3-bucket ' + bucketName : ''} ` +
`${parametersFlag ? '--parameter-overrides ' + parametersFlag : ''}`
log.info(`Deploying stack "${stackName}"...`).command(command)
return spawnAsync(command)
Expand All @@ -31,10 +35,12 @@ async function cleanPackagedTemplates(paths) {

module.exports = async function deploy(input) {
await validate(input)
const { templatePathEnvMerged, templatePathPackaged, environment, stackName } = await packageProject(input)
const { templatePathEnvMerged, templatePathPackaged, environment, stackName, bucketName } = await packageProject(
input
)
const deployParams = [].concat(input.parameters || [], `environment=${environment}`)
try {
await deployStack(templatePathPackaged, stackName, input.capabilities, deployParams)
await deployStack(templatePathPackaged, stackName, bucketName, input.capabilities, deployParams)
} finally {
await cleanPackagedTemplates([templatePathPackaged, templatePathEnvMerged])
}
Expand Down
2 changes: 1 addition & 1 deletion src/commands/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ module.exports = async function packageProject(input) {
log.info('Packaging and uploading code...').command(command)
await spawnAsync(command)
log.success('Code packaged & uploaded')
return { templatePathEnvMerged, templatePathPackaged, environment, stackName }
return { templatePathEnvMerged, templatePathPackaged, environment, stackName, bucketName }
}

0 comments on commit ba3930c

Please sign in to comment.