This application is an example Blazor client app that has been containerized so it can be deployed into a Azure Container App.
This project was created initially by using the sample Blazor todo list app from the Microsoft learn site: Build a Blazor todo list app. I choose to use the Blazor WebAssembly so the code would be downloaded to the client. The only changed I made was to have it call a Web Api Container App that I created for another demo. You can find that here: Web Api Container Demo . There is also a Dockerfile as part of this project that is used to containerize the app and push it up to Azure Container Registry(ACR). Once the image is in ACR, it then creates/updates the Azure Container App for the Blazor demo web app. All of this is done in the deploy-package.yml
GitHub actions workflow. See workflow section below for more specifics on the workflow.
Workflow Name | Badge |
---|---|
Azure Container App Deployment | |
Azure Kubernetes Service (AKS) Deployment |
This is meant to be a repo that you can clone and use as you like. The only thing you will need to change is the variables in the deploy-package.yml
workflow. They will be in the env
section of the workflow. There will need to change to match the resource names you would like to use in your Azure Subscription.
- Azure Subscription
- This repo cloned in your own GitHub repo
- Dapr CLI installed
- Refer to Dapr docs for details
- Docker Desktop
- Refer to Docker docs for details
- Service principle with contributor access to the subscription created as a GitHub Secret
- This is only so you can create your resource group at the subscription level, if you don't want to give your service principle that kind of access you will need to have another way to create the resource group and then you can remove that step from the workflow
- The credentials for this service principle need to be stored according to this document: Service Principal Secret
- I have used the name
AZURE_CREDENTIALS
for the secret
Run the following command to run locally
=> dotnet run
Run the following command to run locally with Dapr. Here is the basic command with the options defined, also see Dapr docs:
dapr run --app-id APP_ID --app-port APP_PORT --dapr-http-port DAPR_HTTP_PORT dotnet run
Option Name | Description |
---|---|
app-id | Unique name of the app |
app-port | Port that the app is listening on |
dapr-http-port | Port that Dapr is listening on |
app-protocol | Protocol you want Dapr to use to communicate with application |
Here is the actual command I run to run locally:
=> dapr run --app-id blazor-app --app-port 7139 --dapr-http-port 3501 --app-protocol https dotnet run
There are a few workflows used by this project to demonstrate the different ways and resources you can deploy to. Currently there are examples for an Azure Container App and Azure Kubernetes Service (AKS).
The workflow will deploy everything it needs to a given resource group and into an Azure Container App. It has 3 separate stages: build-infra, build, deploy
- build-infra
- Creates all the required infrastructure you need for Azure Container Apps using the
az cli
. These actions are idempotent so they can be run multiple times.
- Creates all the required infrastructure you need for Azure Container Apps using the
- build
- Builds the container and tags the image
- deploy
- Uses the container image that was built and pushed to ACR and creates/updates that container app with that newly built image
The workflow is assuming that you have everything in place from an infrastructure perspective (AKS Cluster, namespace, container registry, and log analytics workspace). You can find an example of how to deploy that infrastructure in this GitHub repo. I use that one with this one AKS Cluster Deploy Example using Bicep.
This workflow has 2 separate stages: buildImage, deploy:
- buildImage
- We use the
az aks command invoke
command to get the endpoint for the api so we can set it in theappsettings.json
file. This way it can be dynamic when we deploy. - Builds the container and tags the image
- We use the
- deploy
- We use a
sed
script to replace variables in the AKS deployment file so it can be dynamic to use the container image we just built. - Then we use the deployment file to setup the deployment in AKS
- We use a