Skip to content

This repository holds sample code for deploying apps to Azure Spring Cloud service in an automated blue green way.

License

Notifications You must be signed in to change notification settings

Ed-Price/azure-spring-cloud-blue-green

 
 

Repository files navigation

Automated blue green deployment for Azure Spring Cloud applications

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

Features

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.

Getting Started

Prerequisites

  • 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

Setup the infrastructure

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.

  1. Define environment variables.
RESOURCE_GROUP='spring-cloud-rg'
LOCATION=westus
  1. 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>
  1. Create a resource group for all necessary resources.
az group create --name $RESOURCE_GROUP --location $LOCATION
  1. 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>
  1. 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.

  1. Copy the full output from this command.

  2. In your GitHub repo navigate to Settings > Secrets and select New Repository Secret.

  3. Name the secret AZURE_CREDENTIALS and paste the output from the 'az ad sp create-for-rbac' command in the value textbox.

  4. Select Add Secret.

  5. Inspect the infra-deploy.yml file and update any environment variables at the top of the file to reflect your environment.

  6. In your GitHub repo, navigate to Actions and select the infra-deploy action.

  7. Select Run workflow > Run workflow.

  8. This will start a new workflow run and deploy the necessary infrastructure.

  9. Double check in the Azure Portal that all resources got deployed correctly and are up and running.

Workflows in this sample

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.

Simple Workflow

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:

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

  2. Inspect the simple-deploy.yml file and update any environment variables at the top of the file to reflect your environment.

  3. In your GitHub repo, navigate to Actions and select the simple-deploy action.

  4. Select Run workflow > Run workflow.

  5. This will start a new workflow run and deploy your application.

Blue Green Workflow

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:

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

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

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

  4. Inspect the blue-green-deploy.yml file and update any environment variables at the top of the file to reflect your environment.

  5. In your GitHub repo, navigate to Actions and select the blue-green-deploy action.

  6. Select Run workflow > Run workflow.

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

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

Resources

About

This repository holds sample code for deploying apps to Azure Spring Cloud service in an automated blue green way.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Bicep 100.0%