Friday, June 17, 2016

Golang, appengine and unsafe imports

This post explains a common problem with Golang on appengine, but I still have no good fix for this problem. I'll leave it here just to explain it, in hope that sooner or later somebody will suggest a good solution in the comments section :)

On Google Cloud Platform (GCP) you have a few ways to use golang server-side. You can use appengine, the flexible environment (FE) or just plain VMs. Now, I think that their idea is to slowly move customers to the flexible environment, but I'm reluctant to do that for one reason -- deploying on FE is sloooow (for 5-10 minutes, comparing to 30s for appengine, including the start of the first instance).

In the long-term I definitely think I'll move to FE, because:
  • The unsafe import problem (explained in this post)
  • The current Appengine SDK works with go1.6, but future releases will (probably) lag behind new go releases by a few years. It was stuck with 1.4 for a long time.

But now I'm pretty happy with the current state of the Go support on Appengine. Except when one of my dependencies (or a dependency of a dependency) imports "unsafe". The unsafe package is not allowed on Appengine, and you get an error like this:
ERROR    2016-06-14 13:12:21,813 go_runtime.py:181] Failed to build Go application: (Executed command: /.../go_appengine/goroot/bin/go-app-builder -app_base /.../golang/src/... -arch 6 -dynamic -goroot /.../goroot -nobuild_files ^.*bytestream.go -unsafe -gopath /.../golang -print_extras_hash app.go)
2016/06/14 15:12:21 go-app-builder: Failed parsing input: parser: bad import "unsafe" in github.com/go-openapi/runtime/client_auth_info.go from GOPATH
Now, when this happens, first of all you will not get a correct filename where the import is. In my case it reported github.com/go-openapi/runtime/client_auth_info.go but the import was in github.com/go-openapi/runtime/text.go. So, you will get a random file in the same package when the import is.

What to do? Unfortunately, I have only two half-solutions. You can remove/change the dependency or you can try adding:
nobuild_files: ^github.com/go-openapi/runtime/text.go 
...in your app.yaml. And hope that the build will work without that file.

Any idea is welcome.

No comments:

Post a Comment