Passwordless deployments from GitHub Actions to Microsoft Azure

This is something which i had tried a couple of months back and I think it should still work but please do let me know if things have changed since I am writing this post after a few months.

Step 1: Set up an Azure Account

If you don’t already have an Azure account, you’ll need to set one up. You can sign up for a free account on the Azure website.

Step 2: Create an Azure Resource Group

You’ll need to create a new resource group in Azure to hold your app service, storage account, and other resources. You can create a new resource group using the Azure portal or the Azure CLI.

Step 3: Create an App Service in Azure

Create an App Service in Azure to host your application. You can create a new App Service using the Azure portal or the Azure CLI.

Step 4: Set up Azure App Service Deployment Center

Azure App Service Deployment Center helps you automate deployments from various sources, including GitHub. To set up the Deployment Center:

  • In the Azure portal, navigate to your App Service and select “Deployment Center” from the menu.
  • Choose the source you want to use, in this case, select “GitHub”.
  • Follow the instructions to connect your GitHub account to your Azure subscription.
  • Select your repository, branch, and configure your deployment settings.

Step 5: Configure GitHub Actions

To automate your deployments from GitHub to Azure, you’ll need to configure GitHub Actions. Here’s the YAML file that you can use:

name: Azure App Service CI/CD

on:
  push:
    branches:
      - main

env:
  AZURE_WEBAPP_NAME: <your-app-service-name>
  AZURE_WEBAPP_PACKAGE_PATH: '<path-to-your-app-package>'
  AZURE_WEBAPP_PUBLISH_PROFILE: '<path-to-your-publish-profile>'

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v2
    - name: Set up .NET Core
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: '3.1.x'
    - name: Build with dotnet
      run: dotnet build --configuration Release
    - name: Publish with dotnet
      run: dotnet publish --configuration Release --output $(Build.ArtifactStagingDirectory)
    - name: Deploy to Azure Web App
      uses: azure/webapps-deploy@v2
      with:
        app-name: ${{ env.AZURE_WEBAPP_NAME }}
        publish-profile: ${{ env.AZURE_WEBAPP_PUBLISH_PROFILE }}
        package: ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}

This YAML file sets up a GitHub Actions workflow that builds your app, publishes it, and deploys it to Azure. Make sure to replace the placeholders with your app service name, the path to your app package, and the path to your publish profile.

Step 6: Push your changes to GitHub

Once you’ve set up your GitHub Actions workflow, push your changes to GitHub. This will trigger the workflow and start the deployment process.

Step 7: Verify the Deployment

Once the deployment is complete, verify that your app is up and running in Azure. You can navigate to your App Service in the Azure portal and select “Browse” to see your app.

That’s it! You’ve successfully set up passwordless deployments from GitHub Actions to Microsoft Azure.

Leave a Reply