【问题标题】:App Engine Custom Runtime not caching dockerfileApp Engine 自定义运行时未缓存 dockerfile
【发布时间】:2016-08-08 19:05:16
【问题描述】:

我正在使用custom runtime 部署到应用程序引擎,我注意到当我部署时,应用程序引擎将完全重新构建我的 Dockerfile,而无需任何缓存。这会导致部署花费更长的时间。我不会在部署之间更改我的 Dockerfile。只有我的应用程序代码在改变。这是我的 Dockerfile:

FROM ubuntu
EXPOSE 8080

RUN apt-get update
RUN apt-get install -yq python-crypto python-openssl libffi-dev libssl-dev
RUN pip install --upgrade pip
RUN pip install gunicorn==19.4.5
RUN pip install Flask==0.10.1
RUN pip install PyMySQL==0.7.2
RUN pip install alembic==0.8.5
RUN pip install Flask-Migrate==1.8.0
RUN pip install Flask-CORS==2.1.2
RUN pip install PyCrypto==2.6.1
RUN pip install requests==2.9.1
RUN pip install --upgrade cffi
RUN pip install google-api-python-client==1.5.0
RUN pip install gcloud==0.11.0

# Ensure that Python outputs everything that's printed inside
# the application rather than buffering it.
ENV PYTHONUNBUFFERED 1

ADD . /app/
WORKDIR /app

ENTRYPOINT ["gunicorn", "-b", ":8080", "server:app"]

有没有办法加快我的部署速度?

【问题讨论】:

  • 你在使用Container Builder API吗?基于 GCE 的远程构建?本地 Docker 构建?
  • 我正在使用应用引擎管理的虚拟机(我认为它使用容器构建器)。我正在使用 gcloud --project myproject preview app deploy --version v1 app.yaml 进行部署

标签: google-app-engine


【解决方案1】:

部署的目标是构建要作为您的应用执行的 docker 映像。

dockerfile 只包含 docker 镜像构建指令,所以它的内容没有改变这一事实没有任何意义 - 仍然需要执行构建指令才能获得新的 docker 镜像。

加快 docker 映像构建的唯一方法是将未更改的临时结果(例如当前的 FROM 映像加上所有已安装的 pip 软件包)存储为临时 docker 映像,以 FROM 的形式引用另一个 dockerfile,它只会更新你的应用程序的代码。但是 AFAIK GAE 不允许(至少目前还不允许)保存此类自定义中间图像,以便在构建其他自定义图像时重新用作基础图像。

【讨论】:

  • 故障排除页面提示应该有一些缓存? (cloud.google.com/appengine/docs/flexible/custom-runtimes/…)
  • 啊,那个缓存是存在的,但它是一个你无法控制的共享缓存。您可能获得它的好处与否,这取决于您正在构建什么以及您这样做的频率。构建日志应该表明它是否受益于缓存(Using cache 消息),如这篇文章所示:stackoverflow.com/questions/34500213/…
  • 可能可以控制缓存,请参阅我对该问题的更新答案。
【解决方案2】:

如果您有一个正确配置的本地 docker 环境,您可以使用 --docker-build local 标志来执行本地构建。

--docker-build DOCKER_BUILD

执行托管('remote')或本地('local')Docker 构建。要执行本地构建,您必须正确配置本地 docker 环境。默认是托管构建。

-- https://cloud.google.com/sdk/gcloud/reference/preview/app/deploy#--docker-build

【讨论】:

  • 我不确定这有什么作用。在控制台日志中,我仍然可以看到 REMOTE BUILD OUTPUT 及其从 Dockerfile 执行的所有步骤
猜你喜欢
  • 2020-05-06
  • 2016-11-26
  • 1970-01-01
  • 2023-03-15
  • 2017-06-16
  • 2015-06-13
  • 2018-07-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多