This sample shows how to enable automated blue green deployment for Azure Spring Cloud apps. The repository contains a sample application and workflows to deploy this application in an automated blue green pattern. The provided sample currently uses the Piggymetrics gateway application, but can be updated for deploying your own Spring Boot application. You can reuse the workflows in the .github/workflows folder. The sample source code is based on the Azure Architecture Center sample for [Azure Spring Cloud blue green deployment](link still needed).
This repository provides the following features:
- Repeatable automatic Blue Green deployment workflow for Azure Spring Cloud apps.
- Reusable GitHub Actions workflow for blue green deployment of apps to Azure Spring Cloud service.
- Azure Account
- Azure Spring Cloud service deployed in a resource group in your Azure account (if you don't have one set up, please follow the below guidance for setting up your infrastructure)
- GitHub repository with a Spring Boot app and capability of executing GitHub actions
- Either copy paste the workflows and deploy folder to your existing repository
- Or you can fork this repository
- Or you can start from this templated repository
Only execute the below in case you don't have an Azure resource group and Azure Spring Cloud service deployed yet. The below walk-through also contains the steps needed to set up your deployment secret in your GitHub repository. You will need the latest version of the Azure CLI installed to execute these steps.
- Define environment variables.
RESOURCE_GROUP='spring-cloud-rg'
LOCATION=westus
- Login to your Azure account and make sure the correct subscription is active.
az login
az account list -o table
az account set <your-subscription-id>
- Create a resource group for all necessary resources.
az group create --name $RESOURCE_GROUP --location $LOCATION
- Copy the resource group ID which is outputted in the previous step to a new environment variable.
RESOURCE_GROUP_ID=<resource group ID from previous output>
- Create a service principal and give it access to the resource group.
az ad sp create-for-rbac \
--name SpringCloudGHBicepActionWorkflow \
--role Contributor \
--scopes $RESOURCE_GROUP_ID \
--sdk-auth
Note
In the sample code for the deployment to Azure Spring Cloud service we will reuse this same service principal. However, for a production environment we advise you use a separate service principal with limited scope for deploying your apps to Azure Spring Cloud service.
-
Copy the full output from this command.
-
In your GitHub repo navigate to Settings > Secrets and select New Repository Secret.
-
Name the secret AZURE_CREDENTIALS and paste the output from the 'az ad sp create-for-rbac' command in the value textbox.
-
Select Add Secret.
-
Inspect the infra-deploy.yml file and update any environment variables at the top of the file to reflect your environment.
-
In your GitHub repo, navigate to Actions and select the infra-deploy action.
-
Select Run workflow > Run workflow.
-
This will start a new workflow run and deploy the necessary infrastructure.
-
Double check in the Azure Portal that all resources got deployed correctly and are up and running.
This sample repository includes 2 sample workflows for deploying applications to Azure Spring Cloud. Each workflow deploys the piggymetrics gateway application to Azure Spring Cloud service. Piggymetrics has been added to this repository as a submodule. You can change the application being deployed for your own through the parameters in each of the workflows.
The simple workflow is a workflow you can use for direct deployment to an application in Azure Spring Cloud. It does not include any blue green strategy, but deploys straight to an app. You can use this workflow in case no blue-green zero downtime deployment of your application is needed.
Steps to trigger this workflow:
-
Make sure you have created a AZURE_CREDENTIALS secret in your GitHub repository for your service principal connection as described in the infrastructure deploy above.
-
Inspect the simple-deploy.yml file and update any environment variables at the top of the file to reflect your environment.
-
In your GitHub repo, navigate to Actions and select the simple-deploy action.
-
Select Run workflow > Run workflow.
-
This will start a new workflow run and deploy your application.
The blue green workflow utilizes a blue green pattern to deploy an application to Azure Spring Cloud with zero downtime.
This workflow will deploy your application to a new deployment in Azure Spring Cloud. It then makes use of a second job linked to an environment. On the environment you can configure a required reviewers environment protection rule. This will halt the workflow run execution until you have reviewed the new version of the application has deployed correctly, has fully warmed up and can accept production load. Once this is the case, you can approve the workflow to continue its run. This will swap the 2 deployments, making your newly deployed version the production one receiving traffic. It will also delete the previous production deployment.
Steps to trigger this workflow:
-
Make sure you have created a AZURE_CREDENTIALS secret in your GitHub repository for your service principal connection as described in the infrastructure deploy above.
-
Create a new environment Production. In your GitHub repository navigate to Settings > Environments and select the New environment button. Fill out Production as the name for your environment and select the Configure environment button.
-
In the next screen, select the Required reviewers checkbox, fill out your own GitHub alias in the textbox as a required reviewer and select the Save protection rules button.
-
Inspect the blue-green-deploy.yml file and update any environment variables at the top of the file to reflect your environment.
-
In your GitHub repo, navigate to Actions and select the blue-green-deploy action.
-
Select Run workflow > Run workflow.
-
This will start a new workflow run and deploy your application to a new deployment. The workflow uses 2 deployments it can alternate between: default and green. You can change these names in the environment variables at the top of the workflow.
-
Once the deploy job has deployed your application, you will get a notification to review your deployment. First navigate to your application in Azure Spring Cloud and inspect whether the new deployment holds the new version of your application and is running correctly. If all looks ok you can approve the further run of your workflow. If not, you can reject, alter your code and redeploy.