【问题标题】:Migrating google cloud functions from one project to another in GCP?在 GCP 中将谷歌云功能从一个项目迁移到另一个项目?
【发布时间】:2020-05-14 16:16:59
【问题描述】:

我有一些云功能。我使用 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。

【问题讨论】:

    标签: google-cloud-platform google-cloud-functions google-cloud-build google-source-repositories


    【解决方案1】:

    当您运行 Cloud Build 时,some variable are set automatically,就像当前项目一样。功能部署环境默认使用当前项目。

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

    • 定义一个替换变量,例如_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
    
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-01
      • 1970-01-01
      • 2020-06-12
      • 1970-01-01
      • 2021-01-01
      • 1970-01-01
      相关资源
      最近更新 更多