【问题标题】:How to structure more than one function on git for automated deploy on Google Cloud Functions?如何在 git 上构建多个函数以在 Google Cloud Functions 上自动部署?
【发布时间】:2019-11-14 13:07:12
【问题描述】:

我开始使用 Google Cloud Functions,我发现它可以选择从 bitbucket 进行自动部署。我有多个要部署的功能,我应该每个功能有一个 repo,还是我可以有一个 repo 但按目录或其他东西划分?

这就是我要说的: Deploying from Source Control

谢谢。

【问题讨论】:

    标签: python git google-cloud-platform google-cloud-functions bitbucket


    【解决方案1】:

    您可以在一个存储库中拥有多个功能。一个常见的结构如下:

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

    main.py 包含这两个函数:

    from common import module1, module2
    
    def cloudfunction1(request):
        ...
    
    def cloudfunction2(request):
        ...
    

    您可以直接按名称部署这些功能:

    $ 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/...
    

    或者通过入口点:

    $ 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/...
    

    【讨论】:

    • 感谢您的回答。
    • 遗憾的是 main.py 会变得非常大,加载许多模块并影响冷启动。如果我们可以为每个函数指定不同的主文件会更好。
    猜你喜欢
    • 2017-09-15
    • 2019-09-23
    • 2020-11-03
    • 2022-07-28
    • 2018-05-18
    • 2021-07-03
    • 2019-10-27
    • 2019-06-11
    相关资源
    最近更新 更多