触发 Cloud Build 仅重新部署在同一存储库中更新的 GCP Cloud 功能

问题描述 投票:0回答:1

我有一些属于同一 API 系统的 GCP Cloud Functions,因此我将它们分组在同一个 GitHub 存储库中。

我的整个设置如下:

  • GitHub 存储库: 所有 API 云函数所在的真相来源。

    /src
    内Typescript中的所有函数以及编译好的JS到
    /out

  • 镜像 GCP 云源存储库: 相同的 GitHub 存储库数据,但在 GCP 上(这对于云功能来说是必需的)

  • GCP Cloud Functions: 将其

    Source
    设置为
    Cloud Source Repo
    ,将其
    Directory with source code
    设置为 GitHub 存储库中包名称的
    /out
    目录中的已编译 JS 以及他们自己的
    Entry point
    。例如:

    • func-1
      • 源代码目录:/out/func-1
      • 入口点:
        func1
    • func-2
      • 源代码目录:/out/func-2
      • 入口点:
        func2
  • 云构建触发器:监听具有此

    master
    文件的GitHub存储库
    .yaml
    分支的更改:

steps:
- name: 'gcr.io/cloud-builders/gcloud'
  args: 
    - 'functions'
    - 'deploy'
    - '--trigger-http'
    - '--entry-point'
    - 'func1'
    - '--runtime'
    - 'nodejs20'
  dir: 'out/func-1'

- name: 'gcr.io/cloud-builders/gcloud'
  args: 
    - 'functions'
    - 'deploy'
    - '--trigger-http'
    - '--entry-point'
    - 'func2'
    - '--runtime'
    - 'nodejs20'
  dir: 'out/func-2'

问题是,当我推到

master
时,我正在重新部署所有功能,无论一个功能是否更改,而另一个功能没有更改。流程是这样的:

  1. PR 获得批准并合并到
    master
    分支
  2. 因为 GitHub 的存储库
    master
    分支已更新,所以
    Cloud Source Repo
    master
    分支也已更新,因为它是镜像的。
  3. 此外,由于 GitHub 的存储库
    master
    分支已更新,因此会触发 Cloud Build 触发器并运行
    .yaml
    的命令,该命令使用
    Cloud Source Repo
  4. 中的新代码重新部署所有 Cloud Functions

所以我的问题是在步骤 3 上,如何设置

.yaml
文件以仅更改 PR 中更改的功能?还有其他方法可以解决这个问题吗?也许是 Cloud Build 的 GitHub 操作或替换变量?也不知道如何设置。

我真的很想保留设置,因此所有相关的云功能都保留在同一个存储库中。

github google-cloud-platform google-cloud-functions serverless google-cloud-build
1个回答
0
投票

您可以做到这一点的一种方法是为每个函数构建触发器。为 Cloud Functions 目录设置过滤器,然后使用“内联”而不是 yaml 文件来仅使用目标函数的构建步骤。这并不理想,但应该可以。

© www.soinside.com 2019 - 2024. All rights reserved.