无法在 python 3.8 上使用 webapp 将 python 部署到 azure

Cannot deploy python with webapp to azure on python 3.8

我正在尝试使用 Azure CLI

将使用 Flask 框架的测试项目部署到 Azure 云中

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 才能成功部署。

app非常简单:

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 文件,其中包含 Microsoft 文档中推荐的所需软件包。

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 门户并尝试将 Stack settings 更改为 XXXXXX-blf -> Settings -> Configuration -> General settings -> Stack | Major version / Minor version 下的目标 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

我检查了日志 url 问题是这样的:

{
   "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 操作确实部署在我的 webapp 运行ning [=74= 推送上] 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 }}

有什么想法吗?

根据你的描述和提供的教程,我也发现了这个问题。并且在the official documentation中,az webapp up命令的参数不支持指定的python版本。

如果一定要使用az webapp up命令,目前应该是不行的。我认为这是一个错误,您可以在传送门上raise a support ticket确认。

我给出一个替代方案,你可以使用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进行部署。这样的话每次修改提交后应用都会自动部署