Skip to content

Commit

Permalink
Add support for Nx using the GOOGLE_BUILDABLE environment variable …
Browse files Browse the repository at this point in the history
…to determine the application directory.

PiperOrigin-RevId: 651495161
Change-Id: I90d9deafca45eb3c23004d95ec7bd44cf75a1cbf
  • Loading branch information
GCP Buildpacks Team authored and copybara-github committed Jul 11, 2024
1 parent 7afa30a commit 9f79d07
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 16 deletions.
2 changes: 1 addition & 1 deletion cmd/nodejs/firebaseangular/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestDetect(t *testing.T) {
"packages/foo/index.js": "",
"packages/foo/angular.json": "",
},
envs: []string{"FIREBASE_APP_DIRECTORY=packages/foo"},
envs: []string{"GOOGLE_BUILDABLE=packages/foo"},
want: 0,
},
{
Expand Down
2 changes: 1 addition & 1 deletion cmd/nodejs/firebasenextjs/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func TestDetect(t *testing.T) {
"apps/next-app/index.js": "",
"apps/next-app/next.config.js": "",
},
envs: []string{"FIREBASE_APP_DIRECTORY=apps/next-app"},
envs: []string{"GOOGLE_BUILDABLE=apps/next-app"},
want: 0,
},
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/nodejs/firebasenx/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ import (
)

var (
versionKey = "version"
firebaseAppDirectory = "FIREBASE_APP_DIRECTORY"
versionKey = "version"
// The Nx buildpack build function sets the following environment variables to configure the build
// behavior of subsequent buildpacks.
monorepoProject = "MONOREPO_PROJECT" // The name of a project in a Nx monorepo.
Expand Down
5 changes: 1 addition & 4 deletions cmd/nodejs/firebasenx/main_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"testing"

bpt "github.com/GoogleCloudPlatform/buildpacks/internal/buildpacktest"
Expand Down Expand Up @@ -45,9 +44,7 @@ func TestBuild(t *testing.T) {
}{
{
name: "successfully read project.json",
envs: []string{
fmt.Sprintf("%s=apps/my-project", firebaseAppDirectory),
},
envs: []string{"GOOGLE_BUILDABLE=apps/my-project"},
files: map[string]string{
"index.js": "",
"nx.json": `{
Expand Down
5 changes: 4 additions & 1 deletion pkg/firebase/util/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,8 @@ go_library(
name = "util",
srcs = ["util.go"],
importpath = "github.com/GoogleCloudPlatform/buildpacks/" + package_name(),
deps = ["//pkg/gcpbuildpack"],
deps = [
"//pkg/env",
"//pkg/gcpbuildpack",
],
)
8 changes: 3 additions & 5 deletions pkg/firebase/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,16 @@ import (
"os"
"path/filepath"

gcp "github.com/GoogleCloudPlatform/buildpacks/pkg/gcpbuildpack"
)
"github.com/GoogleCloudPlatform/buildpacks/pkg/env"

var (
firebaseAppDirectory = "FIREBASE_APP_DIRECTORY"
gcp "github.com/GoogleCloudPlatform/buildpacks/pkg/gcpbuildpack"
)

// ApplicationDirectory looks up the path to the application directory from the environment. Returns
// the application root by default.
func ApplicationDirectory(ctx *gcp.Context) string {
appDir := ctx.ApplicationRoot()
if appDirEnv, exists := os.LookupEnv(firebaseAppDirectory); exists {
if appDirEnv, exists := os.LookupEnv(env.Buildable); exists {
appDir = filepath.Join(ctx.ApplicationRoot(), appDirEnv)
}
return appDir
Expand Down
2 changes: 1 addition & 1 deletion pkg/nodejs/angular.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var (
// angularVersionKey is the metadata key used to store the angular build adaptor version in the angular layer.
angularVersionKey = "version"
// PinnedAngularAdapterVersion is the version of the angular adapter that will be used.
PinnedAngularAdapterVersion = "17.2.5"
PinnedAngularAdapterVersion = "17.2.6"
)

// InstallAngularBuildAdaptor installs the angular build adaptor in the given layer if it is not already cached.
Expand Down
2 changes: 1 addition & 1 deletion pkg/nodejs/nextjs.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ var (
// nextJsVersionKey is the metadata key used to store the nextjs build adaptor version in the nextjs layer.
nextJsVersionKey = "version"
// PinnedNextjsAdapterVersion is the version of the nextjs adapter that will be used.
PinnedNextjsAdapterVersion = "14.0.4"
PinnedNextjsAdapterVersion = "14.0.5"
)

// InstallNextJsBuildAdaptor installs the nextjs build adaptor in the given layer if it is not already cached.
Expand Down

0 comments on commit 9f79d07

Please sign in to comment.