Search code examples
azuregithub-actionsazure-cliazure-deploymentazure-webapps

Deployment azure web app with "az webapp deployment source config-zip" works incorrectly


I have a simple web.api that I want to deply to azure. I use github actions for this.

in case if I use azure/webapps-deploy@v2 step, all works smoothly.

 deploy:
    runs-on: ubuntu-latest
    needs: build
    steps:
    - name: Download artifact from build job
      # published previously via `dotnet publish` and 
      #  uses: actions/upload-artifact@v3
      #   with:
      #     name: webapp
      uses: actions/download-artifact@v3
      with:
        name: webapp
        path: webapp
    - name: Login via Azure CLI
      uses: azure/login@v1
      with:
        # secret in json form are added into repository settings
        creds: ${{ secrets.AZURE_CREDENTIALS }}
    - name: Deploy web app
      id: deploywebapp
      uses: azure/webapps-deploy@v2
      with:
        app-name: ${{ env.AZURE_WEBAPP_NAME }}
        package: webapp

I can deploy application and then it's accessible via https://%AZURE_WEBAPP_NAME%.azurewebsites.net/swagger/index.html. Now, I want to use plain azure CLI commands and replace the above steps on (the only change I do):

  deploy:
    runs-on: ubuntu-latest
    needs: build
    steps:
    - name: Download artifact from build job
      uses: actions/download-artifact@v3
      with:
        name: webapp
        path: webapp
    - name: Azure Login
      uses: azure/CLI@v1
      with:
        azcliversion: 2.30.0
        inlineScript: |
          az login --service-principal \
          -u ${{ secrets.DEPLOYMENT_AZURE_CLIENT_ID }} \
          -p ${{ secrets.DEPLOYMENT_AZURE_CLIENT_SECRET }} \
          -t ${{ secrets.DEPLOYMENT_AZURE_TENANT_ID }}        
    - name: Deploy to Azure WebApp
      uses: azure/CLI@v1
      with:
        azcliversion: 2.30.0
        inlineScript: |
          zip -r webapp.zip .
          az webapp deployment source config-zip --resource-group ${{ env.AZURE_WEBAPP_RG }} --name ${{ env.AZURE_WEBAPP_NAME }} --src "webapp.zip"

this step doesn't fail too, but the deployed application is inaccessible (with previous url) and returns 404 error. The deploy step output is:

WARNING: Getting scm site credentials for zip deployment
WARNING: Starting zip deployment. This operation can take a while to complete ...
WARNING: Deployment endpoint responded with status code 202
{
  "active": true,
  "author": "N/A",
  "author_email": "N/A",
  "build_summary": {
    "errors": [],
    "warnings": []
  },
  "complete": true,
  "deployer": "Push-Deployer",
  "end_time": "..",
  "id": "..",
  "is_readonly": true,
  "is_temp": false,
  "last_success_end_time": "..",
  "log_url": "https://%AZURE_WEBAPP_NAME%.scm.azurewebsites.net/api/deployments/latest/log",
  "message": "Created via a push deployment",
  "progress": "",
  "received_time": "..",
  "site_name": "%AZURE_WEBAPP_NAME%",
  "start_time": "...",
  "status": 4,
  "status_text": "",
  "url": "https://%AZURE_WEBAPP_NAME%.scm.azurewebsites.net/api/deployments/latest"
}

az script ran successfully.

What is the difference between both of these steps?

UPDATE1: I've added --debug argument to az webapp deployment .. command and see no errors or failures in the verbose output

UPDATE2: I see required files when I ssh to the azure server:

root@..:~/site/wwwroot/webapp# ls
DeploymentTemplates                 Swashbuckle.AspNetCore.SwaggerGen.dll  WebApiDemo.deps.json  WebApiDemo.runtimeconfig.json  web.config
Microsoft.OpenApi.dll               Swashbuckle.AspNetCore.SwaggerUI.dll   WebApiDemo.dll        appsettings.Development.json
Swashbuckle.AspNetCore.Swagger.dll  WebApiDemo 

UPDATE3: It looks like it might be related to the fact that when I use a plain CLI commandsm the actually generated files are placed one level deeper (see ssh output before and pay attention on webapp folder). Where in the correctly deployed application the deployed files are placed in the root of wwwroot:

root@..:~/site/wwwroot# ls
DeploymentTemplates                 Swashbuckle.AspNetCore.SwaggerGen.dll  WebApiDemo.deps.json  WebApiDemo.runtimeconfig.json  web.config
Microsoft.OpenApi.dll               Swashbuckle.AspNetCore.SwaggerUI.dll   WebApiDemo.dll        appsettings.Development.json
Swashbuckle.AspNetCore.Swagger.dll  WebApiDemo  

Solution

  • The issue was in a zip file. The content inside was:

    - folderName
      - file1
      - file2
    

    which led to the folders structure inside wwwroot:

    - wwwroot
      - folderName
        - file1
        - file2 
    

    where the zip content should be just:

    - file1
    - file2
     
    

    Fixing it has solved the issue