Open4

シンプルなRustアプリをBuildPacksでCloud Runでもローカルでも試したい

harrythecodeharrythecode

背景

タイトルの通り、シンプルなRustアプリをCloud Runでもローカルでも試してました。
テストで動かしてたのは以下のシンプルなRust Web App

https://github.com/katopz/hello-rust-actix-cloudrun

きちんとローカルでもCloud Buildでもビルド、デプロイまで出来たのですが1つ大きな問題が。

大きな問題「ビルド時間が毎回10分かかる件」

Google Cloud Buildはキャッシュを溜め込まないので毎回新しくイメージを取ってきてBuildをします。特にchef系のcompileにものすごく大きな時間がかかっており、デフォルトの設定では毎回10分の時間が掛かっていたので何とかしようと模索中

harrythecodeharrythecode

試したこと1「Google公式の言う通り」

結論、全然ダメでした。Kaniko使えと言うけど、Github見たら予告なくメンテ終了してるし。Dockerfileを最適化してもダメだし。cloudbuild.yamlを最適化してもダメだし。全然ダメ。

https://cloud.google.com/build/docs/optimize-builds/speeding-up-builds?hl=ja

試したこと2「BuildPacks」

大本命。以下を参考にしてます。

generic::invalid_argument: generic::invalid_argument: if 'build.service_account' is specified, the build must either (a) specify 'build.logs_bucket' (b) use the CLOUD_LOGGING_ONLY logging option, or (c) use the NONE logging option というエラーが発生。
「トリガーを実行するService Accountは(a)か(b)か(c)のログ権限のいずれかだけ持ってりゃいい」ということのようで、平たく言えば「余分な権限もちすぎ」だと怒られているようだ。

harrythecodeharrythecode

トラブルシューティング

untrusted builderエラー

  • 原因: Cargo.lockがない状態だと以下のようにエラー
  • 解決: Cargo.lockを適切に生成
[detector] ERROR: No buildpack groups passed detection.
[detector] ERROR: Please check that you are running against the correct path.
[detector] ERROR: failed to detect: no buildpacks participating
ERROR: failed to build: executing lifecycle. This may be the result of using an untrusted builder: failed with status code: 20
Finished Step #0 - "Build"
ERROR
ERROR: build step 0 "gcr.io/k8s-skaffold/pack" failed: step exited with non-zero status: 1