⚠️
[CloudRun]Revision 'name' is not ready and cannot serve traffic.の解決方法
何が起こった?
Cloud Run functions(cloud function第2世代)で作成していた関数を一部修正したかったので、コンソールから修正してデプロイしたところ下記エラーが発生した。
Revision {Revision Name} is not ready and cannot serve traffic. The user-provided container failed to start and listen on the port defined provided by the PORT=8080 environment variable within the allocated timeout. This can happen when the container port is misconfigured or if the timeout is too short. The health check timeout can be extended. Logs for this revision might contain more information
原因
関数自体のログを詳しく調査したところ本当の原因はインポートエラーだった。
インポートエラーの内容
ImportError: cannot import name 'T' from 're' (/layers/google.python.runtime/python/lib/python3.13/re/__init__.py)
なんで?
Python 3.13では19のモジュールが削除されていて、今回削除されたモジュール(re)に依存しているライブラリを使っていたためエラーが発生していた。
Cloud Run functionsを作成時にPythonのランタイムを3.12で指定していたはずだったが、コンソールで編集してデプロイすると自動的に最新のバージョンのランタイム(今回だと3.13)が指定されてしまう?みたい。
解決方法
少なくとも今回はルートに.python-version
ファイルを作成して。もともと設定していたPython3.12を指定して再度デプロイしたら解決した。
Discussion