Table of Content
Part 1 – Provisioning and Restoring DB’s from Backup
Part 4 – Setting Up Dynamic Backend Service Url’s in Mobile app (1 build for all stages) (coming soon)
I’ve recently started giving a talk titled Real World DevOps where I show the power and flexibility of build/release pipelines. I create a full end to end pipeline for a complex app which consists of
- Good ‘ol fashioned asp.net web front end written in c#
- Azure SQL
- API layer written in node.js, hosted in k8s
- Services layer written in .net core hosted in a container
- iOS and android app.
Then, starting from a completely empty Azure subscription, I deploy it all using pipelines and in my release pipeline, I do in parallel
- provision and configure all the infrastructure needed using Infrastructure as Code (specifically by calling the Az CLI with my own infra versioning framework)
- Restore DB data from backups
- Deploy app into all the pieces of infrastructure
- Deploy mobile app to alpha testers/beta testers/store
- Set up HTTPS
- Set up DNS
- Run automated UI tests against the web front end
- Run automated ui tests against the mobile app
- Configure mobile app so there only needs to be one build which can dynamically switch backend service url’s on the fly for different stages
In this blog series, I’ll be breaking down how I do all this in detail.
Infrastructure as Code/Configuration as Code
The IaC for this entire project uses Az CLI commands wrapped in powershell scripts plus my infrastructure versioning framework. This versioning framework versions the script changes and keeps track of what version the infrastructure is currently at. When my pipeline is run, only the versions which have not been run gets run. This does 2 things. 1) This makes my IaC script much cleaner and easier to manage over time (Az CLI is only sort of idempotent, so this removes any need to have messy if statements everywhere) because no matter how many times my pipeline gets run, only new versions of the script gets called. 2) It makes my pipeline run much faster because if the infrastructure is up to date, nothing gets called. To see the how, why, where and what of this infrastructure framework, check out this blog post.
Provisioning and Restoring DB’s from Backup
The script to provision the DB is pretty straight forward. The first thing I do is pass in all the variables I will need later in my script as parameters
Next, I login to Azure with my service principal
Next, I create my resource group
And finally, I create my SQL Server and a firewall rule for the SQL Server
The next step is for disaster recovery. I’m doing scheduled backups of my database. In fact, I store the latest backup of my database in Azure blob storage in a whole separate Azure subscription as a bacpac. So to restore my database using my backpack, I do the following steps.
Download the latest bacpac file from blob storage
And finally restore the db using the bacpac
Here is the full script
Being able to use IaC and my pipeline as a disaster recovery tool was super exciting and fun to do. My entire resource group can be deleted and everything can get restored, including the infrastructure AND data! If you don’t have an Azure DevOps subscription, go to dev.azure.com and start building out some fun pipelines!