|
| 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 |
0 commit comments