This can be achieved in Octopus by using a Community step template and the use of an Output variable
Community step templates are publicly available step templates that have been contributed by the Octopus Community.
There is already an existing step template available for this: Determine Rolling Deploy Window Size
When included in a project deployment process, this template will set a variable named:
#{Octopus.Action[Determine Rolling Deploy Window Size].Output.WindowSize}
to a fixed value.
This value is calculated as a percentage of the machines which have been tagged with the target roles in the parameter: Server Role for Rolling Deploy
Installing the Community Step template
Firstly, within Octopus, go to → Library → Step Templates → Browse Library
Then search for the template as shown here:
Hover over the Step template, and choose Install.
This will then prompt you to check you are sure you wish to install it.
Note: If you don’t want to install a community step template, or the feature has been disabled due to restrictions within your organization - there are a couple of alternatives:
- You can author your own step-template and add this to your Octopus instance and reference it within your project deployment process
- You could add a custom script to your project which sets an output variable for use in the rolling deployment step.
Adding the Step template to your Project
Go to your project and hit Add Step.
Then search for the step template as shown here and hit Add:
Setting the percentage value
Once the step has been added you can update the values in the step as you need to:
I’ve set the script to run on the Octopus Server
so that it only calculates the rolling window size once.
I’ve also set the Server percentage to deploy as: 50
.
I’ve also added the Server Role for Rolling Deploy to as: WindowSize-Web
.
Configuring the rolling deployment window size
So the Determine Rolling Deploy Window Size script will run as the first step in my deployment process and set the rolling deployment window size dynamically to 50%
Then in our rolling deployment step, we need to set the window size to the variable value of:
#{Octopus.Action[Determine Rolling Deploy Window Size].Output.WindowSize}
This is shown here:
Deploying with the percentage window
Finally, when we have created a release and deploy to an environment we can see in the Task output the percentage has been taken and a window size has been calculated, as shown here:
Here I have 2 machines tagged with the role WindowSize-Web
and as I have asked for at most 50% it is going to deploy with a window size
of 1
Sample project:
You can see an example of this in our samples instance (log in as Guest): Octopus Deploy
Summary
So from this, you can see we can set a rolling deployment window size based on a percentage in Octopus using a Community Step template.
A few things to consider when using this approach:
- It’s worth checking the default task cap (which is set to 5) doesn’t affect your rolling deployment window size, and changing if necessary.
- When dynamically scaling your infrastructure it’s possible to automate both the installation and removal of machines in Octopus. If you are using AWS Auto-Scaling Groups, please see this article for more information