gpt4 book ai didi

python - Azure应用程序服务-应用程序不在根目录中

转载 作者:行者123 更新时间:2023-12-02 22:55:32 26 4
gpt4 key购买 nike

我有一个单一存储库,其中包含多个应用程序。我尝试部署的应用程序位于rest_api 目录中。 github actions中看到部署成功,但是启动失败。

这是我的启动命令gunicorn -w 1 -k uvicorn.workers.UvicornWorker main:app

这就是 github 操作文件的样子:

name: Deploy rest_api (dev) to Azure

env:
AZURE_WEBAPP_NAME: 'xxx-rest-api'
PYTHON_VERSION: '3.11'

on:
push:
branches: [ "dev" ]
workflow_dispatch:

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Python version
uses: actions/<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="90e3f5e4e5e0bde0e9e4f8fffed0e6a3bea0bea0" rel="noreferrer noopener nofollow">[email protected]</a>
with:
python-version: ${{ env.PYTHON_VERSION }}
cache: 'pip'

- name: Create and start virtual environment
working-directory: rest_api
run: |
python -m venv venv
source venv/bin/activate

- name: Install dependencies
working-directory: rest_api
run: |
pip install --upgrade pip
pip install -r requirements/base.txt

- name: Upload artifact for deployment jobs
uses: actions/upload-artifact@v3
with:
name: python-app
path: |
rest_api
!venv/
!rest_api/venv/

deploy:
permissions:
contents: none
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@v3
with:
name: python-app
path: rest_api

- name: 'Deploy to Azure Web App'
id: deploy-to-webapp
uses: azure/webapps-deploy@v2
with:
app-name: ${{ env.AZURE_WEBAPP_NAME }}
publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_A79D58476BA645D1BF1A6116201A6E5F }}
package: rest_api

这是错误:

2023-03-27T08:52:28.865320556Z Launching oryx with: create-script -appPath /home/site/wwwroot -output /opt/startup/startup.sh -virtualEnvName antenv -defaultApp /opt/defaultsite -userStartupCommand 'gunicorn -w 1 -k uvicorn.workers.UvicornWorker main:app'
2023-03-27T08:52:28.925294508Z Cound not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
2023-03-27T08:52:28.925870805Z Could not find operation ID in manifest. Generating an operation id...
2023-03-27T08:52:28.925880705Z Build Operation ID: d2e6df02-e71b-45fd-b84c-a0d9d8114831
2023-03-27T08:52:29.307010231Z Oryx Version: 0.2.20230103.1, Commit: df89ea1db9625a86ba583272ce002847c18f94fe, ReleaseTagName: 20230103.1
2023-03-27T08:52:29.354907333Z Writing output script to '/opt/startup/startup.sh'
2023-03-27T08:52:29.472048349Z WARNING: Could not find virtual environment directory /home/site/wwwroot/antenv.
2023-03-27T08:52:29.491003271Z WARNING: Could not find package directory /home/site/wwwroot/__oryx_packages__.
2023-03-27T08:52:30.408188883Z
2023-03-27T08:52:30.408226683Z Error: class uri 'uvicorn.workers.UvicornWorker' invalid or not found:
2023-03-27T08:52:30.408231383Z
2023-03-27T08:52:30.408234383Z [Traceback (most recent call last):
2023-03-27T08:52:30.408237183Z File "/opt/python/3.11.1/lib/python3.11/site-packages/gunicorn/util.py", line 99, in load_class
2023-03-27T08:52:30.408240383Z mod = importlib.import_module('.'.join(components))
2023-03-27T08:52:30.408243083Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-03-27T08:52:30.408245783Z File "/opt/python/3.11.1/lib/python3.11/importlib/__init__.py", line 126, in import_module
2023-03-27T08:52:30.408248583Z return _bootstrap._gcd_import(name[level:], package, level)
2023-03-27T08:52:30.408251383Z ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2023-03-27T08:52:30.408262283Z File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
2023-03-27T08:52:30.408265483Z File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
2023-03-27T08:52:30.408268383Z File "<frozen importlib._bootstrap>", line 1128, in _find_and_load_unlocked
2023-03-27T08:52:30.408271083Z File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
2023-03-27T08:52:30.408273883Z File "<frozen importlib._bootstrap>", line 1206, in _gcd_import
2023-03-27T08:52:30.408276583Z File "<frozen importlib._bootstrap>", line 1178, in _find_and_load
2023-03-27T08:52:30.408279383Z File "<frozen importlib._bootstrap>", line 1142, in _find_and_load_unlocked
2023-03-27T08:52:30.408282083Z ModuleNotFoundError: No module named 'uvicorn'
2023-03-27T08:52:30.408284783Z ]

我的预感是该错误与应用程序和 virtualenv 不在根目录中有关。

最佳答案

我发现问题是需求不在rest_api/requirements.txt中,而是在rest_api/requirements/requirements.txt中。

关于python - Azure应用程序服务-应用程序不在根目录中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/75853973/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com