A containerized (Windows) .NET Framework Task App setup with continuous deployment through GitHub Actions to Azure App Service.
Fork this repository so you have your own copy that you can add your own GitHub secrets to.
Create the following resources. You will need information from each resource detailed below that will be used in the file and stored in your secrets. Create your choice of registry (Azure Container Registry or Docker Hub) first since you will need information from there before you can create your App Service.
- Azure Container Registry OR Docker Hub
CONTAINER_REGISTRY_USERNAME
= your registry nameCONTAINER_REGISTRY_PASSWORD
= your registry passwordCONTAINER_REGISTRY_NAME
= azure container registry login server
- App Service (Web App for Container)
APP_NAME
= your web apps name
- .NET Framework application with supporting dockerfile in a GitHub repository
- Azure SQL Database (Optional)
AZURE_SQL_CONNECTION_STRING
= your database connection stringDATABASE_SERVER_NAME
= name of your server
Our workflow will use a Service Principal to authenticate with Azure when deploying the container to App Service. A service principal is an Active Directory Identity created for use with automation scenarios, such as GitHub Actions.
-
Run the following command in Azure CLI in powershell to get the credentials needed to run the login action. The output of this command will be a collection of key value pairs that you'll need to add to your GitHub secrets.
az ad sp create-for-rbac --name "<appservice-name>" --role contributor \ --scopes /subscriptions/{subscription-id}/resourceGroups/{resource-group} \ --sdk-auth
-
Copy the output into your GitHub secrets to use as your AZURE_CREDENTIALS secret.
{ "clientId": "<GUID>", "clientSecret": "<GUID>", "subscriptionId": "<GUID>", "tenantId": "<GUID>" }
Since we are using sensitive information that you don't want others to access, we will use GitHub secrets to protect our information. Create a secret by following the directions here. Add the github secrets variables below with your own secrets appropriate from each resource. If you are not using Docker Hub, ignore the DOCKERHUB prefixed parameters and if you are not using ACR, ignore the REGISTRY prefixed variables.
APP_NAME
= your web apps nameAZURE_CREDENTIALS
= your service principal outputIMAGE_NAME
= name of your image that will upload to your registryCONTAINER_REGISTRY_NAME
= your registry usernameCONTAINER_REGISTRY_PASSWORD
= your registry passwordCONTAINER_LOGIN_SERVER
= azure container registry login serverAZURE_SQL_CONNECTION_STRING
= your database connection stringDATABASE_SERVER_NAME
= name of your server
The main.yaml
file is set to trigger on any pushes to master, so when you commit your changes the build will run. View the Actions tab in your repository to view the build and any potential errors.