【问题标题】:Google cloud build with Compute Engine使用 Compute Engine 构建 Google 云
【发布时间】:2020-01-05 20:23:55
【问题描述】:

我想将 Cloud Build 与提交触发器一起使用以自动 fetch updated repo 并在 Compute Engine 实例上运行 sudo supervisorctl restart

Cloud Build设置页面,有一个连接Compute Engine的选项,但是目前我只找到了包括Kubernetes Engine的例子和 App Engine here

有可能实现吗?这是进行更新的正确方法吗?还是我应该使用startup-script 重新启动实例?

【问题讨论】:

    标签: google-cloud-platform google-compute-engine google-cloud-build


    【解决方案1】:

    Github 中有一个来自 cloud-builders-community 的 repo,可能正是您正在寻找的。​​p>

    如上述链接中所述,它确实通过以下步骤将 cloud Build 连接到 Compute Engine:

    1. 将在您的 Container Builder 工作区中创建一个临时 SSH 密钥

    2. 将使用您配置的标志启动一个实例

    3. 工作区将被复制到远程实例

    4. 您的命令将在该实例的工作区中运行

    5. 工作区将被复制回您的 Container Builder 工作区

    您需要创建具有创建和销毁 Compute Engine 权限的适当 IAM 角色:

    export PROJECT=$(gcloud info --format='value(config.project)')
    export PROJECT_NUMBER=$(gcloud projects describe $PROJECT --format 'value(projectNumber)')
    export CB_SA_EMAIL=$PROJECT_NUMBER@cloudbuild.gserviceaccount.com
    gcloud services enable cloudbuild.googleapis.com
    gcloud services enable compute.googleapis.com
    gcloud projects add-iam-policy-binding $PROJECT --member=serviceAccount:$CB_SA_EMAIL --role='roles/iam.serviceAccountUser' --role='roles/compute.instanceAdmin.v1' --role='roles/iam.serviceAccountActor'
    

    然后您可以使用类似于以下内容的方式配置您的构建步骤:

    steps:
    - name: gcr.io/$PROJECT_ID/remote-builder
      env:
        - COMMAND=sudo supervisorctl restart
    

    您还可以在 Github 存储库的 examples 部分找到更多信息。

    【讨论】:

      猜你喜欢
      • 2019-03-09
      • 2017-05-11
      • 2018-02-14
      • 2018-04-28
      • 2019-05-06
      • 1970-01-01
      • 2020-01-15
      • 2017-03-02
      • 1970-01-01
      相关资源
      最近更新 更多