How to structure more than one function on git for automated deploy on Google Cloud Functions?

懵懂的女人 提交于 2019-12-31 04:06:27

问题


I'm start using the Google Cloud Functions and I've see that has an option to make an automated deploy from the bitbucket. I have multiple functions to deploy, should I have one repo per functions or can I have one repo but divided by directories or something else?

that is what I'm talking about: Deploying from Source Control

Thanks.


回答1:


You can have multiple functions in a single repo. A common structure would be as follows:

.
├── common
│   ├── module1.py
│   └── module2.py
├── main.py
└── requirements.txt

Where main.py contains both functions:

from common import module1, module2

def cloudfunction1(request):
    ...

def cloudfunction2(request):
    ...

And you deploy those functions either directly by name:

$ gcloud beta functions deploy cloudfunction1 --runtime python37 --trigger-http --source https://source.developers.google.com/...
$ gcloud beta functions deploy cloudfunction2 --runtime python37 --trigger-http --source https://source.developers.google.com/...

Or by entrypoint:

$ gcloud beta functions deploy foo --runtime python37 --entry-point cloudfunction1 --trigger-http --source https://source.developers.google.com/...
$ gcloud beta functions deploy bar --runtime python37 --entry-point cloudfunction2 --trigger-http --source https://source.developers.google.com/...


来源:https://stackoverflow.com/questions/54158294/how-to-structure-more-than-one-function-on-git-for-automated-deploy-on-google-cl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!