添加Python模块google-cloud-storage导致一个正常工作的Azure函数应用出现问题。

huangapple go评论64阅读模式
英文:

Adding python module google-cloud-storage is causing a WORKING Azure Function App to BREAK

问题

I am going to be using the test function that VS-code azure extension auto creates as a "simple" case for this problem.

我将使用VS Code Azure扩展自动创建的测试函数作为这个问题的"简单"案例。

I can add any modules (pandas, requests, facebook) in requirements.txt and it works fine. However when I add google-cloud-storage, my function breaks and only returns 500.

我可以在requirements.txt中添加任何模块(pandas、requests、facebook),它都能正常工作。但是当我添加google-cloud-storage时,我的函数就会崩溃,并且只返回500。

I should note it only breaks when testing on Azure, when run locally it works fine.

我应该注意到,只有在Azure上测试时它才会崩溃,在本地运行时它工作正常。

Also, if the function is created in the Azure Portal (rather than connecting to Github) and google-cloud-storage is pip installed using ssh, then the function also works fine.

此外,如果函数是在Azure门户中创建的(而不是连接到GitHub),并且使用ssh安装了google-cloud-storage,那么函数也可以正常工作。

It seems to be when VS-code is being used to deploy the function with 'google-cloud-storage' in requirements.txt that we get problems. Anyway, thats what I've found, any help would be appreciated.

似乎是当使用VS Code部署带有'requirements.txt'中的'google-cloud-storage'的函数时,我们会遇到问题。不管怎样,这就是我发现的情况,任何帮助都将不胜感激。

How to reproduce:

如何复制:

Step 1: Created Function App

步骤1:创建函数应用程序

This function App uses:
App Service Plan, Basic B1 (100 total ACU, 1.75 GB memory, 1 vCPU)
enter image description here
Can only do Linux as windows isnt supported when selecting python

这个函数应用程序使用:
App Service Plan,Basic B1(100个总ACU,1.75GB内存,1个vCPU)
在此输入图像描述
只能选择Linux,因为在选择Python时不支持Windows

Step 2: The default function is created with VS-code azure extension
https://i.stack.imgur.com/XBLpV.png

步骤2:使用VS Code Azure扩展创建默认函数
https://i.stack.imgur.com/XBLpV.png

The function looks like this
enter image description here

函数看起来像这样
在此输入图像描述

Step3: I now add this to my github repository and which then gets picked up by the Azure App service to deploy as a function. Using the function app is connected to the repo
enter image description here

步骤3:现在我将这个函数添加到我的GitHub存储库中,然后Azure App服务会将其拾取并部署为一个函数。使用函数应用程序连接到存储库
在此输入图像描述

We have success without google-cloud-storage in requirements.txt
enter image description here

在requirements.txt中没有google-cloud-storage的情况下,我们取得了成功
在此输入图像描述

Now we add google-cloud-storage:
enter image description here
we then git push this to our repo and Azure creates our deployment

现在我们添加google-cloud-storage:
在此输入图像描述
然后我们将其推送到我们的存储库,Azure会创建我们的部署

When we try to test the function now, we get consistent 500 results with no logs.
enter image description here

现在当我们尝试测试函数时,我们得到了一致的500结果,没有日志。

I want to continue to using the Git-hub approach, so a solution where we keep the same process would be great but any advice will be amazing. Thanks in advance guys.

我想继续使用GitHub的方法,所以希望能找到一个保持相同流程的解决方案,但任何建议都将令人惊讶。提前感谢各位。

Tried pip installing google-cloud-storage manually using ssh and then deploying with VS-code, that broke that whole function app.

尝试使用SSH手动安装google-cloud-storage,然后使用VS Code进行部署,但这破坏了整个函数应用程序。

英文:

I am going to be using the test function that VS-code azure extension auto creates as a "simple" case for this problem.

I can add any modules (pandas, requests, facebook) in requirements.txt and it works fine. However when I add google-cloud-storage, my function breaks and only returns 500.

I should note it only breaks when testing on Azure, when run locally it works fine

Also, if the function is created in the Azure Portal (rather than connecting to Github) and google-cloud-storage is pip installed using ssh, then the function also works fine.

It seems to be when VS-code is being used to deploy the function with 'google-cloud-storage' in requirements.txt that we get problems. Anyway, thats what I've found, any help would be appreciated

**How to reproduce:
**
**Step 1: **Created Function App

This function App uses:
App Service Plan, Basic B1 (100 total ACU, 1.75 GB memory, 1 vCPU)
enter image description here
Can only do Linux as windows isnt supported when selecting python

**Step 2: **The default function is created with VS-code azure extension
https://i.stack.imgur.com/XBLpV.png

The function looks like this
enter image description here

Step3: I now add this to my github repository and which then gets picked up by the Azure App service to deploy as a function. Using the function app is connected to the repo
enter image description here

We have success without google-cloud-storage in requirements.txt
enter image description here

Now we add google-cloud-storage:
enter image description here
we then git push this to our repo and Azure creates our deployment

When we try to test the function now, we get consistent 500 results with no logs.
enter image description here

I want to continue to using the Git-hub approach, so a solution where we keep the same process would be great but any advice will be amazing. Thanks in advance guys.

