Skip to content

Instantly share code, notes, and snippets.

@m-jovanovic
Created January 10, 2025 17:14
Show Gist options
  • Save m-jovanovic/fc7c17df744063099414986b05930ec4 to your computer and use it in GitHub Desktop.
Save m-jovanovic/fc7c17df744063099414986b05930ec4 to your computer and use it in GitHub Desktop.
Sample GitHub Actions workflow to build a .NET application, build a Docker image, upload to Azure Container Registry, and then publish the image into Azure Container App
name: Deploy to Azure Container Apps
on:
workflow_dispatch:
push:
branches: [main]
env:
AZURE_CONTAINER_REGISTRY: <NAME>
CONTAINER_APP_NAME: <NAME>
RESOURCE_GROUP: <NAME>
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Set up .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: "8.0.x"
- name: Build
run: dotnet build --configuration Release
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Log in to ACR
uses: docker/login-action@v3
with:
registry: ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io
username: ${{ secrets.AZURE_REGISTRY_USERNAME }}
password: ${{ secrets.AZURE_REGISTRY_PASSWORD }}
- name: Build and push container image to ACR
uses: docker/build-push-action@v6
with:
push: true
tags: ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_APP_NAME }}:${{ github.sha }}
file: Refit.Api/Dockerfile
- name: Azure Login
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
- name: Deploy to Azure Container Apps
uses: azure/container-apps-deploy-action@v1
with:
imageToDeploy: ${{ env.AZURE_CONTAINER_REGISTRY }}.azurecr.io/${{ env.CONTAINER_APP_NAME }}:${{ github.sha }}
resourceGroup: ${{ env.RESOURCE_GROUP }}
containerAppName: ${{ env.CONTAINER_APP_NAME }}
environmentVariables: |
ASPNETCORE_ENVIRONMENT=Development
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment