buildpacks icon indicating copy to clipboard operation
buildpacks copied to clipboard

Using `GOOGLE_BUILDABLE` in multi-handler Golang project

Open nikcorg opened this issue 3 years ago • 3 comments

I have a project which in a single codebase contains several handlers that share common code. I was having issues in the actual project, so I made a mock project to reproduce the issue. It has a layout like:

/common
   utils.go
/beep
   handler.go
/boop
   handler.go

Where /common contains shared code and the other directories the various handlers.

Building fails with the error

Unable to extract package name: unable to find Go package in /workspace/serverless_function_source_code

I've attempted several variations of the value in GOOGLE_BUILDABLE (leading slash, no leading slash, trailing slash etc) as well as including and excluding any and all hints towards which builder and runtime to use. The end result is invariably the same.

Building:

$ pack build --builder gcr.io/buildpacks/builder:v1 --env GOOGLE_FUNCTION_SIGNATURE_TYPE=http --env GOOGLE_FUNCTION_TARGET=Handler --env GOOGLE_BUILDABLE=./beep --env GOOGLE_RUNTIME=go multi_beep
v1: Pulling from buildpacks/builder
Digest: sha256:f3556c4ae539c9bc965883ab870c579bf84c023adcbbc34ed2afccc588701c84
Status: Image is up to date for gcr.io/buildpacks/builder:v1
v1: Pulling from buildpacks/gcp/run
Digest: sha256:66fca732b12b7cfbd512a82f1408df348e9a7dc77345738d8555bced2bfd858a
Status: Image is up to date for gcr.io/buildpacks/gcp/run:v1
===> DETECTING
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            0.0.1
===> ANALYZING
Previous image with name "multi_beep" not found
===> RESTORING
===> BUILDING
=== Go - Runtime ([email protected]) ===
Using runtime version from go.mod: 1.16
Installing Go v1.16
--------------------------------------------------------------------------------
Running "bash -c curl --fail --show-error --silent --location --retry 3 https://dl.google.com/go/go1.16.linux-amd64.tar.gz | tar xz --directory /layers/google.go.runtime/go --strip-components=1"
Done "bash -c curl --fail --show-error --silent --location --retry..." (11.0994366s)
=== 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=/tmp/serverless_function_app815892821)"
2021/05/06 22:02:24 Unable to extract package name: 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..." (433.8188ms)
Failure: (ID: 7a420ccf) 2021/05/06 22:02:24 Unable to extract package name: 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://github.com/GoogleCloudPlatform/buildpacks/blob/main/README.md
If you think you've found an issue, please report it:
 -> https://github.com/GoogleCloudPlatform/buildpacks/issues/new
--------------------------------------------------------------------------------
ERROR: failed to build: exit status 1
ERROR: failed to build: executing lifecycle: failed with status code: 145

Environment:

$ pack version
0.18.1+git-b5c1a96.build-2373

$ docker version
Client: Docker Engine - Community
 Cloud integration: 1.0.12
 Version:           20.10.5
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        55c4c88
 Built:             Tue Mar  2 20:13:00 2021
 OS/Arch:           darwin/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.5
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       363e9a8
  Built:            Tue Mar  2 20:15:47 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.4
  GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc:
  Version:          1.0.0-rc93
  GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

$ uname -a
Darwin developers-MacBook-Pro.local 19.6.0 Darwin Kernel Version 19.6.0: Mon Apr 12 20:57:45 PDT 2021; root:xnu-6153.141.28.1~1/RELEASE_X86_64 x86_64

nikcorg avatar May 06 '21 22:05 nikcorg

@juliehockett @mtraver @lukasberger The Go Functions Framework buildpack seems to expect that the function source is in the base directory? In this case the user's source is in a subdirectory. Could we use GOOGLE_FUNCTION_TARGET=beep.Handler to handle this kind of situation?

briandealwis avatar May 10 '21 16:05 briandealwis

GOOGLE_FUNCTION_TARGET is what I used as my workaround for now, sticking all my handlers in a single top-level package. The side-effect of having to bundle everything in a single package, means that the binary will include source code that will never be used.

Just to clarify to avoid any misunderstandings, my desire is to be able to have each handler in their own package.

nikcorg avatar May 11 '21 13:05 nikcorg

Similar to #189 , we should probably do it for both Go and Java runtimes

jama22 avatar Jan 30 '23 22:01 jama22