gpt4 book ai didi

python - 无法在 python 3.8 上将带有 webapp 的 python 部署到 azure

转载 作者:行者123 更新时间:2023-12-05 06:14:47 25 4
gpt4 key购买 nike

我正在尝试使用 Azure CLI 将使用 Flask 框架的测试项目部署到 Azure 云中

https://learn.microsoft.com/en-us/azure/app-service/containers/quickstart-python?tabs=bash

https://learn.microsoft.com/en-us/azure/app-service/containers/how-to-configure-python

我的应用的 runtime_version 存在一些问题。每次我尝试运行部署命令时,它都会尝试将runtime_version升级到python|3.7,即使我在设置中将其设置为python|3.8,然后部署失败。必须将其设置为 python|3.7 才能成功部署。

应用程序非常简单:

from flask import Flask
from markupsafe import escape

app = Flask(__name__)

@app.route('/')
def index():
return 'Index page'

@app.route('/hello')
def hello_world():
return 'Hello, World!!!'

@app.route('/user/<username>')
def show_user_profile(username):
# show the user profile for that user
return 'User %s' % escape(username)

@app.route('/post/<int:post_id>')
def show_post(post_id):
# show the post with the given id, the id is an int
return 'Post %d' % post_id

@app.route('/path/<path:subpath>')
def show_subpath(subpath):
# show the subpath after /path/
return 'Subpath %s' % escape(subpath)

@app.route('/projects/')
def projects():
return 'The project page'

@app.route('/about')
def about():
return 'The about page'

我还按照 Microsoft 文档中的建议创建了一个 requirements.txt 文件,其中包含所需的软件包。

click==7.1.2
flask==1.1.2
itsdangerous==1.1.0
jinja2==2.11.2
markupsafe==1.1.1
werkzeug==1.0.1

这是我第一次部署应用程序时使用的命令

az webapp up --sku F1 -l westeurope -n XXXXXX-blf

输出:

(venv) D:\dev\FlaskTesting [master ≡ +4 ~0 -1 !]> az webapp up --sku F1 -l westeurope -n XXXXXX-blf
webapp XXXXXX-blf doesn't exist
Creating Resource group 'InsaneSpeech_rg_Linux_westeurope' ...
Resource group creation complete
Creating AppServicePlan 'InsaneSpeech_asp_Linux_westeurope_0' ...
Creating webapp 'XXXXXX-blf' ...
Creating zip with contents of dir D:\dev\FlaskTesting ...
Getting scm site credentials for zip deployment
Starting zip deployment. This operation can take a while to complete ...
Deployment endpoint responded with status code 202
You can launch the app at http://XXXXXX-blf.azurewebsites.net
{
"URL": "http://XXXXXX-blf.azurewebsites.net",
"appserviceplan": "InsaneSpeech_asp_Linux_westeurope_0",
"location": "westeurope",
"name": "XXXXXX-blf",
"os": "Linux",
"resourcegroup": "InsaneSpeech_rg_Linux_westeurope",
"runtime_version": "python|3.7",
"runtime_version_detected": "-",
"src_path": "D:\\dev\\FlaskTesting"
}

然后,我转到 Azure 门户,并尝试在 XXXXXX-blf -> 设置 -> 配置 -> 下将 Stack 设置 更改为目标 Python 3.8常规设置->堆栈|主要版本/次要版本单击“保存”后,我尝试再次运行命令来更新我的代码

az webapp up -n python-blf

但是这次输出显示错误:

Webapp XXXXXX-blf already exists. The command will deploy contents to the existing app.
Updating runtime version from PYTHON|3.8 to python|3.7
Creating zip with contents of dir D:\dev\FlaskTesting ...
Getting scm site credentials for zip deployment
Starting zip deployment. This operation can take a while to complete ...
Deployment endpoint responded with status code 202
Configuring default logging for the app, if not already enabled
Zip deployment failed. {'id': 'd9ff6c84c00844bf9f988bd4c98c81d6', 'status': 3, 'status_text': '',
'author_email': 'N/A', 'author': 'N/A', 'deployer': 'Push-Deployer', 'message': 'Created via a push deployment',
'progress': '', 'received_time': '2020-07-05T09:10:02.1802651Z', 'start_time': '2020-07-05T09:10:02.3953194Z',
'end_time': '2020-07-05T09:10:18.7991349Z',
'last_success_end_time': None, 'complete': True, 'active': False, 'is_temp': False, 'is_readonly': True,
'url': 'https://XXXXXX-blf.scm.azurewebsites.net/api/deployments/latest',
'log_url': 'https://XXXXXX-blf.scm.azurewebsites.net/api/deployments/latest/log', 'site_name': 'XXXXXX-blf'}.
Please run the command az webapp log deployment show
-n XXXXXX-blf -g InsaneSpeech_rg_Linux_westeurope

