1

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

我想这样做以添加一个需要调用以实现 HTTP 请求的 C++ 库。这个库几乎是我需要添加到沙盒 python27 运行时的唯一补充。

文档清楚地表明这是可能的:

每个标准运行时都使用 SDK 提供的默认 Dockerfile。您可以通过向此文件添加新的 docker 命令来扩展和增强标准运行时。

在其他地方,他们说标准运行时的 Dockerfile 将在项目目录中生成:

当您使用 gcloud 运行或部署基于标准运行时(在本例中为 Python27)的托管 VM 应用程序时,SDK 将使用标准运行时作为基础映像创建一个最小的 Dockerfile。你会在你的项目目录中找到这个 Dockerfile...

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

本教程后面的步骤将向您展示如何通过向 Dockerfile 添加指令来扩展运行时环境的功能。

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

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

4

3 回答 3

2

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

CryptoUnavailableError:没有可用的加密库

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

应用程序.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)
于 2015-11-20T15:29:07.117 回答
0

似乎 Dockerfile 仅在 usinggcloud preview app run和 not时生成dev_appserver.py,这是我使用的。

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

这整个情况是由残暴的文档和支持助长的噩梦。对考虑使用 Google App Engine 的其他开发者的警告。

于 2015-11-17T17:07:20.363 回答
0

事实证明,在您的应用程序中扩展 Dockerfile 并不能像文档(链接)中声称的那样工作。实际上,如果存在 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 运行时(此处)将 Django 部署到托管 VM 。

由于您使用的是自定义运行时,因此您必须自己实施健康检查。但是,如果您需要访问 Google API,Google 提供了如何在 GitHub 上进行设置的示例(此处)。

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

于 2016-02-04T17:55:58.430 回答