googlearchive / cloud-functions-emulator

A local emulator for deploying, running, and debugging Google Cloud Functions.
https://github.com/GoogleCloudPlatform/cloud-functions-emulator/wiki
Apache License 2.0
827 stars 115 forks source link

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

Open MartinSahlen opened 7 years ago

MartinSahlen commented 7 years ago

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

This should work.

now, try

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!

jmdobry commented 7 years ago

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.

MartinSahlen commented 7 years ago

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?

jmdobry commented 7 years ago

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?

MartinSahlen commented 7 years ago

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.

jmdobry commented 7 years ago

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

MartinSahlen commented 7 years ago

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 commented 7 years ago

The question is if this I bug or not?