我检查了日志网址,这就是问题所在:

{
"ClassName":"System.IO.FileNotFoundException",
"Message":"No log found for 'latest'.",
"Data":null,
"InnerException":null,
"HelpURL":null,
"StackTraceString":" at Kudu.Core.Deployment.DeploymentManager.GetLogEntries(String id) in /tmp/KuduLite/Kudu.Core/Deployment/DeploymentManager.cs:line 111\n at Kudu.Services.Deployment.DeploymentController.GetLogEntry(String id) in /tmp/KuduLite/Kudu.Services/Deployment/DeploymentController.cs:line 432",
"RemoteStackTraceString":null,
"RemoteStackIndex":0,
"ExceptionMethod":null,
"HResult":-2147024894,
"Source":"Kudu.Core",
"WatsonBuckets":null,
"FileNotFound_FileName":null,
"FileNotFound_FusionLog":null
}

出现此问题后,无需更改任何内容,我可以再次运行相同的命令并获得正确的部署,但使用 python|3.7 ...

(venv) D:\dev\FlaskTesting [master ≡ +5 ~0 -1 !]> az webapp up -n XXXXXX-blf
Webapp XXXXXX-blf already exists. The command will deploy contents to the existing app.
Creating zip with contents of dir D:\dev\FlaskTesting ...
Getting scm site credentials for zip deployment
Starting zip deployment. This operation can take a while to complete ...
Deployment endpoint responded with status code 202
You can launch the app at http://XXXXXX-blf.azurewebsites.net
{
"URL": "http://XXXXXX-blf.azurewebsites.net",
"appserviceplan": "InsaneSpeech_asp_Linux_westeurope_0",
"location": "westeurope",
"name": "XXXXXX-blf",
"os": "Linux",
"resourcegroup": "InsaneSpeech_rg_Linux_westeurope",
"runtime_version": "python|3.7",
"runtime_version_detected": "-",
"sku": "FREE",
"src_path": "D:\\dev\\FlaskTesting"
}

更新

我已经在 azure 中配置了链接到我的 github 存储库的 CI\CD,并且 github 操作确实通过运行 python 3.8 的 web 应用程序进行了推送部署

# Docs for the Azure Web Apps Deploy action: https://github.com/Azure/webapps-deploy
# More GitHub Actions for Azure: https://github.com/Azure/actions

name: Build and deploy Python app to Azure Web App - XXXXXX-blf

on:
push:
branches:
- master

jobs:
build-and-deploy:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@master

- name: Set up Python version
uses: actions/setup-python@v1
with:
python-version: '3.8'

- name: Build using AppService-Build
uses: azure/appservice-build@v1
with:
platform: python
platform-version: '3.8'

- name: 'Deploy to Azure Web App'
uses: azure/webapps-deploy@v1
with:
app-name: 'XXXXXX-blf'
slot-name: 'production'
publish-profile: ${{ XXXXXXXXXXXXXXXXXXX }}

有什么想法吗?

最佳答案

经过您的描述和提供的教程,我也发现了这个问题。并在 the official documentationaz webapp up命令的参数不支持指定的python版本。

如果必须使用 az webapp up 命令,目前应该不可能。我认为这是一个错误,您可以在门户上提出支持票进行确认。

我给出了一个替代解决方案,你可以使用continuous deployment 。您可以使用git。如果代码保密,也可以自己在本地创建git存储服务,使用 local git用于部署。在这种情况下,应用程序将在每次提交修改后自动部署。

关于python - 无法在 python 3.8 上将带有 webapp 的 python 部署到 azure,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62739006/

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