Skip to content
This repository was archived by the owner on Apr 19, 2026. It is now read-only.

Commit 2ca1814

Browse files
authored
chore: Consolidate primary build configuration into a single file (#223)
1 parent bb14be3 commit 2ca1814

13 files changed

Lines changed: 417 additions & 300 deletions

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
run: "bundle install && gem install --no-document toys"
2626
- name: Build
2727
shell: bash
28-
run: bundle exec rake build
28+
run: toys build
2929
- name: Test
3030
shell: bash
31-
run: bundle exec rake faster test:only
31+
run: toys test --faster

.toys/.toys.rb

Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
mixin "runtime-params" do
16+
on_include do
17+
File.readlines("#{context_directory}/runtime-config.env").each do |line|
18+
if line =~ /^([A-Z][A-Z0-9_]*)=(.*)$/
19+
match = Regexp.last_match
20+
name_str = match[1]
21+
name_sym = name_str.downcase.to_sym
22+
value = match[2]
23+
static name_sym, value
24+
ENV[name_str] = value
25+
end
26+
end
27+
all_versions = []
28+
default_version = nil
29+
File.readlines("#{context_directory}/ruby-pipeline/ruby-latest.yaml").each do |line|
30+
all_versions << Regexp.last_match[1] if line =~ /([\d\.]+)=gcr\.io/
31+
default_version = Regexp.last_match[1] if line =~ /--default-ruby-version=([\d\.]+)/
32+
end
33+
all_versions = all_versions.join ","
34+
static :all_prebuilt_ruby_versions, all_versions
35+
static :default_ruby_version, default_version
36+
ENV["ALL_PREBUILT_RUBY_VERSIONS"] = all_versions
37+
ENV["DEFAULT_RUBY_VERSION"] = default_version
38+
end
39+
end
40+
41+
tool "build" do
42+
desc "Build all images locally"
43+
44+
flag :project, "--project=PROJECT", default: "gcp-runtimes"
45+
flag :os_name, "--os-name=NAME", default: "ubuntu20"
46+
flag :use_local_prebuilt
47+
48+
include :exec, e: true
49+
include "runtime-params"
50+
51+
def run
52+
cmd = [
53+
"build", "os-image",
54+
"--os-name", os_name,
55+
"--bundler2-version", bundler2_version,
56+
"--nodejs-version", nodejs_version,
57+
"--ssl10-version", ssl10_version
58+
]
59+
exec_tool cmd
60+
exec_tool cmd + ["--use-ssl10-dev"]
61+
if use_local_prebuilt
62+
cmd = ["build", "prebuilt", "--os-name", os_name] + primary_ruby_versions.split(",")
63+
exec_tool cmd
64+
end
65+
cmd = [
66+
"build", "basic",
67+
"--use-prebuilt-binary",
68+
"--os-name", os_name,
69+
"--ruby-version", basic_ruby_version,
70+
"--bundler1-version", bundler1_version,
71+
"--bundler2-version", bundler2_version
72+
]
73+
cmd << "--use-local-prebuilt" if use_local_prebuilt
74+
exec_tool cmd
75+
exec_tool [
76+
"build", "build-tools",
77+
"--gcloud-version", gcloud_version,
78+
"--bundler1-version", bundler1_version,
79+
"--bundler2-version", bundler2_version
80+
]
81+
cmd = [
82+
"build", "generate-dockerfile",
83+
"--os-name", os_name,
84+
"--default-ruby-version", default_ruby_version,
85+
"--bundler1-version", bundler1_version,
86+
"--bundler2-version", bundler2_version
87+
]
88+
if use_local_prebuilt
89+
primary_ruby_versions.split(",").each do |version|
90+
cmd << "--prebuilt-image=#{version}=ruby-prebuilt-#{version}:latest"
91+
end
92+
else
93+
all_prebuilt_ruby_versions.split(",").each do |version|
94+
cmd << "--prebuilt-image=#{version}=gcr.io/#{project}/ruby/#{os_name}/prebuilt/ruby-#{version}:latest"
95+
end
96+
end
97+
exec_tool cmd
98+
exec_tool ["build", "app-engine-exec-wrapper"]
99+
exec_tool ["build", "app-engine-exec-harness"]
100+
end
101+
end
102+
103+
tool "test" do
104+
desc "Run all tests"
105+
106+
flag :project, "--project=PROJECT", default: "gcp-runtimes"
107+
flag :os_name, "--os-name=NAME", default: "ubuntu20"
108+
flag :use_local_prebuilt
109+
flag :faster
110+
remaining_args :tests
111+
112+
include :exec, e: true
113+
include "runtime-params"
114+
115+
def run
116+
env = {
117+
"PREBUILT_RUBY_IMAGE_TAG" => "latest",
118+
"PREBUILT_RUBY_VERSIONS" => all_prebuilt_ruby_versions,
119+
"PRIMARY_RUBY_VERSIONS" => primary_ruby_versions,
120+
"BUNDLER1_VERSION" => bundler1_version,
121+
"BUNDLER2_VERSION" => bundler2_version,
122+
"TESTING_OS_NAME" => os_name
123+
}
124+
env["USE_LOCAL_PREBUILT"] = "true" if use_local_prebuilt
125+
env["FASTER_TESTS"] = "true" if faster
126+
env["PREBUILT_RUBY_IMAGE_BASE"] = use_local_prebuilt ? "ruby-prebuilt-" : "gcr.io/#{project}/ruby/#{os_name}/prebuilt/ruby-"
127+
cmd = ["_test"] + tests
128+
exec_tool cmd, env: env
129+
end
130+
end
131+
132+
expand :minitest, name: "_test", files: ["test/test*.rb"]

.toys/build.rb

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
# Copyright 2022 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
tool "os-image" do
16+
desc "Build local docker image the OS"
17+
18+
flag :os_name, "--os-name=NAME", default: "ubuntu20"
19+
flag :use_ssl10_dev
20+
all_required do
21+
flag :bundler2_version, "--bundler2-version=VERSION"
22+
flag :nodejs_version, "--nodejs-version=VERSION"
23+
flag :ssl10_version, "--ssl10-version=VERSION"
24+
end
25+
26+
include :exec, e: true
27+
28+
def run
29+
sed_script = use_ssl10_dev ? "s|@@IF_SSL10_DEV@@||g" : "s|@@IF_SSL10_DEV@@|#|g"
30+
image_name = use_ssl10_dev ? "ruby-#{os_name}-ssl10" : "ruby-#{os_name}"
31+
exec ["sed", "-e", sed_script, "ruby-#{os_name}/Dockerfile.in"],
32+
out: [:file, "ruby-#{os_name}/Dockerfile"]
33+
exec ["docker", "build", "--pull", "--no-cache",
34+
"-t", "#{image_name}",
35+
"--build-arg", "bundler_version=#{bundler2_version}",
36+
"--build-arg", "nodejs_version=#{nodejs_version}",
37+
"--build-arg", "ssl10_version=#{ssl10_version}",
38+
"ruby-#{os_name}"]
39+
end
40+
end
41+
42+
tool "prebuilt" do
43+
desc "Build prebuilt binary images"
44+
45+
flag :os_name, "--os-name=NAME", default: "ubuntu20"
46+
remaining_args :ruby_versions
47+
48+
include :exec, e: true
49+
50+
def run
51+
if ruby_versions.empty?
52+
logger.error "At least one ruby version required"
53+
exit 1
54+
end
55+
ruby_versions.each do |version|
56+
os_image = version < "2.4" ? "ruby-#{os_name}-ssl10" : "ruby-#{os_name}"
57+
exec ["sed", "-e", "s|@@RUBY_OS_IMAGE@@|#{os_image}|g", "ruby-prebuilt/Dockerfile.in"],
58+
out: [:file, "ruby-prebuilt/Dockerfile"]
59+
exec ["docker", "build", "--no-cache",
60+
"-t", "ruby-prebuilt-#{version}",
61+
"--build-arg", "ruby_version=#{version}",
62+
"ruby-prebuilt"]
63+
end
64+
end
65+
end
66+
67+
tool "basic" do
68+
desc "Build simple base image using the default ruby"
69+
70+
flag :project, "--project=PROJECT", default: "gcp-runtimes"
71+
flag :os_name, "--os-name=NAME", default: "ubuntu20"
72+
flag :use_prebuilt_binary
73+
flag :use_local_prebuilt
74+
all_required do
75+
flag :ruby_version, "--ruby-version=VERSION"
76+
flag :bundler1_version, "--bundler1-version=VERSION"
77+
flag :bundler2_version, "--bundler2-version=VERSION"
78+
end
79+
80+
include :exec, e: true
81+
82+
def run
83+
image_type = use_prebuilt_binary ? "prebuilt" : "default"
84+
prebuilt_base = use_local_prebuilt ? "ruby-prebuilt-" : "gcr.io/#{project}/ruby/#{os_name}/prebuilt/ruby-"
85+
sed_script = "s|@@RUBY_OS_IMAGE@@|ruby-#{os_name}|g;"\
86+
" s|@@PREBUILT_RUBY_IMAGE@@|#{prebuilt_base}#{ruby_version}|g"
87+
exec ["sed", "-e", sed_script, "ruby-base/Dockerfile-#{image_type}.in"],
88+
out: [:file, "ruby-base/Dockerfile"]
89+
exec ["docker", "build", "--no-cache",
90+
"-t", "ruby-base",
91+
"--build-arg", "ruby_version=#{ruby_version}",
92+
"--build-arg", "bundler1_version=#{bundler1_version}",
93+
"--build-arg", "bundler2_version=#{bundler2_version}",
94+
"ruby-base"]
95+
end
96+
end
97+
98+
tool "build-tools" do
99+
desc "Build the build-tools image"
100+
101+
all_required do
102+
flag :gcloud_version, "--gcloud-version=VERSION"
103+
flag :bundler1_version, "--bundler1-version=VERSION"
104+
flag :bundler2_version, "--bundler2-version=VERSION"
105+
end
106+
107+
include :exec, e: true
108+
109+
def run
110+
exec ["docker", "build", "--no-cache",
111+
"-t", "ruby-build-tools",
112+
"--build-arg", "gcloud_version=#{gcloud_version}",
113+
"--build-arg", "bundler1_version=#{bundler1_version}",
114+
"--build-arg", "bundler2_version=#{bundler2_version}",
115+
"ruby-build-tools"]
116+
end
117+
end
118+
119+
tool "generate-dockerfile" do
120+
desc "Build the generate-dockerfile image"
121+
122+
flag :os_name, "--os-name=NAME", default: "ubuntu20"
123+
flag :prebuilt_image, "--prebuilt-image=SPEC", handler: :push, default: []
124+
all_required do
125+
flag :default_ruby_version, "--default-ruby-version=VERSION"
126+
flag :bundler1_version, "--bundler1-version=VERSION"
127+
flag :bundler2_version, "--bundler2-version=VERSION"
128+
end
129+
130+
include :exec, e: true
131+
132+
def run
133+
prebuilt_ruby_images = prebuilt_image.join ","
134+
exec ["docker", "build", "--no-cache",
135+
"-t", "ruby-generate-dockerfile",
136+
"--build-arg", "base_image=ruby-#{os_name}",
137+
"--build-arg", "build_tools_image=ruby-build-tools",
138+
"--build-arg", "prebuilt_ruby_images=#{prebuilt_ruby_images}",
139+
"--build-arg", "default_ruby_version=#{default_ruby_version}",
140+
"--build-arg", "bundler1_version=#{bundler1_version}",
141+
"--build-arg", "bundler2_version=#{bundler2_version}",
142+
"ruby-generate-dockerfile"]
143+
end
144+
end
145+
146+
tool "app-engine-exec-wrapper" do
147+
desc "Build the app-engine-exec wrapper"
148+
149+
include :exec, e: true
150+
151+
def run
152+
exec ["docker", "build", "--no-cache",
153+
"-t", "app-engine-exec-wrapper",
154+
"app-engine-exec-wrapper"]
155+
end
156+
end
157+
158+
tool "app-engine-exec-harness" do
159+
desc "Build the fake test harmess image for app-engine-exec wrapper"
160+
161+
include :exec, e: true
162+
163+
def run
164+
exec ["docker", "build", "--no-cache",
165+
"-t", "app-engine-exec-harness",
166+
"test/app_engine_exec_wrapper/harness"]
167+
end
168+
end

Gemfile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
source 'https://rubygems.org'
22

3-
gem "minitest", "~> 5.11"
3+
gem "minitest", "~> 5.16"
44
gem "minitest-focus", "~> 1.1"
55
gem "minitest-rg", "~> 5.2"
6-
gem "rake", "~> 12.0"

Gemfile.lock

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,19 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
minitest (5.15.0)
4+
minitest (5.16.1)
55
minitest-focus (1.3.1)
66
minitest (>= 4, < 6)
77
minitest-rg (5.2.0)
88
minitest (~> 5.0)
9-
rake (12.3.3)
109

1110
PLATFORMS
1211
ruby
1312

1413
DEPENDENCIES
15-
minitest (~> 5.11)
14+
minitest (~> 5.16)
1615
minitest-focus (~> 1.1)
1716
minitest-rg (~> 5.2)
18-
rake (~> 12.0)
1917

2018
BUNDLED WITH
2119
2.2.33

README.md

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,21 @@ by the Google Ruby team for runtime integration tests.
3535

3636
## Local builds and tests
3737

38-
The provided Rakefile builds all the images locally and runs the unit tests
39-
in the test directory. It requires Ruby 2.3 and Docker 17.06 or later.
38+
[Toys](https://github.com/dazuma/toys) tools are provided to build the images
39+
locally and run the unit tests in the test directory. The tools require current
40+
versions of Ruby and Docker.
4041

4142
To perform a local build and test:
4243

43-
bundle install
44-
bundle exec rake
44+
gem install toys # If not already present
45+
toys build
46+
toys test
4547

4648
Note this procedure tests against production prebuilt Ruby binaries by default.
47-
To create and test locally-built binaries:
49+
To create and test a small number of locally-built binaries:
4850

49-
USE_LOCAL_PREBUILT=true bundle exec rake
51+
toys build --use-local-prebuilt
52+
toys test --use-local-prebuilt
5053

5154
## Release builds
5255

0 commit comments

Comments
 (0)