适用于 Cloud Run 的连接器

定义用于在工作流内访问 Cloud Run 的内置函数的 Workflows 连接器。

深入探索

如需查看包含此代码示例的详细文档,请参阅以下内容:

代码示例

YAML

# This workflow demonstrates how to use the Cloud Run connector:
# Create a new service and then delete it
# A location must be specified
# Expected output is the `delete_service` response with a "Success" status
- init:
    assign:
      - service_name: "test-service"
      - project: ${sys.get_env("GOOGLE_CLOUD_PROJECT_ID")}
- create_service:
    call: googleapis.run.v1.namespaces.services.create
    args:
      location: "us-central1"
      parent: ${"namespaces/" + project}
      body:
        apiVersion: "serving.knative.dev/v1"
        kind: "Service"
        metadata:
          name: ${service_name}
          namespace: ${project}
        spec:
          traffic:
            latest_revision: true
            percent: 100
          template:
            metadata:
              labels:
                serving.knative.dev/type: "container"
            spec:
              containers:
                - image: "us-docker.pkg.dev/cloudrun/container/hello:latest"
    result: create_response
- get_service:
    call: googleapis.run.v1.namespaces.services.get
    args:
      name: ${"namespaces/" + project + "/services/" + service_name}
      location: "us-central1"
    result: get_response
- delete_service:
    call: googleapis.run.v1.namespaces.services.delete
    args:
      location: "us-central1"
      name: ${"namespaces/" + project + "/services/" + service_name}
    result: delete_response
- return:
    return: ${delete_response}

后续步骤

如需搜索和过滤其他 Google Cloud 产品的代码示例,请参阅 Google Cloud 示例浏览器