在 GCP 中将 google 云功能从一个项目迁移到另一个项目?

Migrating google cloud functions from one project to another in GCP?

我有一些云功能。我使用 cloudbuild.yaml 和 Cloud Triggers 通过源存储库部署这些云函数 cloudbuild.yaml 是..

steps:

- name: 'python:3.7'
  entrypoint: 'bash'
  args: 
    - '-c'
    - |
        pip3 install -r requirements.txt
        pytest -rP

- name: 'gcr.io/cloud-builders/gcloud'
  args:
  - functions
  - deploy
  - Function_Name
  - --runtime=python37
  - --source=https://source.developers.google.com/projects/{}/repos/{}/moveable-aliases/master/paths/{}
  - --entry-point=main
  - --trigger-topic=TOPIC_NAME
  - --region=REGION

现在我想将这个云函数从这个项目移动到另一个项目(项目 A 到项目 B)

现在我没有在这里定义我的 project_id。从哪里获取项目 ID?从服务帐户?

如何有效地将此云函数从存储库 A 移动到存储库 B?以及在项目 B 中部署它。

当您运行您的 Cloud Build 时,some variable are set automatically喜欢当前的项目。这个当前projet在部署功能的环境中默认使用。

要保持​​当前行为并添加将其扩展到下一个项目的能力,您可以这样做

  • 定义一个替代变量,例如_TARGET_PROJECT_ID
  • 默认分配当前项目

...
- name: 'gcr.io/cloud-builders/gcloud'
  args:
  - functions
  - deploy
  - Function_Name
  - --runtime=python37
  - --source=https://source.developers.google.com/projects/{}/repos/{}/moveable-aliases/master/paths/{}
  - --entry-point=main
  - --trigger-topic=TOPIC_NAME
  - --region=REGION
  - --project=$_TARGET_PROJECT_ID
substitions:
  _TARGET_PROJECT_ID: $PROJECT_ID

现在,在您的触发器(新触发器?)中或当您手动 运行 云构建时,如果需要,请指定新的 project_ID。如果否,则当前行为(在当前项目中部署)将继续。