Azure 函数部署缓慢

问题描述 投票:0回答:2

我有一个 TypeScript 中的 Node.js Azure 函数。当我部署时,大约需要 25 分钟才能部署。

这些是 Prisma ORM 的基本功能。本地构建只需几秒钟。

这正常吗?我的 Azure Function 配置中也有

WEBSITE_RUN_FROM_PACKAGE = 1

这是我的

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"
  }
node.js typescript azure azure-functions azure-deployment
2个回答
0
投票
  • 为了避免延迟并加快部署速度,请使用远程构建。 Azure Functions 可以在 zip 部署后收到的代码上自动执行构建。
  • 将所有依赖项和项目文件压缩为 zip 文件并使用以下命令部署到功能应用程序:
az functionapp deployment source config-zip -g v-pravallika-mindtree -n kpnodefn --src kpnodefn.zip --build-remote true --verbose

部署函数应用程序之前,在函数应用程序的配置中添加应用程序设置

WEBSITE_RUN_FROM_PACKAGE=1

  • 我创建了一个 NodeJs Http 触发的 Azure 函数
  • 创建了一个带有消费计划的 NodeJs 功能应用程序(Windows)。

我的功能应用程序的应用程序设置:

enter image description here

  • 将函数项目以 zip 形式部署到 Azure,如下所示:

enter image description here

如果您仍然面临部署延迟,请使用“从包运行”部署。 (使用设置

WEBSITE_RUN_FROM_PACKAGE=<storage_url>
)或将 node_modulesWebPack 捆绑在一起。 请参阅MSDOC

参考资料:

  1. 将 Node.js 函数打包为 Azure Functions
  2. https://stackoverflow.com/a/51942391/19991670

0
投票

该问题可能是由 Azure 自动生成的新 yaml Github Actions 引起的,它首先构建、上传,然后在下一步中下载工件以实际部署它。

即使您的构建正确,当 Azure 无法部署时,这个新的 yaml 部署模板非常有用。我的建议是使用不将工件上传到任何存储的“旧”部署方法,而不是 Azure 方法。

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 }}
© www.soinside.com 2019 - 2024. All rights reserved.