Last updated : Aug 26,2019

Overview

Last updated : Aug 26, 2019.

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.

Visual Studio Team Services includes a first-class, powerful release management capability that simplifies deployment of any application to any platform. But teams who prefer or already have chosen Octopus deploy, can use the Octopus Deploy Integration extension available on the Visual Studio Marketplace that provides Build and Release tasks to integrate Octopus Deploy with Team Services and Team Foundation Server.

This lab shows how we can integrate VSTS/TFS Team Build and Octopus to automate build and deployment application using a sample PHP application that will be deployed to an Azure App Service.

Prerequisites for the lab

  1. Microsoft Azure Account: You will need a valid and active Azure account for the Azure labs. If you do not have one, you can sign up for a free trial

    • If you are an active Visual Studio Subscriber, you are entitled for a $50-$150 credit per month. You can refer to this link to find out more information about this including how to activate and start using your monthly Azure credit.

    • If you are not a Visual Studio Subscriber, you can sign up for the FREE Visual Studio Dev Essentials program to create a Azure free account (includes 1 year of free services, $200 for 1st month).

  2. You will need a Visual Studio Team Services Account. If you do not have one, you can sign up for free here

  3. You will need a Personal Access Token to set up your project using the VSTS Demo Generator. Please see this article for instructions to create your token.

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 a Octopus server on Azure. Click the Deploy to Azure button below to provision a Octopus Server.

Octopus Configuration

  1. Click on Create button.

    click_create

  2. Provide Resource group name and click OK. create_RG

  3. Provide Octopus server Domain Name, VM Admin username and password, and SQL admin username and password. Note down the Domain Name (DNS) as this is used later to connect to Octopus server.

    server_details

  4. Provide Octopus Admin username and password. This is used to login to Octopus server. Also provide your name, organization name and email address to activate trial license for octopus server. Click OK.

    octopus_details

  5. Click OK in the Summary section.

    summary

  6. Click Create in the Buy section.

    click_create2

  7. 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.

    Octopus_login

  8. You will see the Octopus deploy web portal.

    Octopus Dashboard

Setting up the Deployment Target

In this lab, we will use Azure WebApp as the deployment target.

Click the Deploy to Azure button below to provision Azure WebApp.

WebApp Configuration

  1. Provide Web App name and Resource Group. You can either create new Resource group or use existing one, and click Create

    webapp

Generate Octopus API Key

API key is used to authenticate VSTS with Octopus server. Using API key lets you keep your username and password secret.

  1. From the Octopus Deploy portal, select Profile under User menu.

    User Profile

  2. Select My API Key and click New API Key to create one. We will use the API Key to connect Octopus Deploy with Team Services

    Request New API Key

  3. Specify a purpose, for e.g., VSTS Integration and click Generate New.

    Generate New API Key

  4. Copy the API Key to clipboard and save this somewhere as you may use it for future requests.

    Generated API Key

Setting up the VSTS team project

  1. Use the VSTS Demo Generator to provision the project on our VSTS account.

    VSTS Demo Generator helps you create team projects on your VSTS account with sample content that include source code, work items,iterations, service endpoints, build and release definitions based on the template you choose during the configuration.

    VSTS Demo Generator

  2. Provide a name for your project. Paste, the Octopus URL (VM’s DNS URL) that was created previously, API Key and click on Create Project.

  3. Once the project is provisioned, click the URL to navigate to the project.

    VSTS Demo Generator

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 software. With Octopus Deploy, we can deploy software 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.

  1. From the Octopus portal, select Create environments to go into the Infrastructure page

    CreateEnvironment

  2. Once inside, click Add Environment.

    AddEnvironment

  3. Provide the environment name and click Save.

    DevEnvironment

  4. 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 Accounts

  5. Select ADD ACCOUNT.

    Add Account

  6. Octopus Deploy authenticates with Azure in one of two methods:

    Enter the following details -

    • Name: Provide an account name
    • Subscription ID: Your Azure Subscription ID
    • Authentication Method: Choose Use Management Certificate

    Create Account

  7. Click Save and notice that a management certificate is generated. Download this certificate.

    Download Certificate

  8. To upload the certificate in Azure, go to Azure Portal and search for Subscriptions.

    O8

  9. Click on the Subscription.

    O9

  10. Scroll down and click Management certificates.

    O10

  11. Click Upload to upload the certificate which was downloaded in the step 7.

    O11

    O12

  12. Once the certificate is uploaded successfully, go back to Octopus portal and click Save and Test. If the test succeeds, we should be able to configure Octopus to deploy application packages to Azure.

    VerificationSuccess

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.

  1. Go to Octopus dashboard and click Create a project.

    Project

  2. Click on ADD PROJECT, provide the project name, description and click on SAVE.

    AddProject

    PUProject

  3. Once the project is created, click Define your deployment process. The deployment process is like a recipe for deploying your software.

    DefineProcess

  4. Click on ADD STEP to see a list of built-in step templates, custom step templates, and community contributed step templates.

    AddStep

  5. Search for Azure Web App template and click Add.

    AddWebAppStep

  6. Populate the step template with required details -

    • Step Name : A short, unique name for the template.
    • Package ID : PHP (if you are providing different package ID, update it in Package PHP task of the build definition)
    • Azure account & Web App : Select from the dropdown

    PkgID

    Azure

  7. Clicking Save should define the project creation and its deployment process.

Exercise 3: Triggering CI-CD

In this exercise, we will package PHP 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.

Tasks Usage
octopuspackage Package Application We will package the PHP source code into a zip file with the version number
copyfiles Copy Files The Copy Files task will copy the generated package to artifacts directory in VSTS
pushpackage Push packages to Octopus The copied package will be pushed to Octopus server from VSTS artifacts directory
createoctopus 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
releaseoctopus 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
  1. Go to Builds under Build and Release tab and click on Octopus build definition.

    BuildDefinition

  2. Edit the build definition to update Octopus server endpoint.

    EditBD

  3. In Push Packages to Octopus task, update Octopus Deploy Server field with the created endpoint value.

    QBuild

  4. In Create Octopus Release task, update Octopus Deploy Server field with the created endpoint value and Project fields.

    Update1

  5. 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.

    Update

  6. Save the build definition.

    Save

  7. Go to Code tab and edit the file functions.php

    EditFile

  8. Update the line 41 as shown, change the title to - PHP DevOps Using VSTS, Octopus and Azure and commit the changes.

    EditCommit

  9. Go to Build tab, you will see in-progress build.

    BuildProgress

  10. Once the build completes, go to Octopus portal project dashboard. We will see the release completion in Octopus.

    CD-Octopus

  11. Go to Azure Web App from your Azure Portal and click on Browse.

    Browse

  12. You will see the PHP application up and running.

    Changes