如何在 git 上构建多个函数以在 Google Cloud Functions 上自动部署? [英] How to structure more than one function on git for automated deploy on Google Cloud Functions?
问题描述
我开始使用 Google Cloud Functions,我看到它提供了从 bitbucket 进行自动部署的选项.我有多个功能要部署,我应该每个功能有一个存储库,还是可以有一个存储库但按目录或其他东西划分?
这就是我要说的:从源代码管理部署
谢谢.
您可以在一个存储库中拥有多个功能.一个常见的结构如下:
<预><代码>.├── 普通│ ├── module1.py│ └── module2.py├── main.py└── 需求.txt其中 main.py
包含两个函数:
from common import module1, module2def cloudfunction1(请求):...def cloudfunction2(请求):...
您可以直接按名称部署这些功能:
$ gcloud 函数部署 cloudfunction1 --runtime python37 --trigger-http --source https://source.developers.google.com/...$ gcloud 函数部署 cloudfunction2 --runtime python37 --trigger-http --source https://source.developers.google.com/...
或者通过入口点:
$ gcloud 函数部署 foo --runtime python37 --entry-point cloudfunction1 --trigger-http --source https://source.developers.google.com/...$ gcloud 函数部署栏 --runtime python37 --entry-point cloudfunction2 --trigger-http --source https://source.developers.google.com/...
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.
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 functions deploy cloudfunction1 --runtime python37 --trigger-http --source https://source.developers.google.com/...
$ gcloud functions deploy cloudfunction2 --runtime python37 --trigger-http --source https://source.developers.google.com/...
Or by entrypoint:
$ gcloud functions deploy foo --runtime python37 --entry-point cloudfunction1 --trigger-http --source https://source.developers.google.com/...
$ gcloud functions deploy bar --runtime python37 --entry-point cloudfunction2 --trigger-http --source https://source.developers.google.com/...
这篇关于如何在 git 上构建多个函数以在 Google Cloud Functions 上自动部署?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!