Skip to content
This repository was archived by the owner on Apr 19, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ GEM
minitest (>= 4, < 6)
minitest-rg (5.2.0)
minitest (~> 5.0)
rake (12.3.1)
rake (12.3.2)

PLATFORMS
ruby
Expand All @@ -18,4 +18,4 @@ DEPENDENCIES
rake (~> 12.0)

BUNDLED WITH
1.16.5
1.17.3
17 changes: 13 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
::Dir.chdir __dir__

RUNTIME_PROJECT="gcp-runtimes"
BUNDLER_VERSION="1.16.6"
BUNDLER1_VERSION="1.17.3"
BUNDLER2_VERSION="2.0.1"
DEFAULT_RUBY_VERSION="2.3.8"
NODEJS_VERSION="8.12.0"
GCLOUD_VERSION="221.0.0"
NODEJS_VERSION="10.15.1"
GCLOUD_VERSION="232.0.0"
OS_NAME="ubuntu16"

LOCAL_PREBUILT_RUBY_VERSIONS=["2.3.8", "2.4.5", "2.5.3", "2.6.0"]
Expand All @@ -45,6 +46,8 @@ end
::ENV["PREBUILT_RUBY_VERSIONS"] = PREBUILT_RUBY_VERSIONS.join(",")
::ENV["PREBUILT_RUBY_IMAGE_BASE"] = PREBUILT_RUBY_IMAGE_BASE
::ENV["PREBUILT_RUBY_IMAGE_TAG"] = PREBUILT_RUBY_IMAGE_TAG
::ENV["BUNDLER1_VERSION"] = BUNDLER1_VERSION
::ENV["BUNDLER2_VERSION"] = BUNDLER2_VERSION

PREBUILT_RUBY_IMAGES = PREBUILT_RUBY_VERSIONS.map do |v|
"#{v}=#{PREBUILT_RUBY_IMAGE_BASE}#{v}:#{PREBUILT_RUBY_IMAGE_TAG}"
Expand All @@ -55,7 +58,7 @@ require "rake/testtask"
desc "Build local docker image for ubuntu16 image"
task "build:ubuntu16" do |t, args|
sh "docker build --pull --no-cache -t ruby-ubuntu16" \
" --build-arg bundler_version=#{BUNDLER_VERSION}" \
" --build-arg bundler_version=#{BUNDLER2_VERSION}" \
" --build-arg nodejs_version=#{NODEJS_VERSION}" \
" ruby-ubuntu16"
end
Expand Down Expand Up @@ -89,13 +92,17 @@ task "build:base" do |t, args|
" ruby-base/Dockerfile-#{image_type}.in > ruby-base/Dockerfile"
sh "docker build --no-cache -t ruby-base" \
" --build-arg ruby_version=#{DEFAULT_RUBY_VERSION}" \
" --build-arg bundler1_version=#{BUNDLER1_VERSION}" \
" --build-arg bundler2_version=#{BUNDLER2_VERSION}" \
" ruby-base"
end

desc "Build local docker image for build-tools image"
task "build:build-tools" do |t, args|
sh "docker build --no-cache -t ruby-build-tools" \
" --build-arg gcloud_version=#{GCLOUD_VERSION}" \
" --build-arg bundler1_version=#{BUNDLER1_VERSION}" \
" --build-arg bundler2_version=#{BUNDLER2_VERSION}" \
" ruby-build-tools"
end

Expand All @@ -106,6 +113,8 @@ task "build:generate-dockerfile" do |t, args|
" --build-arg build_tools_image=ruby-build-tools" \
" --build-arg prebuilt_ruby_images=#{PREBUILT_RUBY_IMAGES}" \
" --build-arg default_ruby_version=#{DEFAULT_RUBY_VERSION}" \
" --build-arg bundler1_version=#{BUNDLER1_VERSION}" \
" --build-arg bundler2_version=#{BUNDLER2_VERSION}" \
" ruby-generate-dockerfile"
end

Expand Down
15 changes: 8 additions & 7 deletions build-ruby-runtime-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@
# version used by the runtime by default if one is not specified by the app.
BASIC_RUBY_VERSION=2.3.8

DEFAULT_BUNDLER_VERSION=1.16.6
NODEJS_VERSION=8.12.0
GCLOUD_VERSION=221.0.0
BUNDLER1_VERSION=1.17.3
BUNDLER2_VERSION=2.0.1
NODEJS_VERSION=10.15.1
GCLOUD_VERSION=232.0.0


