Slow Azure functions deployment

143 views Asked by At

I have a Node.js Azure Function in TypeScript. When I deploy, it takes like 25 minutes to deploy.

Those are pretty basic functions with Prisma ORM. Building locally takes couple seconds only.

Is that normal? I also have the WEBSITE_RUN_FROM_PACKAGE = 1 in my Azure Function configuration.

Here are my project dependencies in my package.json:

"dependencies": {
    "@azure/functions": "^4.0.0",
    "@prisma/client": "5.6.0",
    "crypto": "^1.0.1",
    "jsonwebtoken": "^9.0.2",
    "prisma": "^5.6.0"
  },
  "devDependencies": {
    "@types/node": "18.x",
    "concurrently": "^8.2.2",
    "rimraf": "^5.0.0",
    "typescript": "^4.0.0"
  }
2

There are 2 answers

0
Charles Fonseca On BEST ANSWER

The problem is likely caused by the new yaml Github Actions that are automatically generated by Azure, which first build, upload, and then download the artifact in the next step to actually deploy it.

This new yaml deployment template is useful when Azure fails to deploy even though your build is correct. My recommendation is to use the 'old' deployment method that does not upload the artifact to any storage rather than the Azure method.

name: xxxxxx

on:
  push:
    branches:
      - xxxx
  workflow_dispatch:

env:
  AZURE_FUNCTIONAPP_PACKAGE_PATH: '.'
  NODE_VERSION: '18.x'

jobs:
  build-and-deploy:
    runs-on: windows-latest
    steps:
      - name: 'Checkout GitHub Action'
        uses: actions/checkout@v2

      - name: Setup Node ${{ env.NODE_VERSION }} Environment
        uses: actions/setup-node@v1
        with:
          node-version: ${{ env.NODE_VERSION }}

      - name: 'Resolve Project Dependencies Using Npm'
        shell: pwsh
        run: |
          pushd './${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}'
          npm install
          npm run build --if-present
          npm run test --if-present
          popd

      - name: 'Run Azure Functions Action'
        uses: Azure/[email protected]
        id: fa
        with:
          app-name: 'xxxxxxxx'
          slot-name: 'production'
          package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
          publish-profile: ${{ secrets.AzureAppService_xxxxxxxxxxxxxx }}
0
Pravallika KV On
  • To avoid delay and speed up the deployment, use remote build. Azure Functions can automatically perform builds on the code it receives after zip deployments.
  • Compress all the dependencies and project files into zip file and deploy to function app using the command:
az functionapp deployment source config-zip -g v-pravallika-mindtree -n kpnodefn --src kpnodefn.zip --build-remote true --verbose

Add Application Setting WEBSITE_RUN_FROM_PACKAGE=1 in the Function App's Configuration before deploying the function app.

  • I have created a NodeJs Http Triggered Azure Function.
  • Created a NodeJs Function App with Consumption Plan(Windows).

Application Settings of my Function App:

enter image description here

  • Deploying the function project as zip to Azure as shown below:

enter image description here

If you still face delay in deployment, use Run from Package deployment. (with the setting WEBSITE_RUN_FROM_PACKAGE=<storage_url>) or Bundle your node_modules with WebPack. Refer MSDOC.

References:

  1. Package your Node.js Functions for Azure Functions
  2. https://stackoverflow.com/a/51942391/19991670