Octopus Deploy is an automated deployment server that makes it easy to automate deployment of ASP.NET web applications, Java applications, NodeJS application and custom scripts to multiple environments.
Azure DevOps will be handle the build/CI automation part of the process and will work with Octopus Deploy to handle deployment orchestration. The Octopus setup contains a central deployment server, along with “Tentacle” agents that run on any target VMs where deployment will take place.
Here, we will see how to use Octopus Deploy in conjunction with Azure DevOps to deploy in the cloud in a repeatable and reliable way.
Before you begin
- Refer the Getting Started before you begin to follow the below exercises.
Setting up the Environment
Octopus Deploy has two components:
- Octopus Server - a centralized web front-end that orchestrates deployments , and
- Tentacle - agent that needs to be on every target endpoint.
We will spin up an Octopus server on Azure. Click the Deploy to Azure button below to provision an Octopus Server.
It takes approximately 15 minutes for the deployment to complete. Once the deployment is successful, connect to Octopus server using DNS, and login with Octopus Admin username and password.
You will see the Octopus deploy web portal.
Generating Service Principal Names(SPN) details from Azure
We need to generate SPN details to get Tenant ID, Application ID and Application Password/Key which will be used in the later part of the lab.
Login to your Azure account and click on Cloud Shell.
Select Bash or Powershell to run the command which will generate the SPN details.
Create Storage account as Azure Cloud Shell requires an Azure file share to persist files, If you already have one select it or create new. Select the subscription and click on Create storage.
Once the storage account is provisioned, replace the variables within in brackets with values below and run the command to get the SPN details.
az ad sp create-for-rbac --name (provide a short name) --password (provide a password)
Note down the Tenant ID, Appliction ID and the Password in a notepad.
Setting up the Deployment Target
Since, the deployment target is an Azure WebApp, we need to create one.
Click the button below to provision an Azure WebApp.
Generate Octopus API Key
An API key is used to authenticate Azure DevOps with Octopus server. Using API key lets you keep your username and password a secret.
From the Octopus Deploy portal, select Profile under User menu.
Select My API Key and click New API Key to create one. We will use the API Key to connect Octopus Deploy with Azure DevOps
Specify a purpose, for instance, Azure DevOps Integration and click Generate New.
Copy the API Key to clipboard and save this to a notepad as you might use it for future requests.
Setting up the Azure DevOps team project
- Use Azure DevOps Demo Generator to provision the project on your Azure DevOps Organization.
Exercise 1: Configure Deployment Target in Octopus Server
Let us create a deployment environment in Octopus server and link to Azure using Management Certificate. Environments are deployment targets consisting of machines or services used by Octopus Deploy to deploy applications. With Octopus Deploy, we can deploy applications to Windows servers, Linux servers, Microsoft Azure, or even an offline package drop.
Grouping our deployment targets by environment lets you define your deployment processes and have Octopus deploy the right versions of our software to the right environments at the right time.
In this lab, we are using Azure App Service as the deployment target.
On the Octopus portal dashboard, select Create environments to go into the Infrastructure page.
Once inside, click Add Environment.
Provide the environment name and click Save.
Octopus Deploy provides first-class support for deploying Azure Cloud Services and Azure Web Applications. To deploy software to Azure, we must add our Azure subscription to Octopus Deploy, and then use the built-in step templates to deploy to the cloud. Once the environment is created, click on Accounts select Azure Subscription from ADD ACCOUNT dropdown.
Octopus Deploy authenticates with Azure with one of the two methods:
To deploy to Azure Resource Manager (ARM), Octopus requires Azure Service Principal Account.
To deploy to Cloud Services and Azure Web Apps, Octopus requires Azure Management Certificate.
Enter the following details -
- Name: Provide an account name
- Subscription ID: Your Azure Subscription ID
- Authentication Method: Choose Use a Service Principal
- Tenant ID, Application ID, Application Password/Key: Created earlier in the lab
Click SAVE AND TEST and notice that your account is verified.
To add the deployment target, go to Deployment Targets, click on ADD DEPLOYMENT TARGET, select Azure Web App and click NEXT.
In Create deployment target page, provide Display Name, choose Environment from the dropdown, add Target Roles(Tags), select the Account which was created earlier and select Azure Web App from the dropdown as shown below and click Save..
Exercise 2: Create Project in Octopus
Let us create a Project in Octopus to deploy the package to Azure App Service. A Project is a collection of deployment steps and configuration variables that define how your software is deployed.
Go to the Octopus dashboard and click on Create a project.
Click on ADD PROJECT, provide the project name, description and click on SAVE.
Once the project is created, click Define your deployment process. The deployment process is like a recipe for deploying your software.
Click on ADD STEP to see a list of built-in step templates, custom step templates, and community contributed step templates.
Search for Azure Web App template and click Add.
Populate the step template with required details -
- Step Name : A short, unique name for the template.
- On Behalf Of : Choose the target role from the drop down that was created in previous exercise step 8.
- Package ID : Type-in as Asp.netcore (if you are providing different package ID, update it in Package Application task of the build definition)
Click Save to complete the project creation and its deployment process.
Exercise 3: Triggering CI-CD
In this exercise, we will package the ASP.NET Core application and push the package to Octopus Server. We will use build tasks of Octopus Deploy Integration extension which was installed during Team Project provisioning.
|Restore||dotnet command-line tool restores all the package dependencies like ASP.NET Core Identity, ASP.NET Core session etc. required to build this project|
|Build||We will use dotnet command-line tool to build the project and its dependencies into a set of binaries|
|Publish||We will use this task to create a package with published content for the web deployment|
|Package Application||We will package the ASP.NET Core build output into a zip file with the version number|
|Push packages to Octopus||The copied package will be pushed to Octopus server from the artifacts directory|
|Create Octopus Release||Automates the creation of release in Octopus server. A release captures all the project and package details to be deployed over and over in a safe and repeatable way|
|Deploy Octopus Release||Automates the deployment of release in Octopus server. A deployment is the execution of the steps to deploy a release to an environment. An individual release can be deployed numerous times to different environments|
Go to Builds under Pipelines tab, select Octopus build definition and click on Edit.
In Push Packages to Octopus task, update Octopus Deploy Server field with the created endpoint value.
In Create Octopus Release task, update Octopus Deploy Server field with the created endpoint value and choose the created Project from drop down.
In Deploy Octopus Release task, update Octopus Deploy Server field with the created endpoint value, choose the appropriate values from the drop down for fields - Project and Deploy to Environments and Save & Queue the build definition.
Navigate back to the Build tab see progress of the build.
Once the build completes, go to Octopus portal project dashboard to see the release progress.
Go to the created Azure Web App from your Azure Portal and click Browse.
You will see the associated ASP.NET Core application up and running.
The lab demonstrates how Azure Pipelines pick up a code commit, build the changes and push the deployment to Octopus which deploys to an Azure Web App.