Reputation: 11
I am using GCP Artifact Registry to store a private Go module. The module is automatically uploaded by Cloud Build when a git push
is performed. The upload is successful each time, and I can see the resulting output in Artifact Registry.
Example: Image showing module in Artifact Registry
The package path used in my program exactly matches what Artifact Registry shows:
Image showing Package path in Artifact Registry
When I try to run go mod tidy
in a project that calls this private module on my local cli, a 404 error is returned from Artifact Registry. I am logged into Google Cloud on my local cli with an account that should have ample permissions to perform this - however I'd expect a 401, if it were lack of permissions.
Full output:
$ go mod tidy
go: finding module for package australia-southeast1-go.pkg.dev/<PROJECT>/commonlibs/common
go: finding module for package australia-southeast1-go.pkg.dev/<PROJECT>/commonlibs/http
go: adminpanel imports
australia-southeast1-go.pkg.dev/<PROJECT>/commonlibs/common: cannot find module providing package australia-southeast1-go.pkg.dev/<PROJECT>/commonlibs/common: unrecognized import path "australia-southeast1-go.pkg.dev/<PROJECT>/commonlibs/common": reading https://australia-southeast1-go.pkg.dev/<PROJECT>/commonlibs/common?go-get=1: 404 Not Found
<repeated for each module>
A simple go get
returns a 404 error also:
$ go get australia-southeast1-go.pkg.dev/<PROJECT>/commonlibs
go: unrecognized import path "australia-southeast1-go.pkg.dev/<PROJECT>/commonlibs": reading https://australia-southeast1-go.pkg.dev/<PROJECT>/commonlibs?go-get=1: 404 Not Found
The golang in the program that is importing the above libraries looks like:
package main
import (
<standard imports removed>
commonhttp "australia-southeast1-go.pkg.dev/<PROJECT>/commonlibs/http"
)
<code removed>
Another example from another file in the program:
package main
import (
<removed modules>
config "australia-southeast1-go.pkg.dev/<PROJECT>/commonlibs/config"
db "australia-southeast1-go.pkg.dev/<PROJECT>/commonlibs/db"
)
The commonlibs
structure is as follows:
$ tree .
.
├── cloudbuild.yaml
├── common
│ └── common.go
├── commonlibs.go
├── config
│ ├── config.go
│ └── structs.go
├── db
│ └── db.go
├── go.mod
├── go.sum
├── http
│ └── http.go
├── network
│ └── network.go
├── rabbitmq
│ └── rabbitmq.go
└── slack
└── slack.go
This seems to match the suggested structure defined in the golang documentation.
In the commonlibs
module the go.mod looks like:
module australia-southeast1-go.pkg.dev/<PROJECT>/commonlibs
go 1.21.5
require (
<removed list>
)
require (
<removed list>
)
I have tried to resolve this by following the provided documentation on using private go modules from Artifact Repository however as the demonstration uses a path like example.com/module
I'm not actually sure if I'm using the wrong path or URL to access my private module.
This question is similar to my issue, however I'm having the problem locally whereas that question did not.
I have tried with all forms and combinations of env variables, for example the following each on their own, all together. Tried refreshing auth tokens also as per the example, however no combination seems to help.
export GOOS=linux
export GONOSUMDB=australia-southeast1-go.pkg.dev/<PROJECT>/*
export GOPROXY=https://australia-southeast1-go.pkg.dev/<PROJECT>/commonlibs,https://proxy.golang.org,direct
export GONOPROXY=github.com/GoogleCloudPlatform/artifact-registry-go-tools,australia-southeast1-go.pkg.dev/<PROJECT>/commonlibs
export GOPROXY=proxy.golang.org go run github.com/GoogleCloudPlatform/artifact-registry-go-tools/cmd/[email protected] refresh
So, I'm kinda stuck and stumped. As far as I know, this should work as presented. I'm open to suggestions of things to try, or if I've made an obvious error (likely) please point it out :)
Upvotes: 1
Views: 198