4

When deploying my Go services to Google AppEngine (standard), I receive an errors describing a module version not being found, while everything compiles fine.

The modules are on a private Github instance and checked out to vendor/.

A go build -mod vendor -o /dev/null ./... works in cloud-build-local, locally and in Google Cloud Build. A tag called 'v1.1.0' exists on github.com/company/gosystem:

gosystem$ git tag
v0.0.1
v0.0.2
v0.0.3
v1.0.0
v1.1.0
Failed to build app: [go build -o /tmp/staging172777881/usr/local/bin/start .] with env [PATH=/go/bin:/usr/local/go/bin:/builder/google-cloud-sdk/bin/:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOSTNAME=f3f56ce621f0 HOME=/builder/home BUILDER_OUTPUT=/builder/outputs DEBIAN_FRONTEND=noninteractive GOROOT=/usr/local/go/ GOPATH=/go GO111MODULE=on GOCACHE=/tmp/cache019702820 GOPATH=/go] failed: err=exit status 1, out="
go: finding github.com/pquerna/otp v1.1.0
go: finding github.com/gin-gonic/gin v1.4.0
go: finding github.com/pkg/errors v0.8.1
go: finding github.com/rainycape/unidecode v0.0.0-20150907023854-cb7f23ec59be
go: finding github.com/gosimple/slug v1.5.0
go: finding github.com/boombuler/barcode v1.0.0
go: finding github.com/company/gosystem v1.1.0
go: finding github.com/oblq/i18n v0.0.0-20181031085821-98eec2978e00
go: finding github.com/go-pg/pg v8.0.4+incompatible
go: finding golang.org/x/text v0.3.2
go: finding github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd
go: finding github.com/modern-go/reflect2 v1.0.1
go: finding github.com/golang/protobuf v1.3.1
go: finding github.com/stretchr/testify v1.3.0
go: finding github.com/ugorji/go/codec v0.0.0-20190204201341-e444a5086c43
go: finding github.com/gin-contrib/sse v0.0.0-20190301062529-5545eab6dad3
go: finding github.com/mattn/go-isatty v0.0.7
go: github.com/company/gosystem@v1.1.0: unknown revision v1.1.0

A grep -RI 'gosystem@' * reports nothing.

Niels
  • 61
  • 1
  • 5
  • 1
    A simple visiting of https://github.com/venclave/gosystem using a web browser returns 404. Visiting https://github.com/venclave says that "the organization has no public repositories". So it's no wonder `go` fails to fetch that repository: it does not exist. – kostix May 21 '19 at 11:08
  • If you have some other means of letting the `go` tool reach _the contents of_ that repository, consider using [the `replace` directive in the `go.mod` file](https://github.com/golang/go/wiki/Modules#when-should-i-use-the-replace-directive) to retarget the fetching operation to another URL. – kostix May 21 '19 at 11:09
  • I might have forgot to mention, but I have private access to these repos. The modules are checked out to `vendor/`. (since build works) – Niels May 21 '19 at 11:09
  • 1
    OK, then [use vendoring with `go mod`](https://github.com/golang/go/wiki/Modules#how-do-i-use-vendoring-with-modules-is-vendoring-going-away). – kostix May 21 '19 at 11:10
  • As mentioned, the go build works. I use `go build -mod vendor -o /dev/null ./...`. I did a `go mod vendor`. – Niels May 21 '19 at 11:14
  • The doc says when `go build -mod=vendor` works, it _ignores_ versioning information in the `go.mod` file. In your settup, it appears to not be the case. Hence, two points: 1) can you make sure your `vendor` directory does indeed contain correct import pathnames?; 2) run `go build` w/o redirecting its output and with `-x` to make it tell what it's doing, with much details? I also find interesting that the 1st line of your error contains `go: finding github.com/pquerna/otp v1.1.0`. – kostix May 21 '19 at 11:54
  • Heh! Weirdly enough, without `-mod vendor`, `go build` will trigger a download of the packages in `$GOPATH/pkg/mod`. I'm amazed that the build won't work, because the `vendor/` directory should contain everything because of the `go build -mod vendor`? – Niels May 21 '19 at 12:13
  • Hmm, judging from the wording of your comment, I reckon you might have wrong idea of how `/vendor` works: when using `go` toolset in the "modules" mode, vendoring actually should forfeit any attempts at downloading anything: vendoring is about carrying your deps along with your code (usually with the complete sources). So `go build -mod=vendor` must just look under `/vendor` and use what's there. – kostix May 21 '19 at 12:30
  • The thing that strikes me is that a `go build -mod vendor` shouldn't work then, or `gcloud app deploy` is not in 'vendoring mode'. – Niels May 21 '19 at 12:31
  • May it be that having `GO111MODULE=on` turns off vendoring? What happens if you set it to `auto`? The wording [here](https://golang.org/cmd/go/#hdr-Preliminary_module_support) is moot, so I'm just guessing. Also, if you really have manual checkout of _all_ the required stuff under `/vendor`, you might as well just try `GO111MODULE=off` and using unadorned `go build` (w/o `-mod=vendor`). Note that this might break eventually (somewhere past 1.12). – kostix May 21 '19 at 12:35
  • @kostix: same with `GO111MODULE=auto`: this works for `go build`, but not for `gcloud app deploy`.. – Niels May 21 '19 at 13:59
  • By the way, see [Go issue #27227](https://github.com/golang/go/issues/27227); isn't it what you're experiencing? If yes, would you please chime in and describe your use case there? – kostix May 23 '19 at 16:50
  • Ah, looks like you've already done that, thanks. – kostix May 23 '19 at 17:17

2 Answers2

2

In the end I was able to make this work by forcing go to use vendor, by adding this to the go.mod:

replace github.com/company/gosystem => ./vendor/github.com/company/gosystem
Niels
  • 61
  • 1
  • 5
1

Go uses https to fetch versions/dependencies. Even if you use vendor, Go will verify the version anyway. And since github.com/venclave/gosystem is a private repo, git can't get access to it.

There are few workarounds for this.

1 - Use ssh:

git config --global url.ssh://git@github.com/venclave.insteadOf https://github.com/venclave

2 - Use GitHub token:

Generate GITHUB_TOKEN here https://github.com/settings/tokens.

export GITHUB_TOKEN=xxx
git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic@github.com/venclave".insteadOf "https://github.com/venclave"
Alex Pliutau
  • 21,392
  • 27
  • 113
  • 143
  • I -am- fetching over SSH with key authentication and I verified everything is in `vendor/`. Else a build would never work. – Niels May 21 '19 at 13:48
  • @Niels what do you mean by saying "I am fetching over SSH"? Have you configured it using my 1st example? If not - go modules will use https, not ssh. – Alex Pliutau May 21 '19 at 14:36
  • @Niels, go get uses HTTPS, see [this](https://golang.org/doc/faq#git_https). While [importing](https://github.com/golang/go/issues/27254#issuecomment-416105629) or getting vendors populated via ssh by dep tool usually requires some git config trick: see ref [1](https://github.com/golang/dep/issues/1726#issuecomment-371207015) and [2](https://golang.github.io/dep/docs/FAQ.html#how-do-i-get-dep-to-authenticate-via-ssh-to-a-git-repo). – Sergey Narozhny May 21 '19 at 19:40
  • Also, this [one](https://stackoverflow.com/questions/27500861/whats-the-proper-way-to-go-get-a-private-repository) might be helpful. – Sergey Narozhny May 21 '19 at 19:58
  • I'm a bit confused, why should this step matter? Since I have everything I need already downloaded to `vendor/` with `go mod vendor` or `go mod download`? – Niels May 22 '19 at 06:10