-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PiperOrigin-RevId: 574312263 Change-Id: I4d2c0ad6b751151cb93a316dd36a28afaf61e308
- Loading branch information
1 parent
7ed7150
commit 1f50dcd
Showing
8 changed files
with
275 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
load("//tools:defs.bzl", "builder") | ||
|
||
licenses(["notice"]) | ||
|
||
package(default_visibility = [ | ||
"//builders/firebase/apphosting/acceptance:__pkg__", | ||
]) | ||
|
||
builder( | ||
name = "builder", | ||
buildpacks = [ | ||
"//cmd/nodejs/npm:npm.tgz", | ||
"//cmd/nodejs/pnpm:pnpm.tgz", | ||
"//cmd/nodejs/runtime:runtime.tgz", | ||
"//cmd/nodejs/yarn:yarn.tgz", | ||
], | ||
image = "firebase/apphosting", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# The Firebase App Hosting Builder | ||
This directory contains the definition of the Firebase App Hosting builder. | ||
|
||
IMPORTANT: Firebase "App Hosting" is a new product name from Firebase and unrelated to "apphosting" a.k.a. App Engine. | ||
|
||
## Build the Image | ||
To build the builder image, run: | ||
|
||
```bash | ||
bazel build //builders/firebase/apphosting:builder.image | ||
``` | ||
|
||
## Build a Test Application | ||
To build the sample application [generic/simple](../../testdata/nodejs/generic/simple/), run: | ||
|
||
```bash | ||
pack build sample-nodejs --builder gcp/firebase/apphosting --path builders/testdata/nodejs/generic/simple/ --trust-builder -v | ||
``` | ||
|
||
## Acceptance Tests | ||
To run the acceptance tests across all the products, run: | ||
|
||
```bash | ||
bazel test //builders/firebase/apphosting/acceptance:nodejs_test | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 = "nodejs_test", | ||
size = "enormous", | ||
srcs = ["nodejs_test.go"], | ||
args = [ | ||
"-test-data=$(location //builders/testdata/nodejs:generic)", | ||
"-structure-test-config=$(location :config.yaml)", | ||
"-builder-source=$(location //builders/firebase/apphosting:builder.tar)", | ||
"-builder-prefix=firebase-apphosting-nodejs-test-", | ||
], | ||
data = [ | ||
":config.yaml", | ||
"//builders/firebase/apphosting:builder.tar", | ||
"//builders/testdata/nodejs:generic", | ||
], | ||
embed = [":acceptance"], | ||
rundir = ".", | ||
tags = [ | ||
"local", | ||
], | ||
deps = ["//internal/acceptance"], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2023 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 | ||
|
||
const ( | ||
// Buildpack identifiers used to verify that buildpacks were or were not used. | ||
nodeNPM = "google.nodejs.npm" | ||
nodePNPM = "google.nodejs.pnpm" | ||
nodeRuntime = "google.nodejs.runtime" | ||
nodeYarn = "google.nodejs.yarn" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Copyright 2023 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: | ||
envVars: | ||
- key: PORT | ||
value: 8080 | ||
entrypoint: ['/cnb/process/web'] | ||
cmd: [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
// Copyright 2023 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/internal/acceptance" | ||
) | ||
|
||
func init() { | ||
acceptance.DefineFlags() | ||
} | ||
|
||
func TestAcceptanceNodeJs(t *testing.T) { | ||
imageCtx, cleanup := acceptance.ProvisionImages(t) | ||
t.Cleanup(cleanup) | ||
|
||
testCases := []acceptance.Test{ | ||
{ | ||
Name: "simple application", | ||
App: "simple", | ||
MustUse: []string{nodeRuntime, nodeNPM}, | ||
EnableCacheTest: true, | ||
}, | ||
{ | ||
// Tests a specific versions of Node.js available on dl.google.com. | ||
Name: "runtime version 16.17.1", | ||
App: "simple", | ||
Path: "/version?want=16.17.1", | ||
Env: []string{"GOOGLE_NODEJS_VERSION=16.17.1"}, | ||
MustUse: []string{nodeRuntime}, | ||
}, | ||
{ | ||
Name: "yarn", | ||
App: "yarn", | ||
MustUse: []string{nodeRuntime, nodeYarn}, | ||
MustNotUse: []string{nodeNPM, nodePNPM}, | ||
}, | ||
{ | ||
Name: "pnpm", | ||
App: "pnpm", | ||
MustUse: []string{nodeRuntime, nodePNPM}, | ||
MustNotUse: []string{nodeNPM, nodeYarn}, | ||
}, | ||
{ | ||
Name: "runtime version with npm ci", | ||
App: "simple", | ||
Path: "/version?want=16.18.1", | ||
Env: []string{"GOOGLE_RUNTIME_VERSION=16.18.1"}, | ||
MustUse: []string{nodeRuntime, nodeNPM}, | ||
MustNotUse: []string{nodePNPM, nodeYarn}, | ||
}, | ||
{ | ||
Name: "NPM version specified", | ||
// npm@8 requires nodejs@12+ | ||
VersionInclusionConstraint: ">= 12.0.0", | ||
App: "npm_version_specified", | ||
MustOutput: []string{"npm --version\n\n8.3.1"}, | ||
Path: "/version?want=8.3.1", | ||
}, | ||
} | ||
for _, tc := range acceptance.FilterTests(t, imageCtx, testCases) { | ||
tc := tc | ||
t.Run(tc.Name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
acceptance.TestApp(t, imageCtx, tc) | ||
}) | ||
} | ||
} | ||
|
||
func TestFailuresNodeJs(t *testing.T) { | ||
imageCtx, cleanup := acceptance.ProvisionImages(t) | ||
t.Cleanup(cleanup) | ||
|
||
testCases := []acceptance.FailureTest{ | ||
{ | ||
Name: "bad runtime version", | ||
App: "simple", | ||
Env: []string{"GOOGLE_RUNTIME_VERSION=BAD_NEWS_BEARS"}, | ||
MustMatch: "invalid Node.js version specified", | ||
}, | ||
} | ||
|
||
for _, tc := range testCases { | ||
tc := tc | ||
t.Run(tc.Name, func(t *testing.T) { | ||
t.Parallel() | ||
|
||
acceptance.TestBuildFailure(t, imageCtx, tc) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
description = "Builder for Firebase App Hosting" | ||
|
||
[[buildpacks]] | ||
id = "google.nodejs.npm" | ||
uri = "npm.tgz" | ||
|
||
[[buildpacks]] | ||
id = "google.nodejs.runtime" | ||
uri = "runtime.tgz" | ||
|
||
[[buildpacks]] | ||
id = "google.nodejs.yarn" | ||
uri = "yarn.tgz" | ||
|
||
[[buildpacks]] | ||
id = "google.nodejs.pnpm" | ||
uri = "pnpm.tgz" | ||
|
||
[[order]] | ||
[[order.group]] | ||
id = "google.nodejs.runtime" | ||
[[order.group]] | ||
id = "google.nodejs.yarn" | ||
|
||
[[order]] | ||
[[order.group]] | ||
id = "google.nodejs.runtime" | ||
[[order.group]] | ||
id = "google.nodejs.pnpm" | ||
|
||
[[order]] | ||
[[order.group]] | ||
id = "google.nodejs.runtime" | ||
[[order.group]] | ||
id = "google.nodejs.npm" | ||
|
||
[stack] | ||
id = "google.min.22" | ||
build-image = "gcr.io/gae-runtimes/buildpacks/stacks/google-min-22/build" | ||
run-image = "gcr.io/gae-runtimes/buildpacks/stacks/google-min-22/run" | ||
|
||
[lifecycle] | ||
version = "0.17.0" |