title: How can I speed up Rails Docker deployments on Google Cloud Platform?
body: <p>I'm experimenting with more cost effective ways to deploy my Rails apps, and went through the <a href="https://cloud.google.com/ruby/getting-started/hello-world" rel="noreferrer">Ruby Starter Projects</a> to get a feel for Google Cloud Platform.</p>
  
  <p>It's <em>almost</em> perfect, and certainly competitive on price, but the deployments are incredibly slow.</p>
  
  <p>When I run the deployment command from <a href="https://cloud.google.com/ruby/getting-started/tutorial-app" rel="noreferrer">the sample Bookshelf app</a>:</p>
  
  <pre><code>$ gcloud preview app deploy app.yaml worker.yaml --promote
  </code></pre>
  
  <p>I can see a new <code>gae-builder-vm</code> instance on the <a href="https://console.developers.google.com/compute/instances" rel="noreferrer">Compute Engine/VM Instances page</a> and I get <a href="https://gist.github.com/christiangenco/c3d84119bf7c594b7bd6#file-output-of-first-gcloud-deploy-txt" rel="noreferrer">the familiar Docker build output</a> - this takes about ten minutes to finish.</p>
  
  <p>If I immediately redeploy, though, I get a new <code>gae-builder-vm</code> spun up that goes through <a href="https://gist.github.com/christiangenco/c3d84119bf7c594b7bd6#file-output-of-second-gcloud-deploy-txt" rel="noreferrer">the exact same ten-minute build process with no apparent caching from the first time the image was built</a>.</p>
  
  <p>In both cases, the second <em>module</em> (worker.yaml) gets cached and goes really quickly:</p>
  
  <pre><code>Building and pushing image for module [worker]
  ---------------------------------------- DOCKER BUILD OUTPUT ----------------------------------------
  Step 0 : FROM gcr.io/google_appengine/ruby
  ---&gt; 3e8b286df835
  Step 1 : RUN rbenv install -s 2.2.3 &amp;&amp;     rbenv global 2.2.3 &amp;&amp;     gem install -q --no-rdoc --no-ri bundler --version 1.10.6 &amp;&amp;     gem install -q --no-rdoc --no-ri foreman --version 0.78.0
  ---&gt; Using cache
  ---&gt; efdafde40bf8
  Step 2 : ENV RBENV_VERSION 2.2.3
  ---&gt; Using cache
  ---&gt; 49534db5b7eb
  Step 3 : COPY Gemfile Gemfile.lock /app/
  ---&gt; Using cache
  ---&gt; d8c2f1c5a44b
  Step 4 : RUN bundle install &amp;&amp; rbenv rehash
  ---&gt; Using cache
  ---&gt; d9f9b57ccbad
  Step 5 : COPY . /app/
  ---&gt; Using cache
  ---&gt; 503904327f13
  Step 6 : ENTRYPOINT bundle exec foreman start --formation "$FORMATION"
  ---&gt; Using cache
  ---&gt; af547f521411
  Successfully built af547f521411
  </code></pre>
  
  <p>but it doesn't make sense to me that these versions couldn't be cached between deployments if nothing has changed.</p>
  
  <p>Ideally I'm thinking this would go faster if I triggered a rebuild on a dedicated build server (which could remember Docker images between builds), which then updated a public image file and asked Google to redeploy with the prebuilt image, which would go faster.</p>
  
  <p>Here's the Docker file that was generated by <code>gcloud</code>:</p>
  
  <pre><code># 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 &amp;&amp; \
      rbenv global 2.2.3 &amp;&amp; \
      gem install -q --no-rdoc --no-ri bundler --version 1.10.6 &amp;&amp; \
      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 &amp;&amp; rbenv rehash
  
  # Start application on port 8080.
  COPY . /app/
  ENTRYPOINT bundle exec foreman start --formation "$FORMATION"
  </code></pre>
  
  <p>How can I make this process faster?</p>