When you create an app on your computer, this is when everything seems to work perfectly. When ready, you will move an app to a staging environment for testing, and then finally move it to production. The process for doing all this can be time-consuming and fraught with errors. Now, major cloud players are working to make that process as streamlined as possible and I will walk you through the entire process.
What is CICD?
CICD stands for continuous integration & continuous delivery (also referred to as continuous deployment). With CI, you are regularly merging code changes to ensure those changes work (or integrate) with the existing codebase and allow you to perform testing. With CD, you are repeatedly pushing code through a deployment pipeline where it is built, tested, and then deployed. With CD, you may deploy your code to a staging (test, dev) environment or you might automatically publish your code to production.
Who supports CICD?
This approach of your code moving through an automated pipeline, compiling, and releasing code is not new, but cloud-based solutions like Microsoft’s Azure and Amazon’s AWS are adopting CICD into the development workflow. While CICD as a term and a technology has been around for some time, the ability to effortlessly move your code from a computer to a master repository and then to staging or production in the cloud is still very new. You will find all sorts of capabilities labeled beta or preview throughout most cloud solutions today.
Git and CICD
The one thing all the CICD tools have in common is they prefer your project uses a Git repository. You can host that repository internally, but the more common approach is to host your solution on GitHub. Microsoft offers the popular Visual Studio Team Services that allow you to create Git repositories and quickly set up CICD within Azure.
Set up the environment
For this article and attached video, you will use the following tools:
- Visual Studio 2017 (2015 works, but I believe you may need to download a Visual Studio Team Services Git solution before you can get started).
- Visual Studio Team Services (I use the free level).
- Azure (I use Dev Essentials to make use of free credits).
Azure CICD workflow
As you can see in the image below, you will create and update the app on a local computer with a local Git repository. When ready, you will commit the code to the master repository that, in this case, happens to be Visual Studio Team Services (VSTS). Finally, you will set up Azure to look for changes to that repository. Once Azure sees there is new code, it will download, compile, and run the new solution.
When integrating VSTS with Azure, you have a few options. Of course, one option is you can create your integration using PowerShell, Bash, or some other custom code. The second is to allow VSTS to push your code up to Azure. The third and final option is to have Azure wait for changes to your repository and take action when necessary. Personally, I like the third option because you may have one person managing your organization’s cloud services and another maintaining the Git repository. Also, Microsoft’s current documentation seems to point to the best method of using the Azure cloud to do the integration, but I am not sure if it is a preference thing or part of their future direction.
Create the initial project
Automated CICD is not available for all solution types, but it certainly is available for web apps. In the associated video, I walk you through the process of creating the project, which includes the following steps:
- Create a new Asp.Net web application (MVC).
- Add the application to a local Git repository.
If you are interested in learning more about Git, check out my article here.
Set up VSTS
Once your project is in place, you will use Visual Studio to upload your project to VSTS by following these steps:
- Publish the repository to VSTS.
- Verify the project is available on your VSTS site.
Note: If you do not have a VSTS account, you can get a free site here.
Set up Azure
As mentioned earlier in this article, you can configure VSTS to push your code to Azure, or you can have Azure take over after VSTS receives an update. In my case, I prefer to configure CICD within Azure. Here are the steps to follow:
- Create a new web app within Azure and name it (the name can be different than the project in VSTS).
- Configure continuous deployment.
- Wait for integration to complete (first move of your files from VSTS to Azure).
- Restart your app (may be required).
- Test your app after the first synchronization.
The first time you run this process, there is a manual setup process in Azure where you configure the web app and connect it to your VSTS account. With that complete, you can test the solution end to end:
- Update your local code in Visual Studio.
- Commit your changes in Visual Studio and sync them to VSTS (your workflow may vary).
- Update the master branch for your code (or whatever branch you selected when configuring Azure).
- Wait for Azure to send you an informational email that your code is running.
- Test your code that is now up to date on Azure.
Photo credit: Pixabay