【问题标题】:How can I speed up Rails Docker deployments on Google Cloud Platform?如何加快在 Google Cloud Platform 上的 Rails Docker 部署?
【发布时间】:2016-04-02 16:44:54
【问题描述】:

我正在尝试使用更具成本效益的方法来部署我的 Rails 应用程序,并通过Ruby Starter Projects 了解 Google Cloud Platform。

几乎完美,而且在价格上肯定具有竞争力,但部署速度非常慢。

当我从the sample Bookshelf app 运行部署命令时:

$ gcloud preview app deploy app.yaml worker.yaml --promote

我可以在Compute Engine/VM Instances page 上看到一个新的gae-builder-vm 实例,然后我得到the familiar Docker build output - 这大约需要十分钟才能完成。

不过,如果我立即重新部署,我会得到一个新的 gae-builder-vm,它会通过 the exact same ten-minute build process with no apparent caching from the first time the image was built

在这两种情况下,第二个 模块 (worker.yaml) 都会被缓存并且运行得非常快:

Building and pushing image for module [worker]
---------------------------------------- DOCKER BUILD OUTPUT ----------------------------------------
Step 0 : FROM gcr.io/google_appengine/ruby
---> 3e8b286df835
Step 1 : RUN rbenv install -s 2.2.3 &&     rbenv global 2.2.3 &&     gem install -q --no-rdoc --no-ri bundler --version 1.10.6 &&     gem install -q --no-rdoc --no-ri foreman --version 0.78.0
---> Using cache
---> efdafde40bf8
Step 2 : ENV RBENV_VERSION 2.2.3
---> Using cache
---> 49534db5b7eb
Step 3 : COPY Gemfile Gemfile.lock /app/
---> Using cache
---> d8c2f1c5a44b
Step 4 : RUN bundle install && rbenv rehash
---> Using cache
---> d9f9b57ccbad
Step 5 : COPY . /app/
---> Using cache
---> 503904327f13
Step 6 : ENTRYPOINT bundle exec foreman start --formation "$FORMATION"
---> Using cache
---> af547f521411
Successfully built af547f521411

但如果没有任何变化,这些版本无法在部署之间缓存,这对我来说没有任何意义。

理想情况下,我认为如果我在专用构建服务器上触发重建(它可以记住构建之间的 Docker 映像),然后更新公共映像文件并要求 Google 使用预构建映像重新部署,这会更快会更快。

这是gcloud生成的Docker文件:

# This Dockerfile for a Ruby application was generated by gcloud with:
# gcloud preview app gen-config --custom

# The base Dockerfile installs:
# * A number of packages needed by the Ruby runtime and by gems
#   commonly used in Ruby web apps (such as libsqlite3)
# * A recent version of NodeJS
# * A recent version of the standard Ruby runtime to use by default
# * The bundler and foreman gems
FROM gcr.io/google_appengine/ruby

# Install ruby 2.2.3 if not already preinstalled by the base image
# base image: https://github.com/GoogleCloudPlatform/ruby-docker/blob/master/appengine/Dockerfile
# preinstalled ruby versions: 2.0.0-p647 2.1.7 2.2.3
RUN rbenv install -s 2.2.3 && \
    rbenv global 2.2.3 && \
    gem install -q --no-rdoc --no-ri bundler --version 1.10.6 && \
    gem install -q --no-rdoc --no-ri foreman --version 0.78.0
ENV RBENV_VERSION 2.2.3

# To install additional packages needed by your gems, uncomment
# the "RUN apt-get update" and "RUN apt-get install" lines below
# and specify your packages.
# RUN apt-get update
# RUN apt-get install -y -q (your packages here)

# Install required gems.
COPY Gemfile Gemfile.lock /app/
RUN bundle install && rbenv rehash

# Start application on port 8080.
COPY . /app/
ENTRYPOINT bundle exec foreman start --formation "$FORMATION"

我怎样才能使这个过程更快?

【问题讨论】:

  • 您找到加快速度的方法了吗?我的部署目前非常缓慢
  • 不——我最终在廉价的 VPS 盒子上使用了dokku。它比 GAE 更容易设置,并且与 Heroku 一样容易/快速部署(只需 git push,VM 会记住其安装的 gem)。

标签: ruby-on-rails google-app-engine docker dockerfile


【解决方案1】:

嗯,你有点混淆了两种不同的情况:

  • 重新部署 完全相同 应用程序代码 - 实际上,Google 不会检查要部署的应用程序是否有任何更改,在这种情况下,可以重新使用整个 docker 映像 - 但是您已经拥有该图像,实际上您甚至不需要重新部署。除非您怀疑出了什么问题,并且您真的坚持要重新构建映像(而部署实用程序正是这样做的)。一个相当学术的案例,对实际应用部署的成本效益几乎没有影响:)
  • 您正在部署 不同 应用程序代码(无论有多大不同) - 好吧,没有在映像构建期间重新使用缓存的工件(根据您的构建会发生这种情况)日志) - 最终图像仍然需要构建以包含新的应用程序代码 - 不可避免。重新使用之前构建的图像是不可能的。

更新:我之前错过了您的观点,在仔细查看您的两个日志后,我同意您的观察,即缓存似乎是每个构建 VM 的本地(解释为缓存命中仅在构建 worker 模块,每个模块都在同一个 VM 上,相应的 default 模块是预先构建的),因此不会在部署中重复使用。

另一个更新可能有一种方法可以跨部署获取缓存命中...

gcloud preview app deploy DESCRIPTION 表示除了临时 VM 之外,还可以使用 Container Builder API(这似乎是默认设置!)来完成托管构建:

使用临时虚拟机(使用默认 --docker-build=remote 设置),而不是 Container Builder API 来执行 docker 构建,运行:

$ gcloud config set app/use_cloud_build false

使用Container Builder API 完成的构建可能使用共享存储,可能允许跨部署的缓存命中。恕我直言,值得一试。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-02-06
    • 2018-12-24
    • 2023-03-12
    • 2018-05-26
    相关资源
    最近更新 更多