cloud-functions-emulator icon indicating copy to clipboard operation
cloud-functions-emulator copied to clipboard

Deploying functions using shim (for a go program) does not work locally

Open MartinSahlen opened this issue 7 years ago • 7 comments

Description

The emulator does not support running a bash program that is bundled together with the index.js file and zipped. It seems it corrupts the program, in this case a simple go program. It works perfectly in the production environment. Check this repo for reference: https://github.com/MartinSahlen/go-cloud-fn

Steps to reproduce

  • go get -u github.com/goadesign/goa/...
  • go get https://github.com/MartinSahlen/go-cloud-fn
  • go get github.com/MartinSahlen/cloud-goa
  • cd $GOPATH/src/github.com/MartinSahlen/cloud-goa
  • go-cloud-fn deploy goa --trigger-http --stage-bucket

This should work.

now, try

  • go-cloud-fn deploy goa --trigger-http --emulator and observe logs / output. I get spawn ./goa ENOENT. I also observe that when try to unzip the compiled zip file that the emulator generates, the go binary fails to unzip and is left at 0 MB. Maybe something wrong with the zipping?

I realize I am giving some pretty bizarre issues, but it would be awesome if you could have a look. And it does work in production, so I this would just be a bit more awesome.

Thanks!

MartinSahlen avatar Mar 28 '17 15:03 MartinSahlen

While the Emulator does create a .zip archive, it only does so to mirror the Cloud SDK's behavior (if you provide --stage-bucket when deploying to the Emulator it will even upload the archive for you). However, the Emulator does not use the .zip archive to run your locally deployed function.

I don't think I can debug this without diving into how your go-cloud-fn tool works, especially how it communicates with the Emulator.

jmdobry avatar Apr 04 '17 04:04 jmdobry

I reckon there might be some errors with paths then. As the function references the shim (i.e. the compiled binary) through the local path using execFileSync it might be just the case that it does not have the correct path set up?

MartinSahlen avatar Apr 05 '17 12:04 MartinSahlen

Where/when exactly do you see the spawn ./goa ENOENT error? During deployment? When calling the function?

I tried to install your go libraries but couldn't get it to work. Could you provide an example of what a generated function might look like?

jmdobry avatar Apr 07 '17 16:04 jmdobry

I get the error when my function tries to call the generated binary using spawn (now changed to execFileSync, which is called goa in this case. I will get back with an example. The issue, seems to me to be something relating to file paths / working directories when the generated function is executed.

MartinSahlen avatar Apr 10 '17 10:04 MartinSahlen

What are you expecting the current working directory to be when a function is invoked?

jmdobry avatar Apr 12 '17 20:04 jmdobry

Your comment is on spot. I just got this working. If I am in the folder of the index.js it will work both locally and in the production environment. However, if I am outside and use --local-path to reference the directery of my index.js it will work in the production but fail in the emulator.

MartinSahlen avatar Jun 03 '17 15:06 MartinSahlen

The question is if this I bug or not?

MartinSahlen avatar Jun 03 '17 15:06 MartinSahlen