Tried pip installing google-cloud-storage manually using ssh and then deploying with VS-code, that broke that whole function app.

答案1

得分: 1

我已将google-cloud-storage添加到我的requirements.txt文件中,我的Azure函数Http存储库的文件夹结构如下所示:

  • Init.py和function.json位于HttpTrigger文件夹内,其余所有文件位于根目录外,包括requirements.txt:

添加Python模块google-cloud-storage导致一个正常工作的Azure函数应用出现问题。

现在,我创建了Azure函数应用,选择了Functions Premium计划并选择了Python 3.10:

添加Python模块google-cloud-storage导致一个正常工作的Azure函数应用出现问题。

在部署了我的函数应用后,我转到部署中心,将我的函数连接到上面的GitHub存储库,并启动了GitHub工作流程:

添加Python模块google-cloud-storage导致一个正常工作的Azure函数应用出现问题。

我的GitHub工作流程:

您可以在此处找到我的GitHub工作流程。

name: 构建并部署Python项目到Azure函数应用 - siliconfunc1

on:
  push:
    branches:
      - main
  workflow_dispatch:

env:
  AZURE_FUNCTIONAPP_PACKAGE_PATH: '.' # 设置为您的Web应用项目的路径,默认为存储库根目录
  PYTHON_VERSION: '3.10' # 设置要使用的Python版本(支持3.6、3.7、3.8)

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: 检出存储库
        uses: actions/checkout@v2

      - name: 设置Python版本
        uses: actions/setup-python@v1
        with:
          python-version: ${{ env.PYTHON_VERSION }}

      - name: 创建并启动虚拟环境
        run: |
          python -m venv venv
          source venv/bin/activate          
      - name: 安装依赖项
        run: pip install -r requirements.txt
        
      # 可选:在此处添加运行测试的步骤

      - name: 上传部署作业的工件
        uses: actions/upload-artifact@v2
        with:
          name: python-app
          path: |
            . 
            !venv/            
  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-function.outputs.webapp-url }}

    steps:
      - name: 从构建作业下载工件
        uses: actions/download-artifact@v2
        with:
          name: python-app
          path: .

      - name: '部署到Azure函数'
        uses: Azure/functions-action@v1
        id: deploy-to-function
        with:
          app-name: 'siliconfunc1'
          slot-name: 'Production'
          package: ${{ env.AZURE_FUNCTIONAPP_PACKAGE_PATH }}
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_D29DD8E1DA1B41A68C550903EEF23B74 }}
          scm-do-build-during-deployment: true
          enable-oryx-build: true

输出:

***HttpTrigger已成功部署,当我

英文:

I have added google-cloud-storage in my requirements.txt and my azure function Http repository is in the folder structure like below:-

Init.py and function.json are inside HttpTrigger folder and rest all the files are outside it in the root directory, Including requirements.txt:-

添加Python模块google-cloud-storage导致一个正常工作的Azure函数应用出现问题。

Now, I created Azure Function app with Functions Premium plan and selected Python 3.10:-

添加Python模块google-cloud-storage导致一个正常工作的Azure函数应用出现问题。

After my function app Deployment, I went to Deployment Center and connected my Function to the github repository above and started the github workflow:-

添加Python模块google-cloud-storage导致一个正常工作的Azure函数应用出现问题。

My Github workflow:-

You can find my Github workflow from here

name: Build and deploy Python project to Azure Function App - siliconfunc1

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.10' # 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@v2

      - 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: Upload artifact for deployment job
        uses: actions/upload-artifact@v2
        with:
          name: python-app
          path: |
            . 
            !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@v2
        with:
          name: python-app
          path: .

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

Output:-

> The HttpTrigger got deployed successfully, and when I ran the function I received the same error code as yours. But when I checked the Logs I saw an error related to protobuf package that was restricting Azure Function HttpTrigger from running successfully, Refer below:-

Error:-

添加Python模块google-cloud-storage导致一个正常工作的Azure函数应用出现问题。

2023-06-15T08:21:20.763 [Error] TypeError: Descriptors cannot not be created directly.
2023-06-15T08:21:20.826 [Information] If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
2023-06-15T08:21:20.827 [Information] If you cannot immediately regenerate your protos, some other possible workarounds are:
2023-06-15T08:21:20.827 [Information] 1. Downgrade the protobuf package to 3.20.x or lower.
2023-06-15T08:21:20.827 [Information] 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

I referred this SO thread answer by Kushan Gunasekara and added protobuf==3.20. along with google-cloud-storage in my requirements.txt and ran the deployment again, And after the HttpTrigger was deployed it ran successfully, Refer below:-*

My updated requirements.txt:-

azure-functions
protobuf==3.20.*
google-cloud-storage

添加Python模块google-cloud-storage导致一个正常工作的Azure函数应用出现问题。

添加Python模块google-cloud-storage导致一个正常工作的Azure函数应用出现问题。

添加Python模块google-cloud-storage导致一个正常工作的Azure函数应用出现问题。

添加Python模块google-cloud-storage导致一个正常工作的Azure函数应用出现问题。

添加Python模块google-cloud-storage导致一个正常工作的Azure函数应用出现问题。

huangapple
  • 本文由 发表于 2023年6月15日 10:18:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/76478668.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定