Chris Tremblay

Helping developers build awesome stuff on Azure
Logo
Connect with me

LinkedIn
chris.tremblay@microsoft.com
christremblay.com
azurepetstore.com

View my Microsoft Learn Module https://aka.ms/learn-about-containers-on-azure-with-chris

View Azure Pet Store on GitHub chtrembl/azure-cloud

04 - Configure Git Hub Action for CI/CD into App Service

This guide is part of the Azure Pet Store App Dev Reference Guide

In this section, we’ll configure Git Hub Action for Pet Store App CI/CD into App Service

Head to Azure Portal and find your Container Registry (as seen below, that was provisioned in the first guide 00-setup-your-environment) and copy your Login Server, Username and Password off somewhere (you will need them)

You should see something similar to the below image:

📝 Please Note, you will have to enable Admin user

Head to GitHub. By now you should have already cloned or forked https://github.com/chtrembl/azure-cloud and are working in the same repository structure within your GitHub account

📝 Please Note, We will assume you have forked the azure-cloud repository, it is the easiest way to get going (for instructions on this view the “Forking the azure-cloud” section in 00-setup-your-environment. Also, both PetStoreApp and PetStoreService use a Spring Boot Application properties file named application.yml to drive the functionality/configuration of these applications which is located in src/main/resources/application.yml of both projects. By default, this file has all of the properties that are needed throughout the guides, and by default are commented out. This means that the applications will start automatically without having to configure anything. As you progress through the guides, each guide will inform you of what properties to uncomment and configure within your environment. If you have not already done so, login to your GitHub account, head to https://github.com/chtrembl/azure-cloud, and fork.

You should see something similar to the below image:

Head to Settings > Secrets, Add a secret to store the Azure Container Registry Secret from above. Create a PETSTORECRSECRET, and paste in password from above.

You should see something similar to the below image:

Head to Actions, and select “I Agree” to enable Actions…

You should see something similar to the below image:

Head to azure-cloud/blob/main/.github/workflows/petstoresapp_ci_cd_to_appservice.yml and update the following properties to reflect your Container Registry and your Username from above:

AZURE_CONTAINER_REGISTRY

AZURE_CONTAINER_REGISTRY_USERNAME

Commit your changes

📝 Please Note, azure-cloud/blob/main/.github/workflows/petstoresapp_ci_cd_to_appservice.yml action is configured to execute on any changes to the perstoreapp folder

on:
  push:
    branches:
      - main
    paths:
      - petstore/petstoreapp/**

Let’s first take a look at azure-cloud/blob/main/.github/workflows/petstoresapp_ci_cd_to_appservice.yml to understand what is going on.

There are several Git Hub Tasks. The goal is to build the Spring Boot Java Pet Store Application Docker Image, Push it into Azure Container Registry and have an Azure App Service Web Hook to notify/deploy.

name: Pet Store App CI/CD to Azure App Service

env:
  AZURE_CONTAINER_REGISTRY: azurepetstorecr.azurecr.io
  AZURE_CONTAINER_REGISTRY_USERNAME: azurepetstorecr

on:
  push:
    branches:
      - main
    paths:
      - petstore/petstoreapp/**

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Checking the file system listing for Pet Store App
      run: |
        ls -al
    - name: Update the version.json
      run: echo -n -e "{\"version\":\"$\",\"date\":\"$(date '+%m-%d-%Y %H:%M:%S')\"}" > petstore/petstoreapp/src/main/resources/static/content/version.json
    - run: cat petstore/petstoreapp/src/main/resources/static/content/version.json
    - uses: actions/setup-java@v2
      name: Building Pet Store App with Java 13
      with:
        java-version: '13'
        distribution: 'adopt'
    - name: Run Maven build
      run: mvn -f petstore/petstoreapp/pom.xml --batch-mode --update-snapshots verify
    - name: Upload Maven build artifact
      uses: actions/upload-artifact@v1
      with:
        name: artifact
        path: petstore/petstoreapp/target/petstoreapp-0.0.1-SNAPSHOT.jar
    - uses: azure/docker-login@v1
      name: Build Docker image
      with:
        login-server: $
        username: $
        password: $
    - name: Push Docker image to Azure Container Registry
      run: |
        docker build petstore/petstoreapp -t $/petstoreapp:latest -t $/petstoreapp:$
        docker push $/petstoreapp:$
        docker push  $/petstoreapp:latest

This workflow action does both CI & CD. Below are the details:

📝 Please Note, you may be wondering why we are building the artifact jar before having Docker execute a multi stage build, this was just left in for academic purposes to show the features of GitHub artifact upload and is not needed for anything other than that, feel free to remove the “Upload Maven build artifact” task.

Head to your azure-cloud/petstore/petstoreapp folder and edit your README.MD file and commit, this will trigger the azure-cloud/blob/main/.github/workflows/petstoresapp_ci_cd_to_appservice.yml

You should see something similar to the below image:

Head to Actions again and your action should bow be building/deploying

You should see something similar to the below image:

Once successful you will see something like

📝 Please Note, verify your Azure App Service Container Settings are set for Continuous Deployments of the Images being built in this guide, you may have skipped this step in the previous guide 03-configure-app-service-for-cd

If successful you can head to a browser and visit your FQDN Azure App Service URL as seen below (this is the URL from the previous guide 03-configure-app-service-for-cd)

🎉Congratulations, you now have Pet Store App Continuously Deploying into your App Service each and every time an image is pushed to Azure Container Registry from your Git Hub Action. Notice the Date/Version within your App Service HTML Footer (seen in browser) matches the Git Hub Action Build Meta Data.

📝 Please Note, Enable application logging (Linux/Container) so that logs start aggregating for you. To enable application logging for Linux apps or custom container apps in the Azure portal, navigate to your app and select App Service logs. In Application logging, select File System. In Quota (MB), specify the disk quota for the application logs. In Retention Period (Days), set the number of days the logs should be retained. When finished, select Save. This will come in handy when you start experimenting with Application Insights.

Things you can now do now with this guide

☑️ GitHub Action to CI/CD into App Service, showcasing the details behind building/deploying and the associated meta data reflecting within the running application

☑️ Build Meta Data appears within your running application which matches the container configuration reflected in your App Service

📝 Please Note, if you’re interested in viewing the web hook that got created, automagically, when Container Configuration was updated to sync with Azure Container Registry, you can view these under the Azure Container Registry as seen below.


➡️ Next guide: 05 - Create an Azure Kubernertes Cluster