Cloud Build のワザ その1
Cloud Build のワザ その1
English follows Japanese.
結論
google-cloud-cli や cloud-sdk の代わりに gcr.io/cloud-builders/gcloud を使うだけで1分のビルド時間が短縮できる。
その他、「Cloud Build 提供のサポートされているビルダー イメージ」を知ると時短できる。
はじめに
みなさん、Cloud Build を使っていますか?
Cloud Build は、Google Cloud の CI/CD サービスです。いろいろな使い方ができますが、ソースコードをビルドして、コンテナイメージを作成し、デプロイするための強力なツールです。
Cloud Build の「運用」において、よく話題に上がるのが「時間」です。Cloud Build のビルド時間を短縮すると、
- 開発者の待ち時間が減る
- ビルドコストが下がる
というメリットがあります。
今回は、ビルドの「中身は変えず」に、ビルド時間だけを短縮する方法を紹介します。
詳細
ビルドプロセス内では、いろいろなツールを使うことがあると思います。中でも、Google Cloud のリソースを操作するために gcloud コマンドを使うことは多いでしょう。
実は、gcloud コマンドを提供する Google Cloud のイメージは複数あります(以下に数例示しますが、もっとあるでしょう)。
gcr.io/cloud-builders/gcloudgcr.io/google.com/cloudsdktool/google-cloud-cligcr.io/google.com/cloudsdktool/cloud-sdk
最初のイメージは、Cloud Build 提供のサポートされているビルダー イメージで紹介されています。
実は、私がテストした限りでは、gcr.io/cloud-builders/gcloud のイメージは、「ビルド開始時点で、ビルドを実行する仮想マシンへのダウンロードが完了している(イメージが存在している)」ため、イメージの転送を待たずに、すぐにコマンドが実行されます。
もし、gcr.io/google.com/cloudsdktool/google-cloud-cli のように「ダウンロードが必要なイメージ」を使うと、ビルド開始時点でイメージのダウンロードが始まります。このイメージは 1.2 GB 程度で、ダウンロードには大体1分程度かかります。
逆に言うと、gcloud コマンドが使いたいだけであれば、イメージを切り替えるだけで、ビルド時間が短縮されます。
docker や git コマンドについても同様です。gcr.io/cloud-builders/docker, gcr.io/cloud-builders/git も、追加のダウンロード時間を発生させずにすぐに使えるイメージです。
まとめ
Cloud Build のビルド時間を短縮するためには、gcr.io/cloud-builders/gcloud を使うだけで1分のビルド時間が短縮できる可能性があります。docker や git を何かのイメージにインストールして使っている場合も同様に、Cloud Build 提供の docker や git イメージでの利用を検討してみてください。それぞれ1分程度のビルド時間が短縮される可能性があります。
また、Cloud Build で使える「Cloud Build 提供のイメージ」は他にもあります。これらを知っておくと、ビルド時間の短縮に役立つでしょう。
参考
- Cloud Build 提供のサポートされているビルダー イメージhttps://cloud.google.com/build/docs/cloud-builders?hl=ja
- Google Cloud Build official builder images GitHub https://github.com/GoogleCloudPlatform/cloud-builders
- Google Cloud CLI Docker GitHub https://github.com/GoogleCloudPlatform/cloud-sdk-docker
Cloud Build Tips Part 1
Summary
You can reduce your build time by one minute just by using gcr.io/cloud-builders/gcloud.
Additionally, you can save time by learning about the other "Supported builder images provided by Cloud Build."
Introduction
Hello everyone, are you using Cloud Build?
Cloud Build is Google Cloud's CI/CD service. While it has many uses, it's a powerful tool for building source code, creating container images, and deploying them.
When it comes to "operating" Cloud Build, a common topic of discussion is "time." Shortening your Cloud Build time has two main benefits:
- Reduces waiting time for developers
- Lowers build costs
In this article, I'll introduce a way to shorten only the build time without changing the actual contents of your build.
Details
Within your build process, you probably use a variety of tools. Among them, the gcloud command is likely used frequently to interact with Google Cloud resources.
As it turns out, there are multiple Google Cloud images that provide the gcloud command (here are a few examples, but there are likely more).
gcr.io/cloud-builders/gcloudgcr.io/google.com/cloudsdktool/google-cloud-cligcr.io/google.com/cloudsdktool/cloud-sdk
The first image is featured in the "Supported builder images provided by Cloud Build" documentation.
Based on my testing, the gcr.io/cloud-builders/gcloud image is already downloaded to the virtual machine executing the build when the build starts (the image is already present). This allows commands to run immediately without waiting for the image to be pulled.
On the other hand, if you use an image that needs to be downloaded, such as gcr.io/google.com/cloudsdktool/google-cloud-cli, the image download will begin when the build starts. This image is about 1.2 GB, and the download takes approximately one minute.
In other words, if all you need is the gcloud command, you can shorten your build time just by switching the image.
The same principle applies to the docker and git commands. gcr.io/cloud-builders/docker and gcr.io/cloud-builders/git are also images that you can use immediately without incurring additional download time.
Conclusion
To shorten your Cloud Build time, you can potentially save one minute just by using gcr.io/cloud-builders/gcloud.
Similarly, if you are currently installing docker or git into another image to use them, consider using the docker and git images provided by Cloud Build. You could potentially save about a minute of build time for each.
There are other "Cloud Build-provided images" available as well. Familiarizing yourself with them can be very helpful for reducing your build times.
ディスカッション
コメント一覧
まだ、コメントがありません