Post(s) tagged CI/CD

How to build and deploy a container to an Azure Web App using GitHub CI/CD

  • Create a container application from the Azure portal and download the publish profile for your Azure Web App. You can download this file from the Overview page of your Web App in the Azure Portal.
  • Create a secret in your repository named AZURE_WEBAPP_PUBLISH_PROFILE, paste the publish profile contents as the value of the secret.
  • Create a GitHub Personal access token with "repo" and "read:packages" permissions.
  • Create three app settings on your Azure Web app:
DOCKER_REGISTRY_SERVER_URL: Set this to "https://ghcr.io"
DOCKER_REGISTRY_SERVER_USERNAME: Set this to the GitHub username or organization that owns the repository
DOCKER_REGISTRY_SERVER_PASSWORD: Set this to the value of your PAT token from the previous step
  • Change the value for the AZURE_WEBAPP_NAME. Create a new workflow in GitHub Actions and add the below code as filename.yml
name: Build and deploy a container to an Azure Web App

env:
  AZURE_WEBAPP_NAME: samprixapp  # set this to the name of your Azure Web App

on:
  push:
    branches:
      - master
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/[email protected]

      - name: Set up Docker Buildx
        uses: docker/[email protected]

      - name: Log in to GitHub container registry
        uses: docker/[email protected]
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ github.token }}

      - name: Lowercase the repo name and username
        run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}

      - name: Build and push container image to registry
        uses: docker/[email protected]
        with:
          push: true
          tags: ghcr.io/${{ env.REPO }}:${{ github.sha }}
          file: ./Dockerfile

  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Development'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

    steps:
      - name: Lowercase the repo name and username
        run: echo "REPO=${GITHUB_REPOSITORY,,}" >>${GITHUB_ENV}

      - name: Deploy to Azure Web App
        id: deploy-to-webapp
        uses: azure/[email protected]
        with:
          app-name: ${{ env.AZURE_WEBAPP_NAME }}
          publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
          images: 'ghcr.io/${{ env.REPO }}:${{ github.sha }}'

As per the above workflow, the code pushed in the master branch will automatically deploy to your Azure application. You can view the logs on the GitHub actions tab as well as Azure app logs.


9 Views Posted on March 19, 2022
SPONSORS