I am using the following GH Action to Build/Publish my .NET API.
#https://stackoverflow.com/questions/68327652/error-with-github-action-deploy-to-azure-web-app
name: API-zip
on:
push:
# only trigger on branches, not on tags
branches: '**'
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Setup .NET
uses: actions/setup-dotnet@v3
with:
dotnet-version: 8.0.x
dotnet-quality: 'preview'
- name: dotnet publish
run: dotnet publish 'App.ApiApp.Api.csproj' -r linux-x64 -f net8.0 -c Release -o ${{env.DOTNET_ROOT}}/app --self-contained --nologo
- name: Upload Build Artifact
uses: actions/upload-artifact@v2
with:
name: app-${{ github.run_number }}
path: ${{env.DOTNET_ROOT}}/app
publish:
runs-on: ubuntu-latest
needs: build
steps:
- name: Downlod Artifacts
uses: actions/download-artifact@v3
- name: List Files
run: ls -R
- name: Azure Login
uses: azure/CLI@v1
with:
azcliversion: 2.52.0
inlineScript: |
az login --service-principal
-u **
-p **
-t **
- name: Deploy to Azure
uses: azure/CLI@v1
with:
azcliversion: 2.52.0
inlineScript: |
zip -r app-${{ github.run_number }}.zip .
ls -R
az webapp deployment source config-zip --resource-group App --name App-zip --src app-${{ github.run_number }}.zip
It successfully completes and publishes a ZIP file to my Linux App Service.
However, when I attempt to view the App, it’s still showing me the wwwroot
default HTML page. I do have WEBSITE_RUN_FROM_PACKAGE=1
in my App Settings. I noticed when trouble shooting I extracted the ZIP file locally that it’s not zipping the raw files, but putting them in a folder first (see image)
Is this part of the problem? I tried just zipping the files themselves and re-uploading manually (to eliminate the parent folder) but it still didn’t pickup the App.
What is wrong here?
2
Answers
I figured it out using this updated GH Action:
As .net 8.0 is still in Preview not all the Features are available for Deploying your Asp.net core API. Thus while deploying the Asp.net core API or any API in Azure Web app its necessary to use Deployment mode as self contained while deploying your Web API to Web app like below:-
Reference – SO Thread answer By Pravallika and comment by YMC
I created one Asp.net core 8.0 Web API and while deployment selected Self contained as Deployment Type like below:-
And After clicking on Publish the Web API was deployed successfully like below:-
I have also connected one APIM instance for managing the API while deployment like below, you can skip this step:-
UPDATED Solution:-
By default
az webapp deployment source config-zip
does not contain a parameter to add –self-contained as Deployment mode, Thus you need to add your--self-contained
zip artifact in your az webapp deployment command in your github workflow like below:-My updated github workflow steps with the cli zip method:-
/home/runner/work/WebApplication16/WebApplication16.zip
Also, I have added the Azure CLI service principal credentials as a github secret, Refer below:-
Created service principal with contributor role at subscription level and added the output as a github secret:-
Output:-
Copied this output in the secrets:-
My github action workflow script with zip command:-
Output:-
API got deployed in Azure web app and is running successfully with /WeatherForecast:-
https://.azurewebsites.net/WeatherForecast
An alternative method is to use azure/webapps-deploy@v2 task like below:-
My github action workflow:-
I have created a default workflow by connecting my github repository with the Azure Web app via Deployment Center and then edited the workflow code like below:-
My repository with .net 8.0 core API:-
Edited the workflow file with
--self-contained and -r linux-x64
flag like below:-Workflow code:-
Cross check where your artifacts are downloaded in your build job in deploy stage and add that path in the package at Deploy to Azure Web App step as my script above:-
Web API deployed successfully:-
I am able to access WeatherForecast API like below after deployment:-