In order to gracefully deploy releases to our application servers, I wanted to utilize rolling deployments in Octopus Deploy. If you aren’t familiar, rolling deployments slowly roll out a release one instance at a time (vs. all instances at once). The goal of this being reduced overall downtime. To accomplish this, I wrote PowerShell scripts to leverage AWS Auto Scaling Groups (ASG) that are run as part of Octopus deployments.
The deploy process is setup in the following order for each role that use ASG’s (Web servers, enterprise service bus, CMS, etc.):
1. Octopus picks first instance to run on
2. Instance is placed in standby mode, removing it from the load balancer (EnterStandby.ps1)
3. Normal deploy activities run
4. Instance exits standby mode, placing it back in service (ExitStandby.ps1)
Octopus then moves on to next instance…
The deploy steps that are run for a role are grouped. There is a parent step that has the rolling deployment setting, with child steps to perform the deploy activities.
Example parent step:
The first script (EnterStandby.ps1) gets the instance id, gets the ASG name using it’s instance ID, sets an Octopus output variable with the ASG name (that’s referenced in ExitStandby.ps1), then places the instance in standby mode (if it isn’t already).
The second script (ExitStandby.ps1) gets the instance id, gets the ASG name using the Octopus output variable above, exits standby mode using instance ID and ASG Name, then waits until the instance’s state is InService.