【问题标题】:How to retrieve the URL of a Cloud Run service with Google Workflow?如何使用 Google Workflow 检索 Cloud Run 服务的 URL?
【发布时间】:2021-03-03 01:01:19
【问题描述】:

我习惯于在 Cloud Run 上使用 CI / CD 架构进行部署。每次进行部署时,我都必须手动检索通过电子邮件发送给员工的 URL。我的目标是使用 Google Workflow 自动执行此任务。如何使用 Google Workflow 检索新服务的 URL 或 Cloud Run 服务的标签?

【问题讨论】:

    标签: google-cloud-run google-workflows


    【解决方案1】:

    这会返回云运行服务的 URL

    - initialize:
        assign:
          - project: ${sys.get_env("GOOGLE_CLOUD_PROJECT_NUMBER")}
          - zone: us-central1
          - service: service
    - getCloudRunDetails:
        call: http.get
        args:
            url: ${"https://"+zone+"-run.googleapis.com/apis/serving.knative.dev/v1/namespaces/"+project+"/services/"+service+"?alt=json"}
            auth:
                type: OAuth2
        result: bitresult
    - returnResult:
        return: ${bitresult.body.status.address.url}
    

    预期的输出是:

    argument: 'null'
    endTime: '2020-11-19T23:05:18.232772542Z'
    name: projects/<edited>describeCloudRun/executions/<edited>   
    result: '"https://<edited>uc.a.run.app"'
    startTime: '2020-11-19T23:05:17.769640039Z'
    state: SUCCEEDED
    workflowRevisionId: 000020-b11
    

    result 键中包含您的价值。

    【讨论】:

    • 也可以将return: ${bitresult.body.status.address.url}替换为return: ${bitresult.body.status.url}获取服务链接。通过return: ${bitresult.body.status.traffic[1].url},我们获得了第一个评论 URL(标签)。可以有多个评论 URL。
    【解决方案2】:

    这可以通过gcloud CLI 轻松完成,但目前 Cloud Workflows 步骤不支持该操作。目前,您唯一的选择是使用 Get Service REST API 端点。

    这是一个例子:

    TOKEN="$(gcloud auth print-access-token -q)"
    
    curl -H "Authorization: Bearer $TOKEN" \
      https://us-central1-run.googleapis.com/apis/serving.knative.dev/v1/namespaces/PROJECT_ID/services/SERVICE_NAME?alt=json
    

    在上面的示例中,注意us-central1 是区域,并将PROJECT_IDSERVICE_NAME 替换为您的区域。

    响应将包含一个 JSON 文档,其 status.address.url 将包含您的 Cloud Run 服务的 https://[...].run.app 网址。

    专业提示:要了解 REST API 调用 gcloud 命令的作用(例如 gcloud run services describe),请添加 --log-http 选项。

    【讨论】:

    • 嗨,Ahmet,一个小错误:您忘记了自动标题中的Bearer ;-)
    猜你喜欢
    • 2019-10-24
    • 2020-05-31
    • 1970-01-01
    • 2020-09-17
    • 2021-07-13
    • 2020-02-29
    • 2023-02-10
    • 2020-09-24
    • 2021-02-12
    相关资源
    最近更新 更多