set -e
Expand Down Expand Up @@ -134,7 +135,7 @@ echo

gcloud builds submit ${DIRNAME}/ruby-${OS_NAME} \
--config ${DIRNAME}/ruby-${OS_NAME}/cloudbuild.yaml --project ${PROJECT} \
--substitutions _IMAGE=${OS_BASE_IMAGE},_TAG=${IMAGE_TAG},_BUNDLER_VERSION=${DEFAULT_BUNDLER_VERSION},_NODEJS_VERSION=${NODEJS_VERSION}
--substitutions _IMAGE=${OS_BASE_IMAGE},_TAG=${IMAGE_TAG},_BUNDLER_VERSION=${BUNDLER2_VERSION},_NODEJS_VERSION=${NODEJS_VERSION}
echo "**** Built image: ${OS_BASE_IMAGE}:${IMAGE_TAG}"
if [ "${STAGING_FLAG}" = "true" ]; then
gcloud container images add-tag --project ${PROJECT} \
Expand All @@ -146,7 +147,7 @@ sed -e "s|@@RUBY_OS_IMAGE@@|ruby-${OS_NAME}|g; s|@@PREBUILT_RUBY_IMAGE@@|${PREBU
< ${DIRNAME}/ruby-base/Dockerfile-${BASE_IMAGE_DOCKERFILE}.in > ${DIRNAME}/ruby-base/Dockerfile
gcloud builds submit ${DIRNAME}/ruby-base \
--config ${DIRNAME}/ruby-base/cloudbuild.yaml --project ${PROJECT} --timeout 20m \
--substitutions _OS_NAME=${OS_NAME},_OS_BASE_IMAGE=${OS_BASE_IMAGE},_IMAGE=${RUBY_BASIC_IMAGE},_TAG=${IMAGE_TAG},_RUBY_VERSION=${BASIC_RUBY_VERSION}
--substitutions _OS_NAME=${OS_NAME},_OS_BASE_IMAGE=${OS_BASE_IMAGE},_IMAGE=${RUBY_BASIC_IMAGE},_TAG=${IMAGE_TAG},_RUBY_VERSION=${BASIC_RUBY_VERSION},_BUNDLER1_VERSION=${BUNDLER1_VERSION},_BUNDLER2_VERSION=${BUNDLER2_VERSION}
echo "**** Built image: ${RUBY_BASIC_IMAGE}:${IMAGE_TAG}"
if [ "${STAGING_FLAG}" = "true" ]; then
gcloud container images add-tag --project ${PROJECT} \
Expand All @@ -156,7 +157,7 @@ fi

gcloud builds submit ${DIRNAME}/ruby-build-tools \
--config ${DIRNAME}/ruby-build-tools/cloudbuild.yaml --project ${PROJECT} \
--substitutions _BASE_IMAGE=${RUBY_BASIC_IMAGE},_IMAGE=${BUILD_TOOLS_IMAGE},_TAG=${IMAGE_TAG},_GCLOUD_VERSION=${GCLOUD_VERSION}
--substitutions _BASE_IMAGE=${RUBY_BASIC_IMAGE},_IMAGE=${BUILD_TOOLS_IMAGE},_TAG=${IMAGE_TAG},_GCLOUD_VERSION=${GCLOUD_VERSION},_BUNDLER1_VERSION=${BUNDLER1_VERSION},_BUNDLER2_VERSION=${BUNDLER2_VERSION}
echo "**** Built image: ${BUILD_TOOLS_IMAGE}:${IMAGE_TAG}"
if [ "${STAGING_FLAG}" = "true" ]; then
gcloud container images add-tag --project ${PROJECT} \
Expand All @@ -166,7 +167,7 @@ fi

