首页 > 解决方案 > 如何为烧瓶 azure Web 应用程序设置启动命令

问题描述

我创建了一个简单的烧瓶 Web 应用程序,并设法使用 CI/CD 从 azure devops 将其发布到 azure Web 应用程序。除了启动我的应用程序外,管道都在工作。

如果我查看 webapp 中的日志文件,就会出现 -

日志文件 default_docker.log:

    2020-01-08T13:04:17.017575225Z Documentation: http://aka.ms/webapp-linux
    2020-01-08T13:04:17.017579025Z Python 3.7.5
    2020-01-08T13:04:17.017582725Z Note: Any data outside '/home' is not persisted
    2020-01-08T13:04:17.093756525Z Starting OpenBSD Secure Shell server: sshd.
    2020-01-08T13:04:17.109540649Z Site's appCommandLine: gunicorn --bind = 0.0.0.0 --timeout 600 app: application
    2020-01-08T13:04:17.110379356Z Launching oryx with: -appPath /home/site/wwwroot -output /opt/startup/startup.sh -virtualEnvName antenv -defaultApp /opt/defaultsite -bindPort 8000 -userStartupCommand 'gunicorn --bind = 0.0.0.0 --timeout 600 app: application'
    2020-01-08T13:04:17.114336587Z Oryx Version: 0.2.20191105.2, Commit: 67e159d71419415435cb5d10c05a0f0758ee8809, ReleaseTagName: 20191105.2
    2020-01-08T13:04:17.116548105Z Found build manifest file at '/home/site/wwwroot/oryx-manifest.toml'. Deserializing it...
    2020-01-08T13:04:17.118951024Z Build Operation ID: |DGaRVt5jG5c=.2a144509_
    2020-01-08T13:04:17.554659456Z Writing output script to '/opt/startup/startup.sh'
    2020-01-08T13:04:17.784203265Z Found virtual environment .tar.gz archive.
    2020-01-08T13:04:17.784884970Z Removing existing virtual environment directory /antenv...
    2020-01-08T13:04:17.788272497Z Extracting to directory /antenv...
    2020-01-08T13:04:32.810295030Z Using packages from virtual environment antenv located at /antenv.
    2020-01-08T13:04:32.817794689Z Updated PYTHONPATH to ':/antenv/lib/python3.7/site-packages'
    2020-01-08T13:04:36.780635398Z usage: gunicorn [OPTIONS] [APP_MODULE]
    2020-01-08T13:04:36.780670499Z gunicorn: error: unrecognized arguments: app: application

我的简化应用程序树视图看起来像这样 -

    test_app/
      venv/
      application/
        templates/
        __init__.py
        routes.py
        errors.py
        models.py
        forms.py
      app.py

我在 azure 门户“常规设置”中尝试了不同的启动命令,但没有解决方案

gunicorn --bind=0.0.0.0 --timeout 600  app:application

编辑:添加 app.py 和init .py

应用程序.py:

from application import app, db
from application.models import User, Post

@app.shell_context_processor
def make_shell_context():
    return {'db': db, 'User': User, 'Post': Post, 'Classrooms' : Classrooms, 'ClassSession' : ClassSession, 'Teacher' : Teacher}

初始化.py

from flask import Flask
from config import Config
from flask_sqlalchemy import SQLAlchemy
from flask_migrate import Migrate
from flask_login import LoginManager
from logging.handlers import RotatingFileHandler
import os
from flask_bootstrap import Bootstrap
import logging

app = Flask(__name__)
app.config.from_object(Config)
db = SQLAlchemy(app)
migrate = Migrate(app, db)
login = LoginManager(app)
login.login_view = 'login'
bootstrap = Bootstrap(app)

from application import routes, models, errors

if __name__ == '__main__':
    # * --- DEBUG MODE: --- *
    app.run(host='127.0.0.1', port=5000, debug=True)

谁能指出我可以解决这个愚蠢问题的方向。多谢!!

标签: pythonazureflask

解决方案


gunicorn 命令实际上并不指向 WSGIapp对象。试试这个:

gunicorn --bind=0.0.0.0 --timeout 600  application:app

推荐阅读