Skip to content

Cloud Runサービスを削除して接続を切断するように変更#9359

Merged
komagata merged 1 commit intomainfrom
fix/stop-cloudrun-delete-service
Dec 11, 2025
Merged

Cloud Runサービスを削除して接続を切断するように変更#9359
komagata merged 1 commit intomainfrom
fix/stop-cloudrun-delete-service

Conversation

@komagata
Copy link
Copy Markdown
Member

@komagata komagata commented Dec 11, 2025

Summary

  • --max-instances=0gcloud run services deleteに変更
  • サービスを削除することで、DB接続を確実に切断

問題

--max-instances=0は無効な値で、Cloud Runのautoscaling.knative.dev/maxScaleアノテーションは正の整数が必要だった。

解決策

gcloud run services deleteでサービスを完全に削除し、Deployステップで再作成されるようにした。
これにより、DB接続が確実に切断される。

Test plan

  • ステージング環境へのデプロイが成功することを確認

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Cloud Run サービスの動作を停止から完全削除に変更。データベース接続の確実な切断を実現。ユーザーメッセージを更新し、デプロイメント後の待機時間を短縮。

✏️ Tip: You can customize this high-level summary in your review settings.

--max-instances=0は無効な値(正の整数が必要)のためエラーになっていた。
代わりにgcloud run services deleteでサービスを削除し、
Deployステップで再作成されるようにした。

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Dec 11, 2025

Walkthrough

Cloud BuildのステージングパイプラインでCloud Runサービスの処理を「停止」から「削除」に変更します。メッセージと待機時間を更新し、存在確認ロジックを調整してサービス削除の動作に合わせます。

Changes

Cohort / File(s) Change Summary
Cloud Build Staging Configuration
.cloudbuild/cloudbuild-staging.yaml
Cloud Runサービスの処理を--max-instances=0による停止(30秒待機)からdeleteによる削除(10秒待機)に変更。ユーザーメッセージを「Stopping Cloud Run service」から「Deleting Cloud Run service」に、「service stopped」から「service deleted」に更新。サービスが存在しない場合のログメッセージを「skipping stop」から「skipping delete」に変更。

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3分

Possibly related PRs

Suggested labels

雑事

Suggested reviewers

  • okuramasafumi

Poem

🐰 設定を削除に変えれば、

データベースも切れ味よく。

三十から十へ短縮し、

ウサギのように軽くホップ。

ポン!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description check ⚠️ Warning プルリクエストの説明には、概要、問題点、解決策、テスト計画が記載されていますが、リポジトリのテンプレートで必須とされている「Issue番号」「変更確認方法」「Screenshot」のセクションが不足しています。 テンプレートの必須セクションを追加してください。Issue番号、具体的な変更確認方法(デプロイ手順や検証方法)、変更前後のスクリーンショットなどを記載してください。
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed プルリクエストのタイトルは、変更の主要な内容(Cloud Runサービスの削除)を明確に要約しており、ファイル一覧や曖昧な表現を含まない簡潔で具体的な表現です。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/stop-cloudrun-delete-service

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1c47aad and 0e1a6fe.

📒 Files selected for processing (1)
  • .cloudbuild/cloudbuild-staging.yaml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build_and_test
🔇 Additional comments (3)
.cloudbuild/cloudbuild-staging.yaml (3)

29-48: 削除ロジックは正しい実装ですが、10秒の待機時間の妥当性を検証してください。

サービス削除の条件分岐とエラーハンドリングは適切です。ただし、待機時間を30秒から10秒に短縮した場合、既存の全データベース接続が確実にクローズされるかを確認する必要があります。特に以下の点を検証してください:

  • アクティブなデータベース接続が10秒以内にすべて切断されるか
  • Cloud SQLプロキシ起動待機ステップ(WaitForProxy)で接続リトライがあるため、短い待機時間でも問題ないか
  • ステージング環境の負荷で実際に動作確認したか

本番環境への適用前に、ステージング環境での複数回のデプロイで挙動を確認されることをお勧めします。


36-36: メッセージテキストと日本語コメントは明確です。

ユーザーフェーシングのメッセージと内部コメントが一貫性を持ち、意図が明確に伝わります。サービス削除の目的(DB接続の切断)がコメント(26-28行目)と実装に良く反映されています。

Also applies to: 44-44, 47-47


176-238: Deploy ステップとの連携は適切です。

gcloud run deploy コマンドは既存サービスの更新と新規作成の両方に対応しており、StopCloudRun で削除されたサービスは Deploy ステップで適切に再作成されます。パイプラインの依存関係(DBMigrate → Deploy)も正しく設定されています。


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@komagata komagata merged commit a08f87e into main Dec 11, 2025
3 of 4 checks passed
@komagata komagata deleted the fix/stop-cloudrun-delete-service branch December 11, 2025 17:52
@github-actions github-actions bot mentioned this pull request Dec 11, 2025
28 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant