How to reduce the deployment time using the file compression technique in Azure App Service
Published Jan 04 2023 05:53 AM 5,825 Views
Microsoft

Uncompressed file uploads are slower than uploading the compressed file to the artifact when using the GitHub Workflow.

 

The time taken for a sample Node application to Azure App Service was 50mins to an hour for completing the deployment, that was triggered using GitHub Action Workflow.

The screenshot below shows the total duration for the task to complete using the default GitHub Action workflow:

a.JPG

 

To help mitigate the problem for reducing the deployment time significantly I have added the following steps in the GitHub Action workflow. Please note as I am using the ubuntu-latest OS to run the GitHub Action so there might be different method for file compression when using a different OS.

 

Build Stage:

- name: Zip artifact to upload

   run: zip -r ${{ env.ZIP_PACKAGE_NAME }} ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}

 

Here is the complete sample code for Linux GitHub Action workflow deployment.yml:

 

# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy Node.js app to Azure Web App - <linux web app name>

on:
  push:
    branches:
      - master
  workflow_dispatch:

# CONFIGURATION
# For help, go to https://github.com/Azure/Actions
#
# 1. Set up the following secrets in your repository:
#   YOUR_AZURE_APPSERVICE_PUBLISHPROFILE
#
# 2. Change these variables for your configuration:
env:
  YOUR_AZURE_WEBAPP_NAME: <linux web app name> # set this to your application's name
  YOUR_AZURE_WEBAPP_SLOT_NAME: Production # set this to your application's slot name
  YOUR_AZURE_WEBAPP_PACKAGE_PATH: "."     # set this to the path to your web app project, defaults to the repository root
  YOUR_NODE_VERSION: "16.x" # set this to the node version to use
  YOUR_ZIP_PACKAGE_NAME: "app-release.zip"

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Set up Node.js version
        uses: actions/setup-node@v1
        with:
          node-version: ${{ env.YOUR_NODE_VERSION }}

      - name: npm install, build, and test
        run: |
          npm install
          npm run build
          # npm run test --if-present

      - name: Zip artifact to upload
        run: zip -r ${{ env.YOUR_ZIP_PACKAGE_NAME }} ${{ env.YOUR_AZURE_WEBAPP_PACKAGE_PATH }}

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v2
        with:
          name: ${{ env.YOUR_AZURE_WEBAPP_NAME }}
          path: ${{ env.YOUR_AZURE_WEBAPP_PACKAGE_PATH }}/${{ env.YOUR_ZIP_PACKAGE_NAME }}
          retention-days: 1

  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v2
        with:
          name: ${{ env.YOUR_AZURE_WEBAPP_NAME }}

      - name: 'Deploy to Azure Web App'
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v2
        with:
          app-name: ${{ env.YOUR_AZURE_WEBAPP_NAME }}
          slot-name: ${{ env.YOUR_AZURE_WEBAPP_SLOT_NAME }}
          publish-profile: ${{ secrets.YOUR_AZURE_APPSERVICE_PUBLISHPROFILE }}
          package: ${{ env.YOUR_AZURE_WEBAPP_PACKAGE_PATH }}/${{ env.YOUR_ZIP_PACKAGE_NAME }}

 

 

After adding the above stage, the deployment time was reduced significantly to less than 20mins.

The screenshot below shows the time taken after the above steps implemented using the GitHub Action workflow:

b.JPG

 

You can use Windows OS Equivalent 7z file compression when using windows-latest OS to run the GitHub Action when deploying your Windows WebApp.

 

Build Stage:

- name: Zip artifact to upload

   run: 7z a ${{ env.ZIP_PACKAGE_NAME }} ${{ env.AZURE_WEBAPP_PACKAGE_PATH }}

 

Here is the complete sample code for Windows GitHub Action workflow deployment.yml:

 

# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy Node.js app to Azure Web App - <windows web app name>

on:
  push:
    branches:
      - master
  workflow_dispatch:

# CONFIGURATION
# For help, go to https://github.com/Azure/Actions
#
# 1. Set up the following secrets in your repository:
#   YOUR_AZURE_APPSERVICE_PUBLISHPROFILE
#
# 2. Change these variables for your configuration:
env:
  YOUR_AZURE_WEBAPP_NAME: <windows web app name>            # set this to your application's name
  YOUR_AZURE_WEBAPP_SLOT_NAME: Production # set this to your application's slot name
  YOUR_AZURE_WEBAPP_PACKAGE_PATH: "."     # set this to the path to your web app project, defaults to the repository root
  YOUR_NODE_VERSION: '16.x'                            # set this to the node version to use
  YOUR_ZIP_PACKAGE_NAME: "app-release.zip"

jobs:
  build:
    runs-on: windows-latest

    steps:
      - uses: actions/checkout@v2

      - name: Set up Node.js version
        uses: actions/setup-node@v1
        with:
          node-version: ${{ env.YOUR_NODE_VERSION }}

      - name: npm install, build, and test
        run: |
          npm install
          npm run build
          # npm run test --if-present
      
      - name: Zip artifact to upload
        run: 7z a ${{ env.YOUR_ZIP_PACKAGE_NAME }} ${{ env.YOUR_AZURE_WEBAPP_PACKAGE_PATH }}
      
      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v2
        with:
          name: ${{ env.YOUR_AZURE_WEBAPP_NAME }}
          path: ${{ env.YOUR_AZURE_WEBAPP_PACKAGE_PATH }}/${{ env.YOUR_ZIP_PACKAGE_NAME }}
          retention-days: 1

  deploy:
    runs-on: windows-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v2
        with:
          name: ${{ env.YOUR_AZURE_WEBAPP_NAME }}

      - name: 'Deploy to Azure Web App'
        uses: azure/webapps-deploy@v2
        id: deploy-to-webapp
        with:
          app-name: ${{ env.YOUR_AZURE_WEBAPP_NAME }}
          slot-name: ${{ env.YOUR_AZURE_WEBAPP_SLOT_NAME }}
          publish-profile: ${{ secrets.YOUR_AZURE_APPSERVICE_PUBLISHPROFILE }}
          package: ${{ env.YOUR_AZURE_WEBAPP_PACKAGE_PATH }}/${{ env.YOUR_ZIP_PACKAGE_NAME }}

 

 

Please note that the above example can be used for any Application Stack deployment using file compression technique for both Linux and Windows App Services.

If you have any questions or feedback, please add a comment.

Co-Authors
Version history
Last update:
‎Jan 04 2023 06:15 AM
Updated by: