-
Notifications
You must be signed in to change notification settings - Fork 14
Description
A typical go.work setup (Go 1.18+ Workspaces) causes the build to fail in the teardown step, when running with BP_TARGETS="./sub".
It appears the builder only checks for go.mod (and not go.work), so the builder assumes a pre-module (legacy) GOPATH app.
Workaround
My deployment works by adding an empty wrapper go.mod in the project root: go mod init wrapper
This tricks the buildpack into assuming the (modern) go module build, which coincidentally fixes the build without breaking the go build command (in my case).
Expected Behavior
Build should succeed.
Current Behavior
latest: Pulling from paketobuildpacks/builder
Digest: sha256:efdf0c991248fbbf949bf33ff8752b1ba22828d5a0f7c4481608172d0011ee1d
Status: Image is up to date for paketobuildpacks/builder:latest
base-cnb: Pulling from paketobuildpacks/run
Digest: sha256:960420f8e05845e9acbc4e04de77dc852ca0823bbdf640d9e9f4131a89f8d1fe
Status: Image is up to date for paketobuildpacks/run:base-cnb
0.15.3: Pulling from buildpacksio/lifecycle
Digest: sha256:e2a5fa066b2070fa9dc0837cd09a15b2e404adbac3e2f94c8ea99a8cbe0045d3
Status: Image is up to date for buildpacksio/lifecycle:0.15.3
===> ANALYZING
[analyzer] Restoring data for SBOM from previous image
===> DETECTING
[detector] 3 of 8 buildpacks participating
[detector] paketo-buildpacks/ca-certificates 3.5.1
[detector] paketo-buildpacks/go-dist 2.2.4
[detector] paketo-buildpacks/go-build 2.0.9
===> RESTORING
[restorer] Restoring metadata for "paketo-buildpacks/ca-certificates:helper" from app image
[restorer] Restoring metadata for "paketo-buildpacks/go-dist:go" from cache
[restorer] Restoring metadata for "paketo-buildpacks/go-build:targets" from app image
[restorer] Restoring metadata for "paketo-buildpacks/go-build:gocache" from cache
[restorer] Restoring data for "paketo-buildpacks/go-dist:go" from cache
[restorer] Restoring data for "paketo-buildpacks/go-build:gocache" from cache
[restorer] Restoring data for SBOM from cache
===> BUILDING
[builder]
[builder] Paketo Buildpack for CA Certificates 3.5.1
[builder] https://github.com/paketo-buildpacks/ca-certificates
[builder] Launch Helper: Reusing cached layer
[builder] Paketo Buildpack for Go Distribution 2.2.4
[builder] Resolving Go version
[builder] Candidate version sources (in priority order):
[builder] <unknown> -> ""
[builder]
[builder] Selected Go version (using <unknown>): 1.18.10
[builder]
[builder] Executing build process
[builder] Installing Go 1.18.10
[builder] Completed in 4.059s
[builder]
[builder] Generating SBOM for /layers/paketo-buildpacks_go-dist/go
[builder] Completed in 0s
[builder]
[builder] Paketo Buildpack for Go Build 2.0.9
[builder] Executing build process
[builder] Running 'go build -o /layers/paketo-buildpacks_go-build/targets/bin -buildmode pie -trimpath ./sub'
[builder] Completed in 7.42s
[builder]
[builder] failed to teardown GOPATH: unlinkat /tmp/gopath4127721619/pkg/mod/github.com/gorilla/[email protected]/example_route_test.go: permission denied
[builder] ERROR: failed to build: exit status 1
Possible Solution
Perhaps add a check for presence of go.work in the path manager.
Steps to Reproduce
go.work in app root:
go 1.19
use ./sub
The sub directory contains the simple sample app (which has its own go.mod file, see samples/go/mod)
Motivations
This took an unreasonable amount of time to track down, perhaps because I'm unused to buildpacks. I was deploying with fly.io and thought it was a problem on their end until I finally came down to the buildpack itself. Even then I wasn't sure if it was a permission error with my files. It would be helpful if the diagnostics could help differentiate between internal errors in the buildpack vs external errors (which I assume are much more common day-to-day).
Also, I still don't know how to test the fix locally. How can I do that?