Skip to content

Commit

Permalink
Add buildpacks configuration for ruby27
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 326113166
Change-Id: I00b66f0ffd94d180da776f5a7ab1c93f44ea55c8
  • Loading branch information
mtraver authored and Copybara-Service committed Aug 11, 2020
1 parent 02d0723 commit 941c0ab
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 1 deletion.
2 changes: 2 additions & 0 deletions builders/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ package_group(
"//builders/gae/ruby26",
"//builders/gae/ruby27",
"//builders/gcf/ruby26",
"//builders/gcf/ruby27",
"//builders/gcp/base",
],
)
Expand All @@ -88,5 +89,6 @@ package_group(
"//builders/gcf/php74",
"//builders/gcf/python38",
"//builders/gcf/ruby26",
"//builders/gcf/ruby27",
],
)
16 changes: 16 additions & 0 deletions builders/gcf/ruby27/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
load("//tools:defs.bzl", "builder")

package(default_visibility = ["//builders/gcf/ruby27/acceptance:__pkg__"])

licenses(["notice"])

builder(
name = "builder",
buildpacks = [
"//cmd/ruby/functions_framework:functions_framework.tgz",
"//cmd/ruby/bundle:bundle.tgz",
"//cmd/utils/archive_source:archive_source.tgz",
"//cmd/utils/label:label.tgz",
],
image = "gcf/ruby27",
)
34 changes: 34 additions & 0 deletions builders/gcf/ruby27/acceptance/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

licenses(["notice"])

exports_files(["config.yaml"])

go_library(
name = "acceptance",
srcs = ["acceptance.go"],
importpath = "github.com/GoogleCloudPlatform/buildpacks/" + package_name(),
)

go_test(
name = "acceptance_test",
size = "enormous",
srcs = ["acceptance_test.go"],
args = [
"-test-data=$(location //builders/testdata/ruby:functions)",
"-structure-test-config=$(location :config.yaml)",
"-builder-source=$(location //builders/gcf/ruby27:builder.tar)",
"-builder-prefix=gcfruby27-acceptance-test-",
],
data = [
":config.yaml",
"//builders/gcf/ruby27:builder.tar",
"//builders/testdata/ruby:functions",
],
embed = [":acceptance"],
rundir = ".",
tags = [
"local",
],
deps = ["//pkg/acceptance"],
)
16 changes: 16 additions & 0 deletions builders/gcf/ruby27/acceptance/acceptance.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// Package acceptance implements acceptance tests for a buildpack builder.
package acceptance
101 changes: 101 additions & 0 deletions builders/gcf/ruby27/acceptance/acceptance_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// Copyright 2020 Google LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package acceptance

import (
"testing"

"github.com/GoogleCloudPlatform/buildpacks/pkg/acceptance"
)

func init() {
acceptance.DefineFlags()
}

func TestAcceptance(t *testing.T) {
builder, cleanup := acceptance.CreateBuilder(t)
t.Cleanup(cleanup)

testCases := []acceptance.Test{
{
Name: "function with dependencies",
App: "with_dependencies",
},
{
Name: "function with runtime env var",
App: "with_env_var",
RunEnv: []string{"FOO=foo"},
},
{
Name: "function in fn_source file",
App: "with_fn_source",
Env: []string{"GOOGLE_FUNCTION_SOURCE=sub_dir/custom_file.rb"},
},
}

for _, tc := range testCases {
tc := tc
t.Run(tc.Name, func(t *testing.T) {
t.Parallel()

tc.Path = "/testFunction"
tc.Env = append(tc.Env,
"GOOGLE_FUNCTION_TARGET=testFunction",
"GOOGLE_RUNTIME=ruby27",
)
tc.FilesMustExist = append(tc.FilesMustExist,
"/layers/google.utils.archive-source/src/source-code.tar.gz",
"/workspace/.googlebuild/source-code.tar.gz",
)

acceptance.TestApp(t, builder, tc)
})
}
}

func TestFailures(t *testing.T) {
builder, cleanup := acceptance.CreateBuilder(t)
t.Cleanup(cleanup)

testCases := []acceptance.FailureTest{
{
App: "fail_ruby_version",
MustMatch: "but your Gemfile specified",
},
{
App: "fail_framework_missing",
MustMatch: "unable to execute functions-framework",
},
{
Name: "must fail due to missing source file",
App: "with_dependencies",
Env: []string{"GOOGLE_FUNCTION_SOURCE=missing_file.rb"},
MustMatch: "GOOGLE_FUNCTION_SOURCE specified file 'missing_file.rb' but it does not exist",
},
}

for _, tc := range testCases {
tc := tc
t.Run(tc.App, func(t *testing.T) {
t.Parallel()

tc.Env = append(tc.Env,
"GOOGLE_FUNCTION_TARGET=testFunction",
"GOOGLE_RUNTIME=ruby27",
)

acceptance.TestBuildFailure(t, builder, tc)
})
}
}
28 changes: 28 additions & 0 deletions builders/gcf/ruby27/acceptance/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2020 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Test container structure using a centigrate image with a custom entrypoint.

# See https://github.com/GoogleContainerTools/container-structure-test for the configuration format.

schemaVersion: '2.0.0'

metadataTest:
env:
- key: PORT
value: 8080
exposedPorts: ['8080']
entrypoint: ['/cnb/lifecycle/launcher']
cmd: []
workdir: '/srv'
39 changes: 39 additions & 0 deletions builders/gcf/ruby27/builder.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
description = "Builder for the GCF Ruby 2.6 runtime"

[[buildpacks]]
id = "google.ruby.bundle"
uri = "bundle.tgz"

[[buildpacks]]
id = "google.ruby.functions-framework"
uri = "functions_framework.tgz"

[[buildpacks]]
id = "google.utils.archive-source"
uri = "archive_source.tgz"

[[buildpacks]]
id = "google.utils.label"
uri = "label.tgz"

[[order]]

[[order.group]]
id = "google.utils.archive-source"

[[order.group]]
id = "google.ruby.bundle"

[[order.group]]
id = "google.ruby.functions-framework"

[[order.group]]
id = "google.utils.label"

[stack]
id = "google.ruby27"
build-image = "gcr.io/gae-runtimes/buildpacks/ruby27/build"
run-image = "gcr.io/gae-runtimes/buildpacks/ruby27/run"

[lifecycle]
version = "0.9.0"
5 changes: 4 additions & 1 deletion cmd/utils/archive_source/buildpack.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,7 @@ id = "google.python38"
id = "google.python39"

[[stacks]]
id = "google.ruby26"
id = "google.ruby26"

[[stacks]]
id = "google.ruby27"

0 comments on commit 941c0ab

Please sign in to comment.