gcloud builds submit ${DIRNAME}/ruby-generate-dockerfile \
--config ${DIRNAME}/ruby-generate-dockerfile/cloudbuild.yaml --project ${PROJECT} \
--substitutions _BASE_IMAGE=${RUBY_BASIC_IMAGE},_IMAGE=${GENERATE_DOCKERFILE_IMAGE},_TAG=${IMAGE_TAG}
--substitutions _BASE_IMAGE=${RUBY_BASIC_IMAGE},_IMAGE=${GENERATE_DOCKERFILE_IMAGE},_TAG=${IMAGE_TAG},_BUNDLER1_VERSION=${BUNDLER1_VERSION},_BUNDLER2_VERSION=${BUNDLER2_VERSION}
echo "**** Built image: ${GENERATE_DOCKERFILE_IMAGE}:${IMAGE_TAG}"
if [ "${STAGING_FLAG}" = "true" ]; then
gcloud container images add-tag --project ${PROJECT} \
Expand Down
18 changes: 9 additions & 9 deletions release-ruby-binary-images.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,24 @@ fi
show_usage() {
echo 'Usage: release-ruby-binary-images.sh [flags...]' >&2
echo 'Flags:' >&2
echo ' -c <versions>: comma separated prebuilt ruby versions (defaults to prebuilt-versions.txt)' >&2
echo ' -n <name>: set the runtime name (defaults to `ruby`)' >&2
echo ' -o <osname>: build against the given os base image (defaults to ubuntu16)' >&2
echo ' -p <project>: set the project (defaults to current gcloud config setting)' >&2
echo ' -r <versions>: comma separated prebuilt ruby versions (defaults to prebuilt-versions.txt)' >&2
echo ' -t <tag>: the image tag to release (defaults to `staging`)' >&2
echo ' -y: automatically confirm' >&2
}

OPTIND=1
while getopts ":n:o:p:r:t:yh" opt; do
while getopts ":c:n:o:p:t:yh" opt; do
case ${opt} in
c)
if [ "${OPTARG}" = "none" ]; then
PREBUILT_VERSIONS=()
else
IFS=',' read -r -a PREBUILT_VERSIONS <<< "${OPTARG}"
fi
;;
n)
RUNTIME_NAME=${OPTARG}
;;
Expand All @@ -53,13 +60,6 @@ while getopts ":n:o:p:r:t:yh" opt; do
p)
PROJECT=${OPTARG}
;;
r)
if [ "${OPTARG}" = "none" ]; then
PREBUILT_VERSIONS=()
else
IFS=',' read -r -a PREBUILT_VERSIONS <<< "${OPTARG}"
fi
;;
t)
IMAGE_TAG=${OPTARG}
;;
Expand Down
8 changes: 5 additions & 3 deletions ruby-base/Dockerfile-default.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@
FROM @@RUBY_OS_IMAGE@@

ARG ruby_version
ARG bundler1_version
ARG bundler2_version

ENV DEFAULT_RUBY_VERSION=${ruby_version}

# Install Ruby, set default Ruby version, and install Bundler
RUN rbenv install -s ${ruby_version} \
&& rbenv global ${ruby_version} \
&& rbenv rehash \
&& (bundle version > /dev/null 2>&1 \
|| gem install bundler --version ${DEFAULT_BUNDLER_VERSION}) \
&& rbenv rehash
&& (gem install bundler --version ${bundler1_version} ; \
gem install bundler --version ${bundler2_version} ; \
rbenv rehash)
8 changes: 5 additions & 3 deletions ruby-base/Dockerfile-prebuilt.in
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
FROM @@RUBY_OS_IMAGE@@

ARG ruby_version
ARG bundler1_version
ARG bundler2_version

ENV DEFAULT_RUBY_VERSION=${ruby_version}

Expand All @@ -30,6 +32,6 @@ COPY --from=@@PREBUILT_RUBY_IMAGE@@ \
# Set default Ruby version and install Bundler
RUN rbenv global ${ruby_version} \
&& rbenv rehash \
&& (bundle version > /dev/null 2>&1 \
|| gem install bundler --version ${DEFAULT_BUNDLER_VERSION}) \
&& rbenv rehash
&& (gem install bundler --version ${bundler1_version} ; \
gem install bundler --version ${bundler2_version} ; \
rbenv rehash)
2 changes: 2 additions & 0 deletions ruby-base/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', '$_IMAGE:$_TAG',
'--build-arg', 'ruby_version=$_RUBY_VERSION',
'--build-arg', 'bundler1_version=$_BUNDLER1_VERSION',
'--build-arg', 'bundler2_version=$_BUNDLER2_VERSION',
'.']
- name: 'gcr.io/gcp-runtimes/structure_test'
args: ['--image', '$_IMAGE:$_TAG', '-v',
Expand Down
9 changes: 7 additions & 2 deletions ruby-build-tools/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ FROM ruby-base AS builder

# Versions
ARG gcloud_version
ARG bundler1_version
ARG bundler2_version

RUN mkdir -p /app/bin

Expand All @@ -41,10 +43,13 @@ RUN mkdir /app/google-cloud-sdk \
&& (curl -s https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-${gcloud_version}-linux-x86_64.tar.gz \
| tar xzf - --directory=/app/google-cloud-sdk --strip-components=1)

# Pre-download the gems we'll commonly install
RUN mkdir -p /app/gems \
&& cd /app/gems \
&& gem fetch bundler --version ${bundler2_version} \
&& gem fetch bundler --version ${bundler1_version}

# Generate a minimal image with only the tool files themselves. This image
# can be downloaded quickly and the files copied into a build image.

FROM scratch

COPY --from=builder /app/ /opt/
2 changes: 2 additions & 0 deletions ruby-build-tools/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', '$_IMAGE:$_TAG',
'--build-arg', 'gcloud_version=$_GCLOUD_VERSION',
'--build-arg', 'bundler1_version=$_BUNDLER1_VERSION',
'--build-arg', 'bundler2_version=$_BUNDLER2_VERSION',
'.']

images:
Expand Down
6 changes: 5 additions & 1 deletion ruby-generate-dockerfile/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@ ARG base_image=""
ARG build_tools_image=""
ARG prebuilt_ruby_images=""
ARG default_ruby_version=""
ARG bundler1_version=""
ARG bundler2_version=""

ENV DEFAULT_RUBY_BASE_IMAGE=${base_image} \
DEFAULT_RUBY_BUILD_TOOLS_IMAGE=${build_tools_image} \
DEFAULT_PREBUILT_RUBY_IMAGES=${prebuilt_ruby_images} \
DEFAULT_RUBY_VERSION=${default_ruby_version}
DEFAULT_RUBY_VERSION=${default_ruby_version} \
PROVIDED_BUNDLER1_VERSION=${bundler1_version} \
PROVIDED_BUNDLER2_VERSION=${bundler2_version}

# Install the Dockerfile generation script and template.
COPY app/ /app/
Expand Down
27 changes: 15 additions & 12 deletions ruby-generate-dockerfile/app/Dockerfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ RUN apt-get update -y \
## Ruby version specification in your Gemfile, they must match this value.
ARG ruby_version="<%= ruby_version %>"

## Commonly installed gems (e.g. bundler) are available from this image.
COPY --from=<%= build_tools_image %> /opt/gems/ /opt/gems/

<% if prebuilt_ruby_image %>
## Install Ruby <%= ruby_version %> from a prebuilt image. If a prebuilt image
## is not available, use the alternate installation method commented below.
Expand All @@ -47,9 +50,9 @@ COPY --from=<%= prebuilt_ruby_image %> \
/opt/rbenv/versions/${ruby_version}
RUN rbenv global ${ruby_version} \
&& rbenv rehash \
&& (bundle version > /dev/null 2>&1 \
|| gem install bundler --version ${DEFAULT_BUNDLER_VERSION}) \
&& rbenv rehash
&& (gem install /opt/gems/bundler-<%= @bundler1_version %>.gem ; \
gem install /opt/gems/bundler-<%= @bundler2_version %>.gem ; \
rbenv rehash)
## Alternate installation for Ruby versions that have no prebuilt image.
# RUN if [ ! -x ${RBENV_ROOT}/versions/${ruby_version}/bin/ruby ]; \
# then \
Expand All @@ -58,9 +61,9 @@ RUN rbenv global ${ruby_version} \
# && rbenv install -s ${ruby_version} \
# && rbenv global ${ruby_version} \
# && rbenv rehash \
# && (bundle version > /dev/null 2>&1 \
# || gem install bundler --version ${DEFAULT_BUNDLER_VERSION}) \
# && rbenv rehash; \
# && (gem install /opt/gems/bundler-<%= @bundler1_version %>.gem ; \
# gem install /opt/gems/bundler-<%= @bundler2_version %>.gem ; \
# rbenv rehash); \
# fi
<% else %>
## Install Ruby <%= ruby_version %> by building from source using rbenv and
Expand All @@ -73,19 +76,19 @@ RUN if [ ! -x ${RBENV_ROOT}/versions/${ruby_version}/bin/ruby ]; \
&& rbenv install -s ${ruby_version} \
&& rbenv global ${ruby_version} \
&& rbenv rehash \
&& (bundle version > /dev/null 2>&1 \
|| gem install bundler --version ${DEFAULT_BUNDLER_VERSION}) \
&& rbenv rehash; \
&& (gem install /opt/gems/bundler-<%= @bundler1_version %>.gem ; \
gem install /opt/gems/bundler-<%= @bundler2_version %>.gem ; \
rbenv rehash); \
fi
## Alternate installation for Ruby versions that have a prebuilt image.
# COPY --from=PATH-TO-PREBUILT-IMAGE \
# /opt/rbenv/versions/${ruby_version} \
# /opt/rbenv/versions/${ruby_version}
# RUN rbenv global ${ruby_version} \
# && rbenv rehash \
# && (bundle version > /dev/null 2>&1 \
# || gem install bundler --version ${DEFAULT_BUNDLER_VERSION}) \
# && rbenv rehash
# && (gem install /opt/gems/bundler-<%= @bundler1_version %>.gem ; \
# gem install /opt/gems/bundler-<%= @bundler2_version %>.gem ; \
# rbenv rehash)
<% end %>

