Skip to content

Add feature to expose disabling of auto rollback and disabling of alarms #151

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ You can see a working example in the [example folder](./example/).
* `postTrafficHook`: (optional) validation Lambda function that runs after traffic shifting. It must use the CodeDeploy SDK to notify about this step's success or failure (more info [here](https://docs.aws.amazon.com/codedeploy/latest/userguide/reference-appspec-file-structure-hooks.html))
* `alarms`: (optional) list of CloudWatch alarms. If any of them is triggered during the deployment, the associated Lambda function will automatically roll back to the previous version.
* `triggerConfigurations`: (optional) list of CodeDeploy Triggers. See more details in the [CodeDeploy TriggerConfiguration Documentation](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-codedeploy-deploymentgroup-triggerconfig.html), or [this CodeDeploy notifications guide](https://docs.aws.amazon.com/codedeploy/latest/userguide/monitoring-sns-event-notifications-create-trigger.html) for example uses

* `disableRollback`: (optional) disables the rollback of the canary deployment if it fails. Defaults to false.
* `disableAlarms`: (optional) disables the alarms for the canary deployment. Defaults to false.
### Default configurations

You can set default values for all functions in a top-level custom deploymentSettings section. E.g.:
Expand Down
2 changes: 2 additions & 0 deletions example/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ functions:
deploymentSettings:
type: Linear10PercentEvery1Minute
alias: Live
disableAlarms: true
disableRollback: true
preTrafficHook: preHook
postTrafficHook: postHook
alarms:
Expand Down
5 changes: 3 additions & 2 deletions lib/CfTemplateGenerators/CodeDeploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function buildFnDeploymentGroup ({ codeDeployAppName, codeDeployGroupName, codeD
Ref: codeDeployAppName
},
AutoRollbackConfiguration: {
Enabled: true,
Enabled: !deploymentSettings.disableRollback,
Events: [
'DEPLOYMENT_FAILURE',
'DEPLOYMENT_STOP_ON_ALARM',
Expand Down Expand Up @@ -45,9 +45,10 @@ function buildFnDeploymentGroup ({ codeDeployAppName, codeDeployGroupName, codeD
const name = _.propOr({ Ref: a }, 'name', a)
return { Name: name }
})
console.log({ deploymentSettings })
const alarmConfig = {
Alarms: alarmNames,
Enabled: true
Enabled: !deploymentSettings.disableAlarms
}
Object.assign(deploymentGroup.Properties, { AlarmConfiguration: alarmConfig })
}
Expand Down
49 changes: 48 additions & 1 deletion lib/CfTemplateGenerators/CodeDeploy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const CodeDeploy = require('./CodeDeploy')

describe('CodeDeploy', () => {
describe('.buildApplication', () => {
it('generates a CodeDeploy::Application resouce', () => {
it('generates a CodeDeploy::Application resource', () => {
const expected = {
Type: 'AWS::CodeDeploy::Application',
Properties: { ComputePlatform: 'Lambda' }
Expand Down Expand Up @@ -85,6 +85,53 @@ describe('CodeDeploy', () => {
})
})

context('when disableAlarms is provided and true', () => {
it('should disable the alarm configuration', () => {
const deploymentSettings = {
type: 'Linear10PercentEvery1Minute',
alarms: ['Alarm1', { name: 'Alarm2' }],
disableAlarms: true
}
const expectedAlarms = {
Alarms: [{ Name: { Ref: 'Alarm1' } }, { Name: 'Alarm2' }],
Enabled: false
}
const expected = _.pipe(
_.set('Properties.ApplicationName', { Ref: codeDeployAppName }),
_.set('Properties.DeploymentGroupName', codeDeployGroupName),
_.set('Properties.AlarmConfiguration', expectedAlarms),
_.set('Properties.DeploymentConfigName.Fn::Sub[1].ConfigName', deploymentSettings.type)
)(baseDeploymentGroup)
const actual = CodeDeploy.buildFnDeploymentGroup({ codeDeployAppName, codeDeployGroupName, deploymentSettings })
console.log(actual)
expect(actual).to.deep.equal(expected)
})
})

context('when disableRollback is provided and true', () => {
it('should disable the automatic rollback configuration', () => {
const deploymentSettings = {
type: 'Linear10PercentEvery1Minute',
alarms: ['Alarm1', { name: 'Alarm2' }],
disableRollback: true
}
const expectedAlarms = {
Alarms: [{ Name: { Ref: 'Alarm1' } }, { Name: 'Alarm2' }],
Enabled: true
}
const expected = _.pipe(
_.set('Properties.ApplicationName', { Ref: codeDeployAppName }),
_.set('Properties.DeploymentGroupName', codeDeployGroupName),
_.set('Properties.AlarmConfiguration', expectedAlarms),
_.set('Properties.DeploymentConfigName.Fn::Sub[1].ConfigName', deploymentSettings.type),
_.set('Properties.AutoRollbackConfiguration.Enabled', false)
)(baseDeploymentGroup)
const actual = CodeDeploy.buildFnDeploymentGroup({ codeDeployAppName, codeDeployGroupName, deploymentSettings })
console.log(actual)
expect(actual).to.deep.equal(expected)
})
})

context('when a codeDeploy role is provided', () => {
it('should include the arn of the existing role instead of trying to lookup a generated role', () => {
const deploymentSettings = { type: 'Linear10PercentEvery1Minute' }
Expand Down