-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: action to rollback cloud run if health check fails #2
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,81 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
name: Deploy Cloud Run service | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
description: Create a new revision and rollback if health check fails | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
inputs: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
region: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
description: Region of the Cloud Run service | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
required: true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
image: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
description: Image name | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
required: true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
service: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
description: Name of the Cloud Run service | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
required: true | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
health_check_url: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
description: Health check URL. Multiple URLs can be separated by line breaks. If not provided, health check will be skipped. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
runs: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
using: composite | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
steps: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- name: Get current revision | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
id: get_revision | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
shell: bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
run: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
REV=$( \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
gcloud run services describe "${{ inputs.service }}" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
--region "${{ inputs.region }}" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
--format="value(status.latestReadyRevisionName)" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "Current revision: $REV" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "revision=$REV" >> "$GITHUB_OUTPUT" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- name: Deploy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OTOH and could be out of scope but to be on the safer approach, we might as well utilize revision tags to do test on service healthcheck path before it's serving live traffic. Somewhat like blue/green deployment. Hence potentially reducing chance of having to do rollback https://cloud.google.com/run/docs/rollouts-rollbacks-traffic-migration#tags |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
shell: bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
run: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
gcloud run deploy "${{ inputs.service }}" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
--image "${{ inputs.image }}" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
--region "${{ inputs.region }}" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
--platform managed \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
--quiet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+31
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could utilize this GH actions
Comment on lines
+31
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we want to utilize the
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @rot1024 updated the suggestion to supply the Host Header |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# ensure that the traffic is updated to the latest revision always | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- name: Update traffic | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
shell: bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
run: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
gcloud run services update-traffic "${{ inputs.service }}" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
--to-latest \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
--region "${{ inputs.region }}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Comment on lines
+40
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we are using aforementioned GH actions, we could make sure that Cloud Run will route traffic to the latest revision via GH actions inputs.
Comment on lines
+40
to
+46
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can later direct all traffic to
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
# if the URL is invalid, curl itself will return an error code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- name: Health check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
id: health_check | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if: ${{ inputs.health_check_url }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could utilize aforementioned GH actions output to get URL. But the problem is to hit |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
shell: bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
run: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
for url in ${{ inputs.health_check_url }}; do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "Checking health of $url" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
RESULT=`curl -m 10 -s -o /dev/null -w "%{http_code}" "$url"` | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "Status code is $RESULT" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if [ $RESULT -ge 300 ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "Health check failed" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "error=true" >> "$GITHUB_OUTPUT" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
break | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- name: Rollback | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if: ${{ steps.health_check.outputs.error && steps.get_revision.outputs.revision }} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
shell: bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
run: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
gcloud run services update-traffic "${{ inputs.service }}" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
--to-revision="${{ steps.get_revision.outputs.revision }}" \ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
--region "${{ inputs.region }}" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- name: Finish | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
shell: bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
run: | | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
if [ -z "${{ steps.health_check.outputs.error }}" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "Deployment successful" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
echo "Deployment failed" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
fi |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the services are publicly accessible anyway and we don't implement special host-based routing within the service itself, We might use path instead and leverage cloud-run URL for testing instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using Cloud Run URLs may cause the application to not work properly. Even if you use this, the addition of the Host header to curl is still required. In other words, the need to specify a URL unfortunately cannot be eliminated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted on this. If this is the hard constraint from the service side then my suggestion is not relevant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: this might be useful if we want to explicitly shows the path or list of paths for healthcheck