## Feel free to install any other software needed by both the build process
Expand Down
5 changes: 4 additions & 1 deletion ruby-generate-dockerfile/app/app_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,10 @@ def init_ruby_config
@ruby_version = $1
end
end
if @ruby_version !~ %r{\A[\w.-]*\z}
if @ruby_version =~ %r{\Aruby-(\d+\.\d+\.[\w.-]+)\z}
@ruby_version = $1
end
unless @ruby_version.empty? || @ruby_version =~ %r{\A\d+\.\d+\.[\w.-]+\z}
raise ::AppConfig::Error, "Illegal ruby version: #{@ruby_version.inspect}"
end
@has_gemfile = ::File.readable?("#{@workspace_dir}/Gemfile.lock") ||
Expand Down
10 changes: 8 additions & 2 deletions ruby-generate-dockerfile/app/generate_dockerfile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ def initialize args
add_prebuilt_ruby_image(str)
end
@default_ruby_version = ::ENV["DEFAULT_RUBY_VERSION"] || ::RUBY_VERSION
@bundler1_version = ::ENV["PROVIDED_BUNDLER1_VERSION"]
@bundler2_version = ::ENV["PROVIDED_BUNDLER2_VERSION"]
@testing = false
parse_args args
::Dir.chdir @workspace_dir
Expand Down Expand Up @@ -94,7 +96,8 @@ def add_prebuilt_ruby_image(str)
def write_dockerfile
b = TemplateCallbacks.new(@app_config, @timestamp, @base_image,
@build_tools_image, @prebuilt_ruby_images,
@default_ruby_version).instance_eval{ binding }
@default_ruby_version, @bundler1_version,
@bundler2_version).instance_eval{ binding }
write_path = "#{@app_config.workspace_dir}/Dockerfile"
if ::File.exist? write_path
::STDERR.puts "Unable to generate Dockerfile because one already exists."
Expand Down Expand Up @@ -131,12 +134,15 @@ def write_dockerignore

class TemplateCallbacks < SimpleDelegator
def initialize app_config, timestamp, base_image, build_tools_image,
prebuilt_ruby_images, default_ruby_version
prebuilt_ruby_images, default_ruby_version,
bundler1_version, bundler2_version
@timestamp = timestamp
@base_image = base_image
@build_tools_image = build_tools_image
@prebuilt_ruby_images = prebuilt_ruby_images
@default_ruby_version = default_ruby_version
@bundler1_version = bundler1_version
@bundler2_version = bundler2_version
super app_config
end

Expand Down
5 changes: 4 additions & 1 deletion ruby-generate-dockerfile/cloudbuild.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ steps:
- name: 'gcr.io/cloud-builders/docker'
args: ['tag', '$_BASE_IMAGE:$_TAG', 'ruby-base']
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', '$_IMAGE:$_TAG', '.']
args: ['build', '-t', '$_IMAGE:$_TAG',
'--build-arg', 'bundler1_version=$_BUNDLER1_VERSION',
'--build-arg', 'bundler2_version=$_BUNDLER2_VERSION',
'.']

images:
- '$_IMAGE:$_TAG'
1 change: 1 addition & 0 deletions ruby-ubuntu16/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ RUN apt-get update -y \
COPY files /root

ENV PATH=/opt/nodejs/bin:${RBENV_ROOT}/shims:${RBENV_ROOT}/bin:${PATH} \
MALLOC_ARENA_MAX=2 \
RACK_ENV=production \
RAILS_ENV=production \
APP_ENV=production \
Expand Down
2 changes: 1 addition & 1 deletion test/app_config/ruby-version/.ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.0.99
ruby-2.0.99
Loading