Error : Cloud Run error: Container failed to start. Stop Execution of Container/Cloud Run once execution of Python is done

Error : Cloud Run error: Container failed to start. Stop Execution of Container/Cloud Run once execution of Python is done

我的要求是在 python 代码执行完成后停止 Cloud run/container 的执行。 任务是从云存储中获取文件,处理它们,然后将它们导出回云存储。 我能够顺利完成任务。但是云构建以以下错误结束。

“部署到云-运行”:错误:(gcloud.run.deploy)云运行错误:容器无法启动。无法启动然后侦听 PORT 环境变量定义的端口。此修订的日志可能包含更多信息。

CloudBuild.yml

- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '-t', 'gcr.io/$PROJECT_ID/reponame:latest', '-t', 'gcr.io/$PROJECT_ID/reponame:$COMMIT_SHA', '-t', 'gcr.io/$PROJECT_ID/reponame:$BUILD_ID', '.']
  id: 'build-image-reponame'
  waitFor: ['-']  # The '-' indicates that this step begins immediately.
- name: 'gcr.io/cloud-builders/docker'
  args: ['push', 'gcr.io/$PROJECT_ID/reponame:$COMMIT_SHA']
  id: 'push-image-to-container-registry'
  waitFor: ['build-image-reponame']
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
  entrypoint: gcloud
  args:
  - 'run'
  - 'deploy'
  - 'reponame'
  - '--image'
  - 'gcr.io/$PROJECT_ID/reponame:$COMMIT_SHA'
  - '--region'
  - 'us-east1'
  - '--platform'
  - 'managed'

  waitFor: ['push-image-to-container-registry']
  id: 'deploy-to-cloud-run'
images:
- 'gcr.io/$PROJECT_ID/reponame:latest'
- 'gcr.io/$PROJECT_ID/reponame:$COMMIT_SHA'
- 'gcr.io/$PROJECT_ID/reponame:$BUILD_ID'

您可以简单地依靠 getting started tutorial

对于你的代码,做这样的事情(代码从教程中获取并带有一些注释)

import os

from flask import Flask

app = Flask(__name__)


@app.route("/")
def hello_world():
    #name = os.environ.get("NAME", "World")
    #return "Hello {}!".format(name)
    # Put your logic here
    return "Done", 200 #return nicely the response to the request


if __name__ == "__main__":
    app.run(debug=True, host="0.0.0.0", port=int(os.environ.get("PORT", 8080)))

然后当你想运行你的处理时,调用 / 路由,处理就会被执行。就这样。如果处理时间超过 3 分钟,您可以将云 运行 超时增加到 60 分钟。