无法 find/modify 使用标准运行时的 Google App Engine 托管 VM 的 Dockerfile (python27)

Unable to find/modify the Dockerfile of a Google App Engine Managed VM that uses a standard runtime (python27)

我想修改使用标准 运行 时间 (python27) 的 Google App Engine 托管 VM 的 Dockerfile。

我想这样做是为了添加一个C++库,需要调用它来实现一个HTTP请求。这个库几乎是我需要添加到沙盒 python27 运行time.

中的唯一内容

documentation 很清楚这是可能的:

Each standard runtime uses a default Dockerfile, which is supplied by the SDK. You can extend and enhance a standard runtime by adding new docker commands to this file.

Elsewhere他们说他们会在项目目录下生成一个标准运行时间的Dockerfile:

When you use gcloud to run or deploy a managed VM application based on a standard runtime (in this case Python27), the SDK will create a minimal Dockerfile using the standard runtime as a base image. You'll find this Dockerfile in your project directory...

这是我应该根据同一页面修改的:

Later steps in this tutorial will show you how to extend the capabilities of your runtime environment by adding instructions to the Dockerfile.

问题是,当我在开发服务器上执行 运行 我的应用程序时,我无法在任何地方找到 Dockerfile,因此我无法对其进行任何更改。

有没有人设法修改 Google App Engine 的标准 运行time Dockerfile?任何帮助将不胜感激。

似乎 Dockerfile 仅在使用 gcloud preview app run 而不是 dev_appserver.py 时生成,而我使用的是 dev_appserver.py

但是我无法修改 Dockerfile 和 运行 自定义托管 VM。但这是一个单独的错误(--custom_entrypoint 相关)。

糟糕的文档和支持助长了整个情况,这是一场噩梦。对考虑 Google App Engine 的其他开发者的警告。

要使用 google-api-python-client,我遇到了同样的问题,因为我需要 pycrypto。我总是得到错误:

CryptoUnavailableError: No crypto library available

为了解决这个问题,我创建了一个实例启动处理程序来安装所有需要的库。它很丑,但它有效。

app.yaml:

handlers:
- url: /_ah/start
  script: start_handler.app

start_handler.py

import webapp2
import logging
import os

class StartHandler(webapp2.RequestHandler):
  def execute(self, cmd):
    logging.info(os.popen("%s 2>&1" % cmd).read())

  def get(self):
    if not os.environ.get('SERVER_SOFTWARE','').startswith('Development'):
      self.execute("apt-get update")
      self.execute("apt-get -y install build-essential libssl-dev libffi-dev python-dev")
      self.execute("pip install cryptography")
      self.execute("pip install pyopenssl")


app = webapp2.WSGIApplication([
                                ('/_ah/start', StartHandler)
                              ], debug=True)

事实证明,在您的应用程序中扩展 Dockerfile 并不像文档中声称的那样工作 (Link)。事实上,如果存在 Dockerfile,您将收到以下错误:

"ERROR: (gcloud.preview.app.deploy) There is a Dockerfile in the current directory, and the runtime field in /[...]/app.yaml is currently set to [runtime: python27]. To use your Dockerfile to build a custom runtime, set the runtime field in [...]/app.yaml to [runtime: custom]. To continue using the [python27] runtime, please omit the Dockerfile from this directory"

我能够使用自定义 Dockerfile 的唯一方法是使用自定义运行时。

Google 有一个非常好的 GitHub 示例,用于使用自定义 Python 运行时 (here) 将 Django 部署到托管 VM。

由于您使用的是自定义运行时,因此您必须自己实施健康检查。但是,如果您需要访问 Google API,Google 有一个如何在 GitHub (here).

上进行设置的示例

如需帮助实施健康检查或与 Google API 集成,您可以遵循 Google Compute Engine,入门系列教程 (here)。