无法在 python 3.8 上使用 webapp 将 python 部署到 azure [英] Cannot deploy python with webapp to azure on python 3.8

查看:36
本文介绍了无法在 python 3.8 上使用 webapp 将 python 部署到 azure的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Azure CLI

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

https://docs.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 才能成功部署.

There are some issues regarding the runtime_version of my app. Everytime I try to run the command for deploying it tries to upgrade the runtime_version to the python|3.7 even if I set it to the python|3.8 in the settings and then the deployment fails. It has to be set to python|3.7 to be succesfully deployed.

应用非常简单:

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'

我还创建了一个 requirements.txt 文件,其中包含微软文档中推荐的所需包.

I also created a requirements.txt file with the required packages as recommended in the microsoft documentation.

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

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

And this is the command I used to deploy the application the first time

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

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 门户并尝试将 Stack settings 更改为目标 XXXXXX-blf 下的 Python 3.8 ->设置 ->配置 ->一般设置 ->堆栈 |主要版本/次要版本单击保存后,我尝试再次运行该命令以更新我的代码

Then I go to the azure portal and try to change the Stack settings to target Python 3.8 under XXXXXX-blf -> Settings -> Configuration -> General settings -> Stack | Major version / Minor version After clicking save I try to run again the command to update my code

az webapp up -n python-blf

az webapp up -n python-blf

但是这次输出显示错误:

But this time the output shows an error:

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

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

I check the log url and this is the issue:

{
   "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 ...

After this issue, without changing anything I can run the same command again and get a correct deployment but with 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 中配置了 CI\CD 链接到我的 github 存储库,并且 github 操作确实在使用运行 python 3.8 的 webapp 时部署推送

I have configured the CI\CD in azure linked to my github repository and the github actions do deploy on push with my webapp running python 3.8

# 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 }}

有什么想法吗?

推荐答案

经过你的描述和提供的教程,我也发现了这个问题.而在 官方文档az webapp up命令的参数不支持指定的python版本.

After your description and the tutorial provided, I also found this problem. And in the official documentation, the parameters of the az webapp up command do not support the specified python version.

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

If you must use the az webapp up command, it should not be possible at present. I think this is a bug, you can raise a support ticket on the portal to confirm.

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

I give an alternative solution, you can use continuous deployment. You can use git. If the code is confidential, you can also use your own to create a git storage service locally and use local git for deployment. In this case, the application will be automatically deployed after each modification is submitted.

这篇关于无法在 python 3.8 上使用 webapp 将 python 部署到 azure的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