Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make vendoring work with Google App Engine?

I am trying to introduce Go vendoring (storing dependencies in a folder called vendor) to an existing App Engine project. I have stored all dependencies in the vendor folder (using Godep as a helper) and it looks right, but running the application locally I get the following error:

go-app-builder: Failed parsing input: package "golang.org/x/net/context" is imported from multiple locations: "/Users/erik/go/src/github.com/xyz/abc/vendor/golang.org/x/net/context" and "/Users/erik/go/src/golang.org/x/net/context"

I believe the two locations should resolve to the same location, as Go applications should look in the vendor folder first. Is there a way to make Appengine understand that both dependencies are the same?

like image 520
emidander Avatar asked Oct 09 '16 20:10

emidander


1 Answers

I use a Makefile to move the vendor directory to a temporary GOPATH:

TMPGOPATH := $(shell mktemp -d)

deploy:
  mv vendor $(TMPGOPATH)/src
  GOPATH=$(TMPGOPATH) gcloud app deploy
  mv $(TMPGOPATH)/src vendor 

I store this Makefile at the root of my service near the vendor directory and simply use make deploy to deploy manually or from the CI.

It works with Glide, Godeps or any tool that respects the Go vendor spec.

Please note, that you really need to move the vendor directory out of the build directory, otherwise the GoAppEngine compiler will try to build the vendor dependencies, potentially causing compile errors.

like image 106
Asdine Avatar answered Sep 23 '22 00:09

Asdine