From 12d541e2bae64fa0b8fa7bb50436a592e65cbd83 Mon Sep 17 00:00:00 2001 From: Matthew Robertson Date: Thu, 19 Sep 2024 13:26:06 -0700 Subject: [PATCH] fix ruby function builds using the oss builders We didn't have an order group for the ruby functions framework scenario. This commit adds it and updates the acceptance tests to verify it is being used correctly. PiperOrigin-RevId: 676540372 Change-Id: Ieba3ec2dbf2ad2919079aa6e28a18908b6ad1f23 --- builders/gcp/base/BUILD.bazel | 4 +++ builders/gcp/base/acceptance/acceptance.go | 1 + builders/gcp/base/acceptance/ruby_fn_test.go | 14 +++++----- builders/gcp/base/builder.toml | 29 ++++++++++++++++++++ builders/gcp/base/google.22.builder.toml | 28 +++++++++++++++++++ tools/pull-images.sh | 4 +++ 6 files changed, 73 insertions(+), 7 deletions(-) diff --git a/builders/gcp/base/BUILD.bazel b/builders/gcp/base/BUILD.bazel index a207544b6..5f5aa3055 100644 --- a/builders/gcp/base/BUILD.bazel +++ b/builders/gcp/base/BUILD.bazel @@ -8,6 +8,7 @@ builder( name = "builder", buildpacks = [ "//cmd/config/entrypoint:entrypoint.tgz", + "//cmd/utils/archive_source:archive_source.tgz", "//cmd/utils/label:label_image.tgz", "//cmd/utils/nginx:nginx.tgz", "//cmd/config/flex:flex.tgz", @@ -64,6 +65,7 @@ builder( ], "ruby": [ "//cmd/ruby/missing_entrypoint:missing_entrypoint.tgz", + "//cmd/ruby/functions_framework:functions_framework.tgz", "//cmd/ruby/rubygems:rubygems.tgz", "//cmd/ruby/bundle:bundle.tgz", "//cmd/ruby/rails:rails.tgz", @@ -84,6 +86,7 @@ builder( name = "google_22_builder", buildpacks = [ "//cmd/config/entrypoint:entrypoint.tgz", + "//cmd/utils/archive_source:archive_source.tgz", "//cmd/utils/label:label_image.tgz", "//cmd/utils/nginx:nginx.tgz", "//cmd/config/flex:flex.tgz", @@ -141,6 +144,7 @@ builder( ], "ruby": [ "//cmd/ruby/missing_entrypoint:missing_entrypoint.tgz", + "//cmd/ruby/functions_framework:functions_framework.tgz", "//cmd/ruby/rubygems:rubygems.tgz", "//cmd/ruby/bundle:bundle.tgz", "//cmd/ruby/rails:rails.tgz", diff --git a/builders/gcp/base/acceptance/acceptance.go b/builders/gcp/base/acceptance/acceptance.go index 9e7954414..68b5174a5 100644 --- a/builders/gcp/base/acceptance/acceptance.go +++ b/builders/gcp/base/acceptance/acceptance.go @@ -55,6 +55,7 @@ const ( pythonMissingEntrypoint = "google.python.missing-entrypoint" pythonWebserver = "google.python.webserver" rubyBundle = "google.ruby.bundle" + rubyFF = "google.ruby.functions-framework" rubyRails = "google.ruby.rails" rubyRuntime = "google.ruby.runtime" utilsNginx = "google.utils.nginx" diff --git a/builders/gcp/base/acceptance/ruby_fn_test.go b/builders/gcp/base/acceptance/ruby_fn_test.go index 2ce10b0e7..c80249a12 100644 --- a/builders/gcp/base/acceptance/ruby_fn_test.go +++ b/builders/gcp/base/acceptance/ruby_fn_test.go @@ -31,29 +31,29 @@ func TestAcceptance(t *testing.T) { { Name: "function with dependencies", App: "with_dependencies", - MustUse: []string{rubyRuntime, rubyBundle, entrypoint}, + MustUse: []string{rubyRuntime, rubyBundle, rubyFF}, }, { Name: "function with platform-specific dependencies", App: "with_platform_dependencies", - MustUse: []string{rubyRuntime, rubyBundle, entrypoint}, + MustUse: []string{rubyRuntime, rubyBundle, rubyFF}, }, { Name: "function with runtime env var", App: "with_env_var", RunEnv: []string{"FOO=foo"}, - MustUse: []string{rubyRuntime, rubyBundle, entrypoint}, + MustUse: []string{rubyRuntime, rubyBundle, rubyFF}, }, { Name: "function in fn_source file", App: "with_fn_source", - RunEnv: []string{"FUNCTION_SOURCE=sub_dir/custom_file.rb"}, - MustUse: []string{rubyRuntime, rubyBundle, entrypoint}, + Env: []string{"GOOGLE_FUNCTION_SOURCE=sub_dir/custom_file.rb"}, + MustUse: []string{rubyRuntime, rubyBundle, rubyFF}, }, { Name: "function using framework older than 0.7", App: "with_legacy_framework", - MustUse: []string{rubyRuntime, rubyBundle, entrypoint}, + MustUse: []string{rubyRuntime, rubyBundle, rubyFF}, }, } @@ -65,7 +65,7 @@ func TestAcceptance(t *testing.T) { tc.Path = "/testFunction" tc.Env = append(tc.Env, "GOOGLE_RUNTIME_VERSION=3.1.*", - "GOOGLE_ENTRYPOINT=bundle exec functions-framework-ruby --target testFunction", + "GOOGLE_FUNCTION_TARGET=testFunction", ) acceptance.TestApp(t, imageCtx, tc) diff --git a/builders/gcp/base/builder.toml b/builders/gcp/base/builder.toml index 484b23db8..55e459098 100644 --- a/builders/gcp/base/builder.toml +++ b/builders/gcp/base/builder.toml @@ -136,6 +136,10 @@ description = "Ubuntu 18 base image with buildpacks for .NET, Go, Java, Node.js, id = "google.python.missing-entrypoint" uri = "python/missing_entrypoint.tgz" +[[buildpacks]] + id = "google.utils.archive-source" + uri = "archive_source.tgz" + [[buildpacks]] id = "google.utils.label-image" uri = "label_image.tgz" @@ -144,6 +148,10 @@ description = "Ubuntu 18 base image with buildpacks for .NET, Go, Java, Node.js, id = "google.ruby.runtime" uri = "ruby/runtime.tgz" +[[buildpacks]] + id = "google.ruby.functions-framework" + uri = "ruby/functions_framework.tgz" + [[buildpacks]] id = "google.ruby.rubygems" uri = "ruby/rubygems.tgz" @@ -525,6 +533,7 @@ description = "Ubuntu 18 base image with buildpacks for .NET, Go, Java, Node.js, [[order.group]] id = "google.utils.label-image" + ########### # Ruby applications # @@ -558,6 +567,26 @@ description = "Ubuntu 18 base image with buildpacks for .NET, Go, Java, Node.js, [[order.group]] id = "google.utils.label-image" +# The Ruby functions order group. Similar to the generic Ruby +# applications order group above but uses the GOOGLE_FUNCTION_TARGET +# env var to set the container entrypoint. +[[order]] + [[order.group]] + id = "google.ruby.runtime" + + [[order.group]] + id = "google.utils.archive-source" + optional = true + + [[order.group]] + id = "google.ruby.bundle" + + [[order.group]] + id = "google.ruby.functions-framework" + + [[order.group]] + id = "google.utils.label-image" + ####### # PHP # ####### diff --git a/builders/gcp/base/google.22.builder.toml b/builders/gcp/base/google.22.builder.toml index 776c04b9b..f168183b7 100644 --- a/builders/gcp/base/google.22.builder.toml +++ b/builders/gcp/base/google.22.builder.toml @@ -128,6 +128,10 @@ description = "Ubuntu 22.04 base image with buildpacks for .NET, Dart, Go, Java, id = "google.python.missing-entrypoint" uri = "python/missing_entrypoint.tgz" +[[buildpacks]] + id = "google.utils.archive-source" + uri = "archive_source.tgz" + [[buildpacks]] id = "google.utils.label-image" uri = "label_image.tgz" @@ -136,6 +140,10 @@ description = "Ubuntu 22.04 base image with buildpacks for .NET, Dart, Go, Java, id = "google.ruby.runtime" uri = "ruby/runtime.tgz" +[[buildpacks]] + id = "google.ruby.functions-framework" + uri = "ruby/functions_framework.tgz" + [[buildpacks]] id = "google.ruby.rubygems" uri = "ruby/rubygems.tgz" @@ -550,6 +558,26 @@ description = "Ubuntu 22.04 base image with buildpacks for .NET, Dart, Go, Java, [[order.group]] id = "google.utils.label-image" +# The Ruby functions order group. Similar to the generic Ruby +# applications order group above but uses the GOOGLE_FUNCTION_TARGET +# env var to set the container entrypoint. +[[order]] + [[order.group]] + id = "google.ruby.runtime" + + [[order.group]] + id = "google.utils.archive-source" + optional = true + + [[order.group]] + id = "google.ruby.bundle" + + [[order.group]] + id = "google.ruby.functions-framework" + + [[order.group]] + id = "google.utils.label-image" + ####### # PHP # ####### diff --git a/tools/pull-images.sh b/tools/pull-images.sh index 1659a9158..d68bb98cd 100755 --- a/tools/pull-images.sh +++ b/tools/pull-images.sh @@ -29,8 +29,12 @@ readonly candidate="latest" echo "Pulling stack images for ${product}/${runtime}" if [[ "${product}" == "gcp" ]]; then + # We pull both the google-22 and the google-18 images, because the OSS builder + # supports both. docker pull "gcr.io/buildpacks/${product}/run:${candidate}" docker pull "gcr.io/buildpacks/${product}/build:${candidate}" + docker pull "gcr.io/buildpacks/google-22/build:${candidate}" + docker pull "gcr.io/buildpacks/google-22/run:{candidate}" else docker pull "gcr.io/${project}/buildpacks/${runtime}/run:${candidate}" docker pull "gcr.io/${project}/buildpacks/${runtime}/build:${candidate}"