Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to figure out functions-framework-go in a monorepo #257

Open
remiphilippe opened this issue Dec 9, 2024 · 0 comments
Open

Unable to figure out functions-framework-go in a monorepo #257

remiphilippe opened this issue Dec 9, 2024 · 0 comments
Assignees
Labels
P3 Low Priority question Further information is requested

Comments

@remiphilippe
Copy link

Hello,
I'm trying to figure out how to use this in a monorepo. I've got the following structure:

project
└─── go
│   └─── functions
│   │   └─── func_A
│   │   │   └─── cmd
│   │   │   │    main.go
│   │   │    code_A.go
│   │   └─── func_B
│   └─── pkg
│   │    go.mod
│   │    go.sum
└─── ui
└─── infra

each func_* folder holds multiple functions (for example one could be all the user endpoints, one all the group endpoints), but the idea is to have them run as one function per endpoint in GCP.

If I run with just go run . everything is good:

vscode ➜ .../go/function/funca/cmd $ go run .
Serving function: "Code_A"

The problem is when I try to get it to work in build pack.

When I try to build it:

vscode ➜ /workspaces/testFolder $ pack build test-build --path /workspaces/testFolder/go --builder gcr.io/buildpacks/builder:google-22 --env GOOGLE_FUNCTION_SIGNATURE_TYPE=http --env GOOGLE_FUNCTION_TARGET=Code_A --env GOOGLE_BUILDABLE=./function/funca
google-22: Pulling from buildpacks/builder
Digest: sha256:afb313a7ffc6a63057ad8379d721b5c07a5d9b83ab54af411401db0bcd3fe6f9
Status: Image is up to date for gcr.io/buildpacks/builder:google-22
latest: Pulling from buildpacks/google-22/run
Digest: sha256:4cbbb4387c9c5eebbe5b24d0bb1cc03f8d701d7abdb8730c831a2b024cc2e229
Status: Image is up to date for gcr.io/buildpacks/google-22/run:latest
===> ANALYZING
Timer: Analyzer started at 2024-12-09T02:17:59Z
Restoring data for SBOM from previous image
Timer: Analyzer ran for 8.436431ms and ended at 2024-12-09T02:17:59Z
===> DETECTING
Timer: Detector started at 2024-12-09T02:17:59Z
4 of 6 buildpacks participating
google.go.runtime             0.9.1
google.go.functions-framework 0.9.4
google.go.build               0.9.0
google.utils.label-image      0.0.2
Timer: Detector ran for 180.706901ms and ended at 2024-12-09T02:17:59Z
===> RESTORING
Timer: Restorer started at 2024-12-09T02:17:59Z
Restoring metadata for "google.go.runtime:go" from cache
Restoring metadata for "google.go.functions-framework:functions-framework" from app image
Restoring metadata for "google.go.build:bin" from app image
Restoring data for "google.go.runtime:go" from cache
Timer: Restorer ran for 2.605035902s and ended at 2024-12-09T02:18:01Z
===> BUILDING
Timer: Builder started at 2024-12-09T02:18:01Z
=== Go - Runtime ([email protected]) ===
Using latest stable Go version
2024/12/09 02:18:01 [DEBUG] GET https://go.dev/dl/?mode=json
***** CACHE HIT: "go"
Go v1.23.4 cache hit, skipping installation.
=== Go - Functions Framework ([email protected]) ===
--------------------------------------------------------------------------------
Running "go run /cnb/buildpacks/google.go.functions-framework/0.9.4/converter/get_package/main.go -dir /workspace/serverless_function_source_code (GOCACHE=/layers/google.go.functions-framework/gcpbuildpack-tmp/app)"
2024/12/09 02:18:10 Unable to extract package name and imports: unable to find Go package in /workspace/serverless_function_source_code.
exit status 1
Done "go run /cnb/buildpacks/google.go.functions-framework/0.9.4/c..." (8.251598632s)
--------------------------------------------------------------------------------
failed to build: (error ID: 38c9f277):
error extracting package name: (error ID: 7a420ccf):
2024/12/09 02:18:10 Unable to extract package name and imports: unable to find Go package in /workspace/serverless_function_source_code.
exit status 1
--------------------------------------------------------------------------------
Sorry your project couldn't be built.
Our documentation explains ways to configure Buildpacks to better recognise your project:
 -> https://cloud.google.com/docs/buildpacks/overview
If you think you've found an issue, please report it:
 -> https://github.com/GoogleCloudPlatform/buildpacks/issues/new
--------------------------------------------------------------------------------
Timer: Builder ran for 8.535698949s and ended at 2024-12-09T02:18:10Z
ERROR: failed to build: exit status 1
ERROR: failed to build: executing lifecycle: failed with status code: 51

When I try to run it from cmd, same issue:

vscode ➜ .../testFolder/go/function/funca $ pack build test-build --path /workspaces/testFolder/go --builder gcr.io/buildpacks/builder:google-22 --env GOOGLE_FUNCTION_SIGNATURE_TYPE=http --env GOOGLE_FUNCTION_TARGET=Code_A --env GOOGLE_BUILDABLE=./function/funca/cmd
google-22: Pulling from buildpacks/builder
Digest: sha256:afb313a7ffc6a63057ad8379d721b5c07a5d9b83ab54af411401db0bcd3fe6f9
Status: Image is up to date for gcr.io/buildpacks/builder:google-22
latest: Pulling from buildpacks/google-22/run
Digest: sha256:4cbbb4387c9c5eebbe5b24d0bb1cc03f8d701d7abdb8730c831a2b024cc2e229
Status: Image is up to date for gcr.io/buildpacks/google-22/run:latest
===> ANALYZING
Timer: Analyzer started at 2024-12-09T02:24:31Z
Restoring data for SBOM from previous image
Timer: Analyzer ran for 6.920068ms and ended at 2024-12-09T02:24:31Z
===> DETECTING
Timer: Detector started at 2024-12-09T02:24:31Z
4 of 6 buildpacks participating
google.go.runtime             0.9.1
google.go.functions-framework 0.9.4
google.go.build               0.9.0
google.utils.label-image      0.0.2
Timer: Detector ran for 66.727986ms and ended at 2024-12-09T02:24:31Z
===> RESTORING
Timer: Restorer started at 2024-12-09T02:24:31Z
Restoring metadata for "google.go.runtime:go" from cache
Restoring metadata for "google.go.functions-framework:functions-framework" from app image
Restoring metadata for "google.go.build:bin" from app image
Restoring data for "google.go.runtime:go" from cache
Timer: Restorer ran for 2.495483481s and ended at 2024-12-09T02:24:34Z
===> BUILDING
Timer: Builder started at 2024-12-09T02:24:34Z
=== Go - Runtime ([email protected]) ===
Using latest stable Go version
2024/12/09 02:24:34 [DEBUG] GET https://go.dev/dl/?mode=json
***** CACHE HIT: "go"
Go v1.23.4 cache hit, skipping installation.
=== Go - Functions Framework ([email protected]) ===
--------------------------------------------------------------------------------
Running "go run /cnb/buildpacks/google.go.functions-framework/0.9.4/converter/get_package/main.go -dir /workspace/serverless_function_source_code (GOCACHE=/layers/google.go.functions-framework/gcpbuildpack-tmp/app)"
2024/12/09 02:24:42 Unable to extract package name and imports: unable to find Go package in /workspace/serverless_function_source_code.
exit status 1
Done "go run /cnb/buildpacks/google.go.functions-framework/0.9.4/c..." (7.676210429s)
--------------------------------------------------------------------------------
failed to build: (error ID: 231ec39f):
error extracting package name: (error ID: 7a420ccf):
2024/12/09 02:24:42 Unable to extract package name and imports: unable to find Go package in /workspace/serverless_function_source_code.
exit status 1
--------------------------------------------------------------------------------
Sorry your project couldn't be built.
Our documentation explains ways to configure Buildpacks to better recognise your project:
 -> https://cloud.google.com/docs/buildpacks/overview
If you think you've found an issue, please report it:
 -> https://github.com/GoogleCloudPlatform/buildpacks/issues/new
--------------------------------------------------------------------------------
Timer: Builder ran for 8.028883812s and ended at 2024-12-09T02:24:42Z
ERROR: failed to build: exit status 1
ERROR: failed to build: executing lifecycle: failed with status code: 51

If I separate it in 2 modules (one module for the function folder, one for the core folder, which creates some go mod vendor fund). I can only get it to build IF the functions are declared at the root of the function module (as a package, but at the root). But I can't seem to be able to execute them.

I'm surely missing something, is anyone using a monorepo with

@HKWinterhalter HKWinterhalter added question Further information is requested P3 Low Priority labels Jan 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 Low Priority question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants