Jump to content

How to reduce the deployment time using the file compression technique in Azure App Service


Recommended Posts

Guest sarkarsa
Posted

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:

 

560x251vv2.jpg.8a8f5e5d56b2141c46245d6a463ed268.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: GitHub - Azure/webapps-deploy: Enable GitHub developers to deploy to Azure WebApps using GitHub Actions

# More GitHub Actions for Azure: GitHub - Azure/actions: Author and use Azure Actions to automate your GitHub workflows

 

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 GitHub - Azure/actions: Author and use Azure Actions to automate your GitHub workflows

#

# 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:

 

559x260vv2.jpg.4597278d5da80823b5bee256baea745c.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: GitHub - Azure/webapps-deploy: Enable GitHub developers to deploy to Azure WebApps using GitHub Actions

# More GitHub Actions for Azure: GitHub - Azure/actions: Author and use Azure Actions to automate your GitHub workflows

 

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 GitHub - Azure/actions: Author and use Azure Actions to automate your GitHub workflows

#

# 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.

 

Continue reading...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...