Skip to content

Instantly share code, notes, and snippets.

@ukazap
Created November 27, 2018 11:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ukazap/70eeb24252aa15523330070c0ee3760f to your computer and use it in GitHub Desktop.
Save ukazap/70eeb24252aa15523330070c0ee3760f to your computer and use it in GitHub Desktop.
Tried and true Dockerfile for custom Rails 5 runtime in Google App Engine
# This Dockerfile for a Ruby application was generated by gcloud.
# 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 gem
FROM gcr.io/google-appengine/ruby:latest
RUN apt-get update && apt-get -y install pkg-config libxml2 wget
# If your application requires a specific ruby version (compatible with rbenv),
# set it here. Leave blank to use the currently recommended default.
ARG REQUESTED_RUBY_VERSION="2.5.1"
# Install any requested ruby if not already preinstalled by the base image.
# Tries installing a prebuilt package first, then falls back to a source build.
RUN if test -n "$REQUESTED_RUBY_VERSION" -a \
! -x /rbenv/versions/$REQUESTED_RUBY_VERSION/bin/ruby; then \
(apt-get update -y \
&& apt-get install -y -q gcp-ruby-$REQUESTED_RUBY_VERSION) \
|| (cd /rbenv/plugins/ruby-build \
&& git pull \
&& rbenv install -s $REQUESTED_RUBY_VERSION) \
&& rbenv global $REQUESTED_RUBY_VERSION \
&& gem install -q --no-rdoc --no-ri bundler --version $BUNDLER_VERSION \
&& apt-get clean \
&& rm -f /var/lib/apt/lists/*_*; \
fi
ENV RBENV_VERSION=${REQUESTED_RUBY_VERSION:-$RBENV_VERSION}
# Copy the application files.
COPY . /app/
# Install required gems if Gemfile.lock is present.
RUN if test -f Gemfile.lock; then \
bundle config build.nokogiri --use-system-libraries --with-xml2-include=/usr/include/libxml2 --with-xml2-lib=/usr/lib \
&& bundle install --deployment --without="development test" \
&& rbenv rehash; \
fi
# Temporary. Will be moved to base image later.
ENV RACK_ENV=production \
RAILS_ENV=production \
RAILS_SERVE_STATIC_FILES=true
# Run asset pipeline if we're in a Rails app.
RUN if test -d app/assets -a -f config/application.rb; then \
bundle exec rake assets:precompile || true; \
fi
# BUG: Reset entrypoint to override base image.
ENTRYPOINT []
# Start application on port $PORT.
CMD bundle exec foreman start -f LiveProcfile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment