Octopus is an automated deployment tool for .net. It is feature rich working with your build server to create reliable releases that can be automated to deploy to your test environment all the way thru QA and Production. Octopus has a million options, features and ways to to do things. I think the documentation is a little light, there just aren’t any examples of how all the pieces fit together, its alot of “Lets see what happens when I do this”. In this series, I’ll take you down what I consider to be a pretty straightforward setup. Pretty basic environment really. Once you see how it looks end to end on this setup, you can then figure out what changes you might need to make to fit this into yours.
ok. Enough talking, lets doooooo eeeet.
First things first:
Download and Install Octopus server on your Application server or somewhere on your network. You can get it here: https://octopus.com/ . I am using the Community edition, it is free for small teams, even for commercial use. It allows you to deploy up to five projects to up to ten target machines, and is limited to five users. So far this has been enough to get started and unlocking the professional edition is as simple as adding your key.
I am working with an environment that consists of the following:
- Visual Studio 2015 Professional
- TFS 2015 Build Server
- Octopus Application Server (Using internal nuget repository)
- Sandbox- 1 Windows 2012 r2 web server
- Development – 1 Windows 2012 r2 web server
- QA – 1 Windows 2012 r2 web server
- Production – 8 Windows 2012 r2 web servers
OK, Lets Configure a Visual Studio Project for Octopus Deployment:
Here is a summary of steps required to configure a project to be uploaded to Octopus:
- Add OctoPack to Deployment Project with nuget
- Assembly Version Management
- TFS Check In
- Generate Octopus User API Key
- Configure TFS build Template MSBuild Arguments
- Build on TFS (auto upload to Octopus nuget repository)
- View Nuget Package on Octopus nuget repository server
1. Add OctoPack to Deployment Project with nuget
Octopack only needs to be added to the project to be deployed. You can think of this as the startup project within your solution.
- Add Octopak to the deployment project
- From Visual Studio (Example is using VS2015, vs 2013 looks slightly different): ->Tools/Nuget Package Manager/Manage Nuget Packages for solution
- From the Package manager, choose Browse at the top left and search for OctoPack
- Select OctoPack from the list, Installation options will appear to the right.
- OctoPack should only be installed on projects that you are going to deploy – that means the main ASP.NET web application/API project. Unit tests, class libraries, and other supporting projects wouldn’t be selected.In this case, we will select the OctoTest Web API project I created.
- Click Install
- You will be asked to preview your changes
- Click OK
The OctoPack Package installs, Check your Package Manager window for installation results.
2. Assembly Version Management
There are 2 different ways we can version, for simplicity’s sake, I will be using the auto generated date versioning available by changing the assembly version in AssemblyInfo.cs:
This will auto generate a version based on the date.
HOW IT WORKS:
The build numbers provide a relative identifier from the base of 12.31.1999. If you use a date calculator for the auto generated Assembly version of 1.0.6047.19483 you would start with its base of 12.31.1999 and add 6047. You’ll get July 22, 2015. The time is represented by the last set of digits 19483 and then divide by 1800. 19483/1800 = 10.823 or 10:49 am (this equates to military time when its pm) This will likely cover our needs, however there are other methods including manually incrementing the assembly version each build but this can easily be forgotten and OctoPack will not upload a nuget package with the same or lower assembly version.
3. TFS Check In
Check in OctoPack and your updated AssemblyInfo.cs file to TFS. I assume you can do this without pictures. If not, shoot me an email and venmo me like 10 bucks.
4. Generate Octopus User API Key
- Login to Octopus Server
- Top menu, Click Configuration
- Left Side menu, Click Users
- Create Publisher User
When creating the new publishing account, select the “The user is a service account” check box since this is just a service account.
- Click Create user and Select the new user on the user list screen.
- In the authentication section, click +New API Key
- Provide the purpose for the key and Generate a key
- Copy the key. there is no way to retrieve it so save it somewhere safe. (I deleted this one right away so don’t even)
5. Configure MSBuild
- Open your TFS build template for your project
- Build Defaults Tab
- Staging location – Since Octopack will create a nuget package and upload to the octopus internal nuget repository we do not need a build output)
- “Do not copy build out to server.”
- Process Tab
- Template: TfvcTEmplate.12.xaml
- 2 Get Version – Leave Blank
- 4 Output location – SingleFolder
- MSBuild Arguments (Enter these all one one line)
6. Build your project
- Build your project in TFS
- Im not sure why this one got its own bullet point.
7. View your nuget application package in Octopus
- login into Octopus Server to view the package
- Top Menu, Click Library
- OctoPack has generated a nuget package and uploaded it to the octopus nuget repository API
whats that? Your package wasnt uploaded to the repository? great. OK lets check some stuff.
- Check your tfs build logs first, make sure the project actually built. if it doesnt build, it wont upload obviously.
- Check the msBuild Arguments for OctoPack, OctoPackPublishPackageToHttp and OctoPackPublishApiKey
OK now you have it right?
Now that we have our application package in Octopus, we can set up our Octopus environment. In Part 2 of this series we will:
- Create Environments
- Install Tentacles on all target servers
- Add Deployment targets to Environments
- Create a Project
- Configure Settings
- Add Variables
- Configure Deployment Process
- Create Release