最終更新日: 2026-08-27
TOP(About this memo)) > 一覧(Google Cloud) > Cloud Run
allUsersが設定されている。/var/logディレクトリにあるすべてのファイル/dev/log)production_service.yamlのようにコード管理しておくとよい(当然だが、YAMLには環境変数の値は入るものの、シークレットはキー情報のみが入る)。gcloud run deploy [SERVICE] --image [IMAGE_URL]gcloud run deployは--imageをつけない場合はソースコードからデプロイしてくれるが、ビルドを完全にカスタマイズすることはできない。デモンストレーション以外では使う機会は少なそう(IMO)。
gcr.io/distroless/static-debian12は2MiB程度。:debugタグをつけることでシェル等を使うことができる。
:debug-nonroot。:nonrootによってnonrootのイメージを使うことができる。
:nonrootを使わなくても、DockerfileのUSER nonrootによって同様のことができる。CGO_ENABLED=0にすればNativeモジュールに依存しないので問題ない。level=info msg="token verify failed. ID token has invalid 'aud' (audience) claim; expected \"[EXPECTED_PROJECT_ID]\" but got \"[ACTUAL_PROJECT_ID]\"; make sure the ID token comes from the same Firebase project as the credential used to authenticate this SDK; see https://firebase.google.com/docs/auth/admin/verify-id-tokens for details on how to retrieve a valid ID token"
PORTで指定されたポートをリッスンさせる必要がある。
/cloudsql/INSTANCE_CONNECTION_NAMEX-Forwarded-ForヘッダーにクライアントのIPアドレスをセットする。roles/run.invokerの権限が必要)。https://[TAG---][サービス名]-[プロジェクト番号].[リージョン].run.app
https://[TAG---][サービス名]-[ランダムなハッシュ].a.run.app
gcloud run services update-traffic [SERVICE] --to-latest
# または
gcloud run services update-traffic [SERVICE] --to-revisions LATEST=100
gcloud run services update-traffic [SERVICE] --to-revisions [REVISION]=100
100の部分を50にすると、既存の割当てが50%、新規の割当てが50%といった配分になる。gcloud run services update-traffic [SERVICE] --to-tags [TAG]=100
gcloud run services update-traffic [SERVICE] --to-revisions rev-00005-red=25,rev-00001-bod=25,rev-00002-nan=50
gcloud run deploy [SERVICE] --image [IMAGE_URL] --no-traffic --tag [TAG]
https://[TAG]---[サービス名]-[プロジェクト番号].[リージョン].run.app--no-trafficは、今回のリビジョンにトラフィックが割り当てられることを避けるために使うもの。
gcloud run services update-traffic [SERVICE] --remove-tags [TAG]
gcloud run services list
gcloud run services describe [SERVICE]
gcloud run revisions list --service [SERVICE]
gcloud run revisions describe [REVISION]
gcloud run revisions delete [REVISION]
gcloud run services delete [SERVICE]
gcloud run services describe [SERVICE] --format export > service.yaml
gcloud run services replace service.yaml
サービスを最初にデプロイしたときに提供される、安定した自動割り当て URL を Cloud Run の一般公開 URL として使用できます。