【问题标题】:Google AppEngine: 502 Bad Gateway From Deploying Flask AppGoogle AppEngine:部署 Flask 应用程序时出现 502 Bad Gateway
【发布时间】:2020-02-06 04:40:17
【问题描述】:

在将应用程序部署到 Google AppEngine 后,我从远程服务器启动应用程序时遇到了很多麻烦。我查找了类似的问题并尝试应用建议的修复程序,但仍然没有成功 - 我不断收到 502 Bad Gateway 问题。有人可以建议吗?

文件夹结构是这样的:

目录:cross_sell_dash/
app.yml
数据库.py
Dockerfile
gcp-sa-creds.json
main.py
要求.txt

app.yml

entrypoint: "gunicorn --bind:$PORT main:app"
env: flex
runtime: custom

main.py

app = Flask(__name__)

@app.route("/call/<function_name>/search/", methods=["GET"])
def callFunction(function_name: str):
    user_id = request.args.get('user_id')
    savm_id = request.args.get('savm_id')
    business_sub_entity = request.args.get('business_sub_entity')
    user_comments = request.args.get('user_comments')
    user_approval = request.args.get('user_approval')
    functionToCall = getattr(Database(), function_name)
    return str(functionToCall(user_id, savm_id, business_sub_entity, user_comments, user_approval))

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8080, debug=True)

Dockerfile

FROM python:3-onbuild

RUN mkdir /app
ADD . /app

WORKDIR /app

RUN pip3 --no-cache-dir install -r requirements.txt

EXPOSE 8080

ENTRYPOINT ["python3", "main.py"]
ENTRYPOINT ["gunicorn","--bind=0.0.0.0:8080","main:app"]

【问题讨论】:

  • 嘿,这在本地有效吗?它只在 GAE 上失败?您能否也发布您的 requirements.txt ?你能解释一下为什么你使用 python:3-onbuild 而不仅仅是 python3 吗?您的 VM 实例是否正常运行?当应用程序无法响应请求时,通常会发生错误网关。 (可能从未初始化或崩溃)让我知道。

标签: python google-app-engine debugging flask


【解决方案1】:
  • 删除 app.yaml 中的entrypoint
  • 更新Dockerfile如下
FROM python:3-onbuild

RUN mkdir /app
ADD . /app

WORKDIR /app

RUN pip3 --no-cache-dir install -r requirements.txt

EXPOSE 8080

ENTRYPOINT ["gunicorn", "--bind=0.0.0.0:8080", "main:app"]

【讨论】:

  • 请让我知道如何在使用此命令安装时包含要应用的 Dockerfile 的信息:gcloud app deploy;显然,它没有考虑 Dockerfile 中的信息。
猜你喜欢
  • 2021-05-31
  • 2020-08-24
  • 2013-07-16
  • 2021-10-02
  • 1970-01-01
  • 2019-07-27
  • 2018-08-22
  • 1970-01-01
  • 2020-12-14
相关资源
最近更新 更多