Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix architect/architect#376 and close architect/architect#31 #112

Merged
merged 2 commits into from
Dec 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Architect Deploy changelog

---
## [1.3.0] 2019-12-14

### Added

- Adding `--name` for creating a unique stack name. (Aliased to `-n` and `name`.)
- Adding `--tags` for adding tags to the CloudFormation stack.


## [1.2.14] 2019-12-12

Expand Down
27 changes: 11 additions & 16 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,45 +3,40 @@ let deploy = require('.')
let {banner} = require('@architect/utils')
let create = require('@architect/create')
let validate = require('./src/validate')
let options = require('./src/options')
let {version} = require('./package.json')

/**
* `arc deploy`
*
* deploys the current .arc as a sam application to AppNameStaging stack
* deploys the current arcfile
*
* options
* -p|--production|production ... deploys to AppNameProduction
* -d|--dirty|dirty ............. *staging only* dirty deploy function code/config
* -s|--static|static ........... dirty deploys /public to s3 bucket
* -v|--verbose|verbose ......... prints all output to console
* -t|--tags|tags ............... add tags
* -n|--name|name ............... customize stack name
*/
let isDirty = opt=> opt === 'dirty' || opt === '--dirty' || opt === '-d'
let isStatic = opt=> opt === 'static' || opt === '--static' || opt === '-s'
let isProd = opt=> opt === 'production' || opt === '--production' || opt === '-p'
let isPrune = opt=> opt === 'prune' || opt === '--prune'
let isVerbose = opt=> opt === 'verbose' || opt === '--verbose' || opt === '-v'

async function cmd(opts=[]) {

// validate the call for expected env and args
validate(opts)

// create any missing local infra
await create({})

let args = {
prune: opts.some(isPrune),
verbose: opts.some(isVerbose),
production: opts.some(isProd)
}
// read args into {prune, verbose, production, tags, name, isFullDeploy}
let args = options(opts)

if (opts.some(isDirty))
if (args.isDirty)
return deploy.dirty()

if (opts.some(isStatic)) {
args.isFullDeploy = false
if (args.isStatic)
return deploy.static(args)
}

// deploy with SAM by default..
return deploy.sam(args)
}

Expand Down
49 changes: 49 additions & 0 deletions src/options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
let isDirty = opt=> opt === 'dirty' || opt === '--dirty' || opt === '-d'
let isStatic = opt=> opt === 'static' || opt === '--static' || opt === '-s'
let isProd = opt=> opt === 'production' || opt === '--production' || opt === '-p'
let isPrune = opt=> opt === 'prune' || opt === '--prune'
let isVerbose = opt=> opt === 'verbose' || opt === '--verbose' || opt === '-v'

let tags = arg=> arg === '--tags' || arg === '-t' || arg === 'tags'
let name = arg=> arg === '--name' || arg === '-n' || arg === 'name' || arg.startsWith('--name=')

module.exports = function options(opts) {
return {
prune: opts.some(isPrune),
verbose: opts.some(isVerbose),
production: opts.some(isProd),
tags: getTags(opts),
name: getName(opts),
isDirty: opts.some(isDirty),
isStatic: opts.some(isStatic),
isFullDeploy: opts.some(isStatic)? false : true
}
}

function getTags(list) {
let hasTags = process.argv.some(tags)
if (!hasTags)
return []
let len = list.length
let index = list.findIndex(tags) + 1
let left = list.slice(index, len)
return left.filter(arg=> /^[a-zA-Z0-9]+=[a-zA-Z0-9]+/.test(arg))
}

function getName(list) {
let hasName = process.argv.some(name)
if (!hasName)
return false

let len = list.length
let index = list.findIndex(name)
let left = list.slice(index, len)
let operator = left.shift()

if (operator.indexOf('=') === -1) {
return left.shift()
}
else {
return operator.split('=')[1]
}
}
9 changes: 5 additions & 4 deletions src/sam/01-deploy/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let spawn = require('../spawn')

module.exports = function deploy(params, callback) {
let {stackname, nested, appname, bucket, pretty, region, update} = params
let {stackname, nested, appname, bucket, pretty, region, update, tags} = params
update.done('Generated CloudFormation deployment')
update.start('Deploying & building infrastructure...')
let template = nested ? `${appname}-cfn.yaml` : 'sam.yaml'
Expand All @@ -13,8 +13,9 @@ module.exports = function deploy(params, callback) {
'--capabilities', 'CAPABILITY_IAM CAPABILITY_AUTO_EXPAND',
'--region', region
]
// if (nested) {
// args.push('CAPABILITY_AUTO_EXPAND')
//}
if (tags.length > 0) {
args.push('--tags')
args = args.concat(tags)
}
spawn('aws', args, pretty, callback)
}
17 changes: 14 additions & 3 deletions src/sam/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let after = require('./02-after')
* @param {Function} callback - a node-style errback
* @returns {Promise} - if not callback is supplied
*/
module.exports = function samDeploy({verbose, production}, callback) {
module.exports = function samDeploy({verbose, production, tags, name}, callback) {

let stage = production? 'production' : 'staging'
let ts = Date.now()
Expand All @@ -30,6 +30,9 @@ module.exports = function samDeploy({verbose, production}, callback) {
let stackname = `${utils.toLogicalID(appname)}${production? 'Production' : 'Staging'}`
let update = updater('Deploy')

if (name)
stackname += utils.toLogicalID(name)

// Assigned below
let cloudformation
let sam
Expand Down Expand Up @@ -118,8 +121,16 @@ module.exports = function samDeploy({verbose, production}, callback) {
* Deployment
*/
function theDeploy(callback) {
let params = {appname, stackname, nested, bucket, pretty, region, update}
deploy(params, callback)
deploy({
appname,
stackname,
nested,
bucket,
pretty,
region,
update,
tags,
}, callback)
},

/**
Expand Down