Skip to content

Instantly share code, notes, and snippets.

@sturlath
Last active July 3, 2023 08:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sturlath/d51df80d8daf38aa343c9208fdd0b402 to your computer and use it in GitHub Desktop.
Save sturlath/d51df80d8daf38aa343c9208fdd0b402 to your computer and use it in GitHub Desktop.
A abp.io Blazor Server docker build and deploy to dev and production to Azure Container Apps
name: Version, Build, and Deploy
on:
push:
branches:
- main
tags:
- 'v*' # This will match tags like v1.0, v2.0.1, etc. and is used to deploy to production
pull_request:
branches:
- main
env:
# Development Environment Configuration
DEV_AZURE_CONTAINER_APP_NAME: your-dev-container-app-name
DEV_AZURE_CONTAINER_REGISTRY: your-container-registry.azurecr.io
DEV_RESOURCE_GROUP: your-dev-resource-group
DEV_LOCATION: your-dev-location
# Production Environment Configuration
PROD_AZURE_CONTAINER_APP_NAME: your-prod-container-app-name
PROD_AZURE_CONTAINER_REGISTRY: your-prod-acr-name.azurecr.io
PROD_RESOURCE_GROUP: your-prod-resource-group
PROD_LOCATION: your-prod-location
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
# Build the Blazor UI Docker image
- name: Build the Blazor UI Docker image
run: docker build . --file /aspnet-core/src/yourSolution.Blazor/Dockerfile --tag blazor:${{ github.sha }} # Docker images are tagged with the commit hash
# Build the Migrator Docker image
- name: Build the Migrator Docker image
run: docker build . --file /aspnet-core/src/yourSolution.DbMigrator/Dockerfile --tag dbmigrator:${{ github.sha }} # Docker images are tagged with the commit hash
# Deployed to dev on every sucessfull PR merge to main
deploy-development:
needs: build
if: github.ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Login to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.DEV_AZURE_CREDENTIALS }}
- name: Login to ACR (Development)
run: az acr login --name ${{ env.DEV_AZURE_CONTAINER_REGISTRY }}
- name: Deploy Blazor to Azure Container Apps (Development)
run: |
az containerapp create --name ${{ env.DEV_AZURE_CONTAINER_APP_NAME }}-blazor \
--resource-group ${{ env.DEV_RESOURCE_GROUP }} \
--image ${{ env.DEV_AZURE_CONTAINER_REGISTRY }}/blazor:${{ github.sha }} \
--cpu 0.5 --memory 1Gi \
--location ${{ env.DEV_LOCATION }}
- name: Run Migrations (Development)
run: |
docker run --rm \
-e ConnectionString="${{ secrets.DEV_POSTGRES_CONNECTION_STRING }}" \
dbmigrator:${{ github.sha }}
# Deployed to production only if code is tagged with v (v1.0) on the main branch
deploy-production:
needs: build
if: startsWith(github.ref, 'refs/tags/v') && github.event.base_ref == 'refs/heads/main'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Login to Azure
uses: azure/login@v1
with:
creds: ${{ secrets.PROD_AZURE_CREDENTIALS }}
- name: Login to ACR (Production)
run: az acr login --name ${{ env.PROD_AZURE_CONTAINER_REGISTRY }}
- name: Deploy Blazor to Azure Container Apps (Production)
run: |
az containerapp create --name ${{ env.PROD_AZURE_CONTAINER_APP_NAME }}-blazor \
--resource-group ${{ env.PROD_RESOURCE_GROUP }} \
--image ${{ env.PROD_AZURE_CONTAINER_REGISTRY }}/blazor:${{ github.sha }} \
--cpu 1 --memory 2Gi \
--location ${{ env.PROD_LOCATION }}
- name: Run Migrations (Production)
run: |
docker run --rm \
-e ConnectionString="${{ secrets.PROD_POSTGRES_CONNECTION_STRING }}" \
dbmigrator:${{ github.sha }}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment