Authenticating Private Go Modules in Google App Engine Standard with Go 1.11
When updating a Go App Engine Standard project to Go 1.11 modules, authentication for private modules can pose a challenge. By default, the Google Cloud build system does not have access to private repositories.
The Error:
When attempting to deploy a project that includes private modules, an error similar to the following may occur:
ERROR: (gcloud.app.deploy) Error Response: [9] Cloud build <GUI> status: FAILURE. Build error details: go: bitbucket.org/[email protected]: https://api.bitbucket.org/2.0/repositories/myPrivateRepo?fields=scm: 403 Forbidden
Can It Be Done?
Yes, it is possible to authenticate private modules in App Engine Standard using Go 1.11 modules. However, the migration documentation's guidance on moving files to the GOPATH is misleading. The new module system is indeed designed to keep code outside of the GOPATH.
Solution: Using Module Replace
Instead of managing credentials, a preferable solution is to use Go's module replace functionality. This allows the local project to use a local copy of the private module during the build.
Method:
module myServiceGAE require ( bitbucket.org/me/myService v0.0.0 google.golang.org/appengine v1.4.0 ) replace bitbucket.org/me/myService => ./src replace bitbucket.org/me/myModule => ./modules/utils
Pros:
Cons:
The above is the detailed content of How to Authenticate Private Go Modules in Google App Engine Standard with Go 1.11?. For more information, please follow other related articles on the PHP Chinese website!