Reputation: 168
I am used to using CI / CD architecture for my deployments on Cloud Run. Each time a deployment has taken place, I have to manually retrieve the URL that I send to my employees by email. My goal is to automate this task with Google Workflow. How do I retrieve the URL of a new service or the tag of a Cloud Run service with Google Workflow ?
Upvotes: 5
Views: 1786
Reputation: 396
Google now provides built-in workflows connectors, including one for Cloud Run service.
Getting the Cloud Run URL based on a service name can be done as below :
main:
steps:
- initialize:
assign:
- project_number: ${sys.get_env("GOOGLE_CLOUD_PROJECT_NUMBER")}
- cloud_run_location: europe-west2
- cloud_run_service_name: my-service-name
- get_cloud_run_details:
call: googleapis.run.v1.namespaces.services.get
args:
name: ${"namespaces/" + project_number + "/services/" + cloud_run_service_name}
location: ${cloud_run_location}
result: service_obj
- assign_vars:
assign:
- service_url: ${service_obj.status.address.url}
Upvotes: 1
Reputation: 207912
Put together this returns the URL of a cloud run service
- 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}
the expected output is:
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
You have your value inside the result
key.
Upvotes: 4
Reputation: 45214
This could be easily done with gcloud
CLI, however that's currently not an action supported in Cloud Workflows steps. Currently your only option is to use the Get Service REST API endpoint.
Here is an example:
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
In the example above, note us-central1
is the region and replace PROJECT_ID
and SERVICE_NAME
with yours.
The response will have a JSON document, and its status.address.url
will contain the https://[...].run.app
URL of your Cloud Run service.
Pro-tip: To find out what REST API calls a gcloud
command does (for example gcloud run services describe
) add --log-http
option.
Upvotes: 1