micro / services

Real World Micro Services
Apache License 2.0
1.25k stars 137 forks source link

Deploy cloud function from a local definition #367

Closed Ishan27g closed 2 years ago

Ishan27g commented 2 years ago

Hi, the functions service can deploy and run serverless functions from a Git repository. It would be useful to deploy a function from a local .go file instead of the git repository, similar to Google's functions-framework-go I can have a go at this feature if it sounds like a good addition

asim commented 2 years ago

If you can map and explain how that would work we welcome the change.

Ishan27g commented 2 years ago

The existing function service can me modified -

  1. The deploy-request variable repo can be set as an absolute/path/to/local/go/file . Or A new var can be added to denote local/remote. The local file ( via repo ) with the exported function (via entrypoint) can then be optionally validated to ensure it has the valid param signature.

  2. Deploying this function would not be any different line 329 so long as fn.Entrypoint has a valid param-signature. It would just skip using the git package. - The git package could also be modified to skip to a local dir without doing the checkout

  3. The line 339 can then be set according to the absolute path or the git.repo

asim commented 2 years ago

I guess the assumption you're making here is that the function service is actually running on your machine as opposed to in the cloud.

Ishan27g commented 2 years ago

oops, is that not the case when my env is set to local?

asim commented 2 years ago

Sure but the case then has zero value when we actually run this in the cloud and remotely which is the point of the software, unless the code is located with the machine running the services. So it's just a case of understanding what you're optimising for.

Ishan27g commented 2 years ago

Yea that makes sense. Cheers

asim commented 2 years ago

I'm happy to accept a PR if you still feel like it's a value add feature that you are personally using.

Ishan27g commented 2 years ago

I don't see any use-cases outside of local development, so now i'm not sure if its worthwhile. But I can probably pitch in for one of the existing issues, maybe Lists Api? Can you give some information about that? I was thinking, maybe lists could reuse notes

asim commented 2 years ago

Sure, I think actually if someone is running micro locally it might be useful but equally a potential design pattern for the future where the source is actually mounted as a networked filesystem. There's no reason github couldn't be mounted that way :)

On lists. It's the idea of creating a list for anything really, waitlist, mailing list, todo list, etc. It could reuse notes but equally might be easy enough to copy the service as the storage will then at least be in a separate table for lists.

Ishan27g commented 2 years ago

Just thinking out loud, what if the local-source files could be transferred to the remote / cloud machine? ( not sure if micro has file transfer or some similar functionality). The locally transferred files could then be deployed as discussed earlier .

Ive got an idea about lists, will update soon

asim commented 2 years ago

https://github.com/micro/services/pull/397/files

This is a simple solution that just takes in the source file. It's only useful for single file operations but it works.

asim commented 2 years ago

Functions now supports a "source" argument that takes source code and deploys it. This only works for single files but it's a starting point.