azure-web-app-servicegithub-actionsmicroservicesazure-deployment

having issue in deploing dotnet core api on azure app service as virtual application using github workflow without publish profile


I'm trying to deploy my api applications on azure app services as virtual application (/api/service1/) using GitHub workflows. I was able to deploy but other virtual applications are getting deleted when I see in scm portal. How can I clean only the target virtual application directory before deploying latest version.

if I set clean argument as true then it is clearing wwwroot directory and all other virtual applications directories are deleting.

If I set clean argument as false then wwwroot directories are not getting deleted but in virtual application old binaries(dlls) exists.

Here is my workflow file.

deploy:
    if: ${{ github.ref == inputs.branch_name }}
    name: Deploying app on Azure
    runs-on: [self-hosted-linux]
    needs: [publish_artifacts]
    environment:
      name: ${{ inputs.environment_name }}
    steps:
      - name: Install az cli
        uses: elstudio/action-install-azure-cli@v1

      # authenticate to azure
      - name: "Az CLI login"
        uses: azure/login@v1.5.1
        with:
          creds: '{"clientId":"${{ secrets.AZURE_CLIENT_ID }}","clientSecret":"${{ secrets.AZURE_CLIENT_SECRET }}","subscriptionId":"${{ secrets.AZURE_SUBSCRIPTION_ID }}","tenantId":"${{ env.AZURE_TENANT_ID }}"}'

      - name: Download published artifact
        uses: actions/download-artifact@v3
        with:
          name: dev-artifact

      - name: Deploy to Azure Web App
        uses: azure/webapps-deploy@v3
        id: deploy-to-webapp
        with:
          app-name: "${{ inputs.azure_app_name }}"
          package: ${{ github.WORKSPACE }}
          target-path: ${{ inputs.virtual_app_path}}
          clean: true 

if I set clean argument as true then it is clearing wwwroot directory and all other virtual applications directories are deleting.

If I set clean argument as false then wwwroot directories are not getting deleted but in virtual application old binaries(dlls) exists.

I'm expecting to delete files only within specific targeted virtual directory and not to delete any of other virtual directory exists in wwwroot folder.


Solution

  • I created a sample ASP. NET Core Web Api with Virtual directories in it and able to delete specific directory files via GitHub actions.

    - name: Delete files from /api2 directory using Kudu API
    run: |
    curl -X DELETE "https://linuxvirtual-dqa2hggacehwggdt.scm.eastus-01.azurewebsites.net/api/vfs/site/wwwroot/api2/?recursive=true" \
    -H "Authorization: Basic $(echo -n ${{ secrets.KUDU_USERNAME }}:${{ secrets.KUDU_PASSWORD }} | base64)" \
    -v \
    --write-out "%{http_code}" \
    --output /dev/null
    

    My complete workflow file

    name: Build and deploy ASP.Net Core app to Azure Web App - linuxvirtual
    on:
      push:
        branches:
          - main
      workflow_dispatch:
    jobs:
      build:
        runs-on: ubuntu-latest
        steps:
          - uses: actions/checkout@v4
          - name: Set up .NET Core
            uses: actions/setup-dotnet@v4
            with:
              dotnet-version: '8.x'
          - name: Build with dotnet
            run: dotnet build --configuration Release
          - name: dotnet publish
            run: dotnet publish -c Release -o ${{ github.workspace }}/myapp
          - name: Upload artifact for deployment job
            uses: actions/upload-artifact@v4
            with:
              name: .net-app
              path: ${{ github.workspace }}/myapp
      deploy:
        runs-on: ubuntu-latest
        needs: build
        environment:
          name: 'Production'
          url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
        permissions:
          id-token: write 
        steps:
          - name: Download artifact from build job
            uses: actions/download-artifact@v4
            with:
              name: .net-app    
          - name: Login to Azure
            uses: azure/login@v2
            with:
              client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_<client-id> }}
              tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_<tenant-id>}}
              subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_<subscription-id> }}
          - name: Debug connectivity to Kudu
            run: |
              nslookup linuxvirtual-dqa2hggacehwggdt.scm.eastus-01.azurewebsites.net
              curl -v https://linuxvirtual-dqa2hggacehwggdt.scm.eastus-01.azurewebsites.net
          - name: Delete files from /api2 directory using Kudu API
            run: |
              curl -X DELETE "https://linuxvirtual-dqa2hggacehwggdt.scm.eastus-01.azurewebsites.net/api/vfs/site/wwwroot/api2/?recursive=true" \
              -H "Authorization: Basic $(echo -n ${{ secrets.KUDU_USERNAME }}:${{ secrets.KUDU_PASSWORD }} | base64)" \
              -v \
              --write-out "%{http_code}" \
              --output /dev/null
    
          - name: Deploy to Azure Web App
            id: deploy-to-webapp
            uses: azure/webapps-deploy@v3
            with:
              app-name: 'linuxvirtual'
              slot-name: 'Production'
              package: .
              clean : false
    

    enter image description here