当我将函数应用程序存储库部署到新应用程序时,它无法识别任何函数 Azure/Python/FunctionApp

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

我使用 VSCode 插件创建了一个 Azure Function App。它上传良好并且应用程序按预期运行。我想将相同的功能部署到新应用程序中,因此我使用 ARM 模板创建了一个功能应用程序和存储帐户。然后我编写了一个新的 Github 操作,将存储库上传到新的 Function App。

部署顺利,Function App 与存储帐户正确连接。但Function App无法识别从存储库上传的函数。

这是我旧的 Github Action:


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

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v3
        with:
          name: python-app

      - name: Unzip artifact for deployment
        run: unzip release.zip

      - name: 'Deploy to Azure Functions'
        uses: Azure/functions-action@v1
        id: deploy-to-function
        env:
          TABLE_CONNECTION_STRING: ${{ secrets.TABLE_CONNECTION_STRING }}
        with:
          app-name: 'oldApp'
          slot-name: 'Production'
          package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE }}
          scm-do-build-during-deployment: true
          enable-oryx-build: true

这是来自新动作:

  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-function.outputs.webapp-url }}
    permissions:
      id-token: write #This is required for requesting the JWT

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v3
        with:
          name: python-app

      - name: Unzip artifact for deployment
        run: unzip release.zip

      - name: Login to Azure
        uses: azure/login@v1
        with:
          client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID }}
          tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID }}
          subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID }}

      - name: 'Deploy to Azure Functions'
        uses: Azure/functions-action@v1
        id: deploy-to-function
        with:
          app-name: 'newApp'
          slot-name: 'Production'
          package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
          scm-do-build-during-deployment: true
          enable-oryx-build: true

我尝试停止/重新启动并重置 FunctionApp。

我搜索并找到了使用调试控制台的建议,但我的计划不支持调试控制台。

我找到了检查

function.json
文件的建议,但我没有该文件,而且我原来的(工作)函数应用程序也没有
function.json

我比较了应用程序之间的配置。

FUNCTIONS_EXTENSION_VERSION
FUNCTIONS_WORKER_RUNTIME
WEBSITE_CONTENTSHARE
WEBSITE_CONTENTAZUREFILECONNECTIONSTRING
在这两个应用程序上都是正确的。新的设置为
WEBSITE_ENABLE_SYNC_UPDATE_SITE
,并且
WEBSITE_RUN_FROM_PACKAGE
设置为最新
Functionapp.zip
的路径。

正确的数据已上传到存储,但存储帐户文件共享中没有数据。

Github 存储库 有问题的操作位于“update-workflow”分支上。我最近更改了 main 上的操作,以使用新的应用程序名称和 PUBLISH_PROFILE 以及旧的操作脚本,并收到此错误:https://imgur.com/a/iq49KiJ

python azure azure-functions
1个回答
0
投票

我已经在你的项目根目录下添加了

local.settings.json
,并在我的环境中进行了测试:

local.settings.json:

{
    "IsEncrypted": false,
    "Values": {
      "FUNCTIONS_WORKER_RUNTIME": "python",
      "AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
      "AzureWebJobsStorage": "UseDevelopmentStorage=true"
    }
}
  • 已将代码推送到GitHub
  • 使用 GitHub 操作将函数部署到 Azure:

工作流程:

name: Build and deploy Python project to Azure Function App - <web_app_name>

on:
  push:
    branches:
      - main
  workflow_dispatch:

env:
  AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # set this to the path to your web app project, defaults to the repository root
  PYTHON_VERSION: '3.11' # set this to the python version to use (supports 3.6, 3.7, 3.8)

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Setup Python version
        uses: actions/setup-python@v1
        with:
          python-version: ${{ env.PYTHON_VERSION }}

      - name: Create and start virtual environment
        run: |
          python -m venv venv
          source venv/bin/activate
      - name: Install dependencies
        run: pip install -r requirements.txt

      # Optional: Add step to run tests here

      - name: Zip artifact for deployment
        run: zip release.zip ./* -r

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v3
        with:
          name: python-app
          path: |
            release.zip
            !venv/
  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-function.outputs.webapp-url }}
    
    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v3
        with:
          name: python-app

      - name: Unzip artifact for deployment
        run: unzip release.zip     
        
      - name: 'Deploy to Azure Functions'
        uses: Azure/functions-action@v1
        id: deploy-to-function
        with:
          app-name: '<web_app_name>'
          slot-name: 'Production'
          package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
          scm-do-build-during-deployment: true
          enable-oryx-build: true
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_123EC76XXXXF7E }}
  • 能够在 Azure 中部署函数应用程序并同步触发器:

enter image description here

  • 为了避免评论中提到的
    Authentication 401 error
    ,请在
    SCM Basic Auth Publishing Credentials
    中启用
    Function app=>Configuration=>Gerneral Settings

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.