0

Trying to deploy my GO application with Cloud SQL using gcloud app deploy but build is failing every time with package not found error. Not sure where it is picking the GOPATH from. Is it possible to change the GOPATH in google cloud engine.

  Step #0: main.go:9:2: cannot find package "github.com/gin-gonic/gin"
  in any of: Step #0:   /usr/local/go/src/github.com/gin-gonic/gin (from
  $GOROOT) Step #0:     /workspace/_gopath/src/github.com/gin-gonic/gin
  (from $GOPATH) Step #0: main.go:10:2: cannot find package
  "github.com/go-sql-driver/mysql" in any of: Step #0:
    /usr/local/go/src/github.com/go-sql-driver/mysql (from $GOROOT) Step
  #0:   /workspace/_gopath/src/github.com/go-sql-driver/mysql (from $GOPATH) Step #0: main.go:8:2: cannot find package
  "google.golang.org/appengine" in any of: Step #0:
    /usr/local/go/src/google.golang.org/appengine (from $GOROOT) Step #0:
    /workspace/_gopath/src/google.golang.org/appengine (from $GOPATH)

I have import statements to include the above libraries. My local GOPATH is set to /Users/amar.jain/go/ and it is trying to use /workplace/_gopath/

I'm also using the GO App Engine SDK.

Mangu
  • 3,160
  • 2
  • 25
  • 42
Amar Jain
  • 1,698
  • 1
  • 14
  • 11
  • Are you running an example from the docs? Could you please provide sample code to reproduce the issue? – Victor M Perez Jun 04 '18 at 14:33
  • I have import statements to include the above libraries. My local GOPATH is set to /Users/amar.jain/go/ and it is trying to use /workplace/_gopath/ – Amar Jain Jun 04 '18 at 17:20
  • Infomration is quite insufficent. Are you using goappengine sdk for development ? – Manish Champaneri Jun 05 '18 at 09:31
  • @AmarJain, if you are using multiple `GOPATH`s, try to set `/Users/amar.jain/go/ ` as the first item in the list. Look at this answer https://stackoverflow.com/a/36017866/9015852 and the comment below it, which is also very useful for your case. – Victor M Perez Jun 05 '18 at 10:23
  • @mchampaneri Yes I am using the goappengine sdk. What other information do you need? @Victor No there is only one GOPATH set to `/Users/amar.jain/go/` – Amar Jain Jun 06 '18 at 12:40
  • goappengine has its own goroot. Do you have added goappengine to your env variable. Check the setup docs of goappengine. – Manish Champaneri Jun 07 '18 at 05:41
  • 1
    Please share a minimal working example of what you're doing so we can try to reproduce the issue. See if this question is related to your case https://stackoverflow.com/questions/49717504/gcloud-deploy-app-cannot-find-import-packages-golang – Victor M Perez Jun 07 '18 at 11:25
  • Thanks @VictorHerasmePerez.. That was the exact solution. Even I had included api_version: go1 in my yaml file. That solved it. Thanks a lot :) – Amar Jain Jun 08 '18 at 07:09
  • Hello @AmarJain , would you mind posting the answer here, on your own? For future reference of the community. – Mangu Jun 11 '18 at 07:26

2 Answers2

0

As mentioned in here, the following line should be deleted from the app.yaml file when using Flexible environment:

api_version: go1

Compare an example of an app.yaml file when in Flexible and Standard.

These are the options available when configuring the Flexible environment.

Mangu
  • 3,160
  • 2
  • 25
  • 42
0

Are you using the app engine standard environment?

The app engine standard environment is picky about GOPATH, it does try to upload all files required but it often helps to vendor the dependancies and make sure the app.yaml is at the top level.

https://cloud.google.com/appengine/docs/standard/go/building-app/creating-your-application#structuring_your_application_project

Ive had problems with the standard environment when using the standard go /cmd /pkg structure for example.