{"id":590,"date":"2025-06-22T21:04:03","date_gmt":"2025-06-22T12:04:03","guid":{"rendered":"https:\/\/tako.nakano.net\/blog\/?p=590"},"modified":"2025-06-23T11:21:11","modified_gmt":"2025-06-23T02:21:11","slug":"cloud-build-tips-part-2","status":"publish","type":"post","link":"https:\/\/tako.nakano.net\/blog\/2025\/06\/cloud-build-tips-part-2\/","title":{"rendered":"Cloud Build \u306e\u30ef\u30b6 \u305d\u306e2"},"content":{"rendered":"<h1>Cloud Build \u306e\u30ef\u30b6 \u305d\u306e2<\/h1>\n<p>English follows Japanese.<\/p>\n<h2>\u7d50\u8ad6<\/h2>\n<p>\u30d3\u30eb\u30c9\u30d7\u30ed\u30bb\u30b9\u306e\u6700\u521d\u306b\u3001\u3068\u306b\u304b\u304f <code>pull<\/code> \u3060\u3051\u3092\u5b9f\u884c\u3057\u3066\u304a\u304f\u3088\u3046\u306b\u3057\u3066\u304a\u304f\u3068\u3001\u30d3\u30eb\u30c9\u6642\u9593\u304c\u77ed\u7e2e\u3067\u304d\u308b\u3002<br \/>\n\u30d3\u30eb\u30c9\u30b9\u30c6\u30c3\u30d7\u306b\u73fe\u308c\u308b\u30a4\u30e1\u30fc\u30b8\u306e\u6570\u304c\u591a\u3044\u307b\u3069\u3001\u52b9\u679c\u304c\u5927\u304d\u3044\u3002<br \/>\n<code>Dockerfile<\/code> \u3067\u5229\u7528\u3059\u308b\u30a4\u30e1\u30fc\u30b8\u306b\u3082\u52b9\u679c\u304c\u3042\u308b\u3002<\/p>\n<h2>\u306f\u3058\u3081\u306b<\/h2>\n<p>\u307f\u306a\u3055\u3093\u3001Cloud Build \u3092\u4f7f\u3063\u3066\u3044\u307e\u3059\u304b\uff1f<br \/>\nCloud Build \u306f\u3001Google Cloud \u306e CI\/CD \u30b5\u30fc\u30d3\u30b9\u3067\u3059\u3002\u3044\u308d\u3044\u308d\u306a\u4f7f\u3044\u65b9\u304c\u3067\u304d\u307e\u3059\u304c\u3001\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9\u3092\u30d3\u30eb\u30c9\u3057\u3066\u3001\u30b3\u30f3\u30c6\u30ca\u30a4\u30e1\u30fc\u30b8\u3092\u4f5c\u6210\u3057\u3001\u30c7\u30d7\u30ed\u30a4\u3059\u308b\u305f\u3081\u306e\u5f37\u529b\u306a\u30c4\u30fc\u30eb\u3067\u3059\u3002<\/p>\n<p>\u3053\u306e\u8a18\u4e8b\u306f\u3001Cloud Build \u306e\u30ef\u30b6\u306e2\u56de\u76ee\u3067\u3059\u3002<br \/>\n\u524d\u56de\u306f\u3001<code>google-cloud-cli<\/code> \u3084 <code>cloud-sdk<\/code> \u306e\u4ee3\u308f\u308a\u306b <code>gcr.io\/cloud-builders\/gcloud<\/code> \u3092\u4f7f\u3046\u3060\u3051\u30671\u5206\u306e\u30d3\u30eb\u30c9\u6642\u9593\u304c\u77ed\u7e2e\u3067\u304d\u308b\u3053\u3068\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002<\/p>\n<p>\u4eca\u56de\u3082\u3001\u30d3\u30eb\u30c9\u306e\u300c\u4e2d\u8eab\u306f\u5909\u3048\u305a\u300d\u306b\u3001\u30d3\u30eb\u30c9\u6642\u9593\u3060\u3051\u3092\u77ed\u7e2e\u3059\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<h2>\u8a73\u7d30<\/h2>\n<p>\u30d3\u30eb\u30c9\u30d7\u30ed\u30bb\u30b9\u5185\u3067\u306f\u3001\u30b9\u30c6\u30c3\u30d7\u6bce\u306b\u7570\u306a\u308b Docker \u30a4\u30e1\u30fc\u30b8\u3092\u4f7f\u3046\u3053\u3068\u304c\u591a\u3044\u3067\u3057\u3087\u3046\u3002\u307e\u305f\u3001\u30d3\u30eb\u30c9\u30b9\u30c6\u30c3\u30d7\u306b\u306f\u300c\u9806\u5e8f\u300d\u304c\u3042\u308b\u3053\u3068\u304c\u591a\u3044\u3067\u3059\u3002\u7279\u5b9a\u306e\u30b9\u30c6\u30c3\u30d7\u306e\u7d50\u679c\u306b\u4f9d\u5b58\u3057\u3066\u3001\u6b21\u306e\u30b9\u30c6\u30c3\u30d7\u304c\u5b9f\u884c\u3055\u308c\u308b\u3053\u3068\u304c\u591a\u3044\u304b\u3089\u3067\u3059\u3002<\/p>\n<p><code>https:\/\/console.cloud.google.com\/cloud-build\/builds;region=global\/604d39a5-8ec1-4017-8b5e-xxxxxxxxxxxxx<\/code> \u306e\u3088\u3046\u306a\u5f62\u5f0f\u306e Cloud Build \u306e\u30d3\u30eb\u30c9\u306e\u8a73\u7d30\u753b\u9762\u3092\u898b\u3066\u307f\u308b\u3068\u3001\u30d3\u30eb\u30c9\u30b9\u30c6\u30c3\u30d7\u3067\u4f55\u304c\u5b9f\u884c\u3055\u308c\u3066\u3044\u308b\u304b\u304c\u5206\u304b\u308a\u307e\u3059\u3002<\/p>\n<p>\u30b9\u30c6\u30c3\u30d7\u5185\u3067<\/p>\n<pre><code>Pulling image: wordpress:php8.2-apache\nphp8.2-apache: Pulling from library\/wordpress\n61320b01ae5e: Already exists\nb4ce612dc732: Already exists\n093338982d92: Pulling fs layer\n0c2a0ba9eb0c: Pulling fs layer\n442abaed7751: Pulling fs layer\naa4e51934eef: Pulling fs layer\n924949db942b: Pulling fs layer\n153d2fb08c64: Pulling fs layer\n26f17ce45149: Pulling fs layer\n64a857ca8a6a: Pulling fs layer<\/code><\/pre>\n<p>\u306e\u3088\u3046\u306a\u51fa\u529b\u304c\u3042\u308b\u3053\u3068\u304c\u3042\u308a\u307e\u3059\u3002\u3053\u308c\u306f\u3001Docker \u30a4\u30e1\u30fc\u30b8\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u304c\u305d\u306e\u30b9\u30c6\u30c3\u30d7\u5185\u3067\u884c\u308f\u308c\u3066\u3044\u308b\u3053\u3068\u3092\u793a\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u3053\u306e\u300c\u30a4\u30e1\u30fc\u30b8\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u300d\u304c\u3001\u5f8c\u308d\u306e\u65b9\u306e\u30b9\u30c6\u30c3\u30d7\u3067\u884c\u308f\u308c\u3066\u3044\u306a\u3044\u3067\u3057\u3087\u3046\u304b\u3002\u3053\u3053\u306b\u3001\u5b9f\u306f\u3001\u7121\u99c4\u304c\u3042\u308b\u306e\u3067\u3059\u3002\u30b9\u30c6\u30c3\u30d7\u306e\u300c\u5185\u5bb9\u300d\u81ea\u4f53\u306f\u524d\u306e\u30b9\u30c6\u30c3\u30d7\u306e\u7d50\u679c\u306b\u4f9d\u5b58\u3057\u3066\u3044\u308b\u305f\u3081\u3001\u9806\u756a\u306b\u5b9f\u884c\u3055\u308c\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002\u4e00\u65b9\u3067\u3001\u30a4\u30e1\u30fc\u30b8\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u306f\u300c\u5148\u306b\u300d\u884c\u3046\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>Cloud Build \u306e\u30d3\u30eb\u30c9\u30d7\u30ed\u30bb\u30b9\u306f\u3001\u524d\u5f8c\u95a2\u4fc2\u304c\u5b9a\u7fa9\uff08\u6307\u5b9a\uff09\u3055\u308c\u3066\u3044\u306a\u3044\u30b9\u30c6\u30c3\u30d7\u540c\u58eb\u3092\u300c\u4e26\u884c\u3057\u3066\u5b9f\u884c\u300d\u3057\u3066\u304f\u308c\u308b\u6a5f\u80fd\u304c\u3042\u308a\u307e\u3059\u3002<a href=\"https:\/\/cloud.google.com\/build\/docs\/configuring-builds\/configure-build-step-order?hl=ja\">\u30d3\u30eb\u30c9\u30b9\u30c6\u30c3\u30d7\u306e\u9806\u5e8f\u306e\u69cb\u6210<\/a>\u306b\u8a73\u3057\u304f\u8aac\u660e\u3055\u308c\u3066\u3044\u307e\u3059\u3002<\/p>\n<p>\u5404\u30d3\u30eb\u30c9\u30b9\u30c6\u30c3\u30d7\u306f <code>id<\/code> \u3092\u6301\u3064\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u307e\u305f\u3001<code>waitFor<\/code> \u3068\u3044\u3046\u30d7\u30ed\u30d1\u30c6\u30a3\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u7279\u5b9a\u306e <code>id<\/code> \u306e\u30b9\u30c6\u30c3\u30d7\u304c\u5b8c\u4e86\u3059\u308b\u307e\u3067\u5f85\u3064\u3088\u3046\u306b\u6307\u5b9a\u3067\u304d\u307e\u3059\u3002<br \/>\n<code>waitFor<\/code> \u3092\u6307\u5b9a\u3055\u308c\u306a\u3044\u5834\u5408\u3001\u30d3\u30eb\u30c9\u30b9\u30c6\u30c3\u30d7\u306f\u3001\u30d3\u30eb\u30c9 \u30ea\u30af\u30a8\u30b9\u30c8\u5185\u306e <strong>\u5148\u884c\u3059\u308b\u3059\u3079\u3066\u306e\u30d3\u30eb\u30c9\u30b9\u30c6\u30c3\u30d7\u304c\u6b63\u5e38\u306b\u5b8c\u4e86<\/strong> \u3059\u308b\u307e\u3067\u5f85\u6a5f\u3057\u305f\u5f8c\u306b\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002\u4f8b\u3048\u3070\u3001\u6b21\u306e\u3088\u3046\u306a\u30d3\u30eb\u30c9\u69cb\u6210\u30d5\u30a1\u30a4\u30eb\u304c\u3042\u308b\u5834\u5408\u3001\u30b9\u30c6\u30c3\u30d7 A, B, C \u306f\u9806\u756a\u306b\u5b9f\u884c\u3055\u308c\u307e\u3059\u3002<\/p>\n<pre><code class=\"language-yaml\">steps:\n- name: foo\n  id: A\n- name: bar\n  id: B\n- name: baz\n  id: C<\/code><\/pre>\n<p>\u3053\u3053\u3067\u3001\u30b9\u30c6\u30c3\u30d7 B, C \u3067\u4f7f\u7528\u3059\u308b Docker \u30a4\u30e1\u30fc\u30b8\u3092\u3001\u30b9\u30c6\u30c3\u30d7 A \u3068\u4e26\u884c\u3057\u3066\u3001\u5148\u306b\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u304a\u304f\u3088\u3046\u306b\u3059\u308b\u3068\u3001\u30b9\u30c6\u30c3\u30d7 B, C \u306e\u5b9f\u884c\u6642\u9593\u304c\u3001\u305d\u308c\u305e\u308c\u306e\u30b9\u30c6\u30c3\u30d7\u3067\u5229\u7528\u3059\u308b\u30a4\u30e1\u30fc\u30b8\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u6642\u9593\u5206\u77ed\u7e2e\u3055\u308c\u308b\u306f\u305a\u3067\u3059\u3002<\/p>\n<pre><code class=\"language-yaml\">steps:\n- name: foo\n  id: A\n  waitFor: [&#039;-&#039;] # Download images \u3068\u4e26\u884c\u3057\u3066\u5b9f\u884c\u3055\u308c\u308b\u3001\u66f8\u304b\u306a\u304f\u3066\u3082\u826f\u3044\n- name: bar\n  id: B\n- name: baz\n  id: C\n- name: &#039;gcr.io\/cloud-builders\/docker&#039;\n  id: &#039;Download images&#039;\n  entrypoint: &#039;bash&#039;\n  args:\n    - &#039;-c&#039;\n    - |\n      # foo \u306f\u30b9\u30c6\u30c3\u30d7 A \u3067\u4f7f\u3046\u30a4\u30e1\u30fc\u30b8\u306a\u306e\u3067\u3001\u66f8\u304b\u306a\u304f\u3066\u3082\u826f\u3044\n      docker pull foo\n      docker pull bar\n      docker pull baz\n  waitFor: [&#039;-&#039;] # A \u3068\u4e26\u884c\u3057\u3066\u5b9f\u884c\u3055\u308c\u308b<\/code><\/pre>\n<p>\u3082\u3057\u3001<code>&#039;Download images&#039;<\/code> \u306e\u30b9\u30c6\u30c3\u30d7\u3092\u5148\u306b\u66f8\u304d\u305f\u3044\u5834\u5408\u306f\u3001\u30b9\u30c6\u30c3\u30d7 B, C \u7b49\u306b <code>waitFor<\/code> \u3092\u6307\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u30d3\u30eb\u30c9\u30b9\u30c6\u30c3\u30d7\u306e\u30ed\u30b0\u3067\u3001\u4f8b\u3048\u3070\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u8868\u793a\u3055\u308c\u308b\u5834\u5408\u306f\u3001\u300c\u30a4\u30e1\u30fc\u30b8\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u304c\u6e08\u3093\u3067\u3044\u308b\u300d\u3053\u3068\u3092\u793a\u3057\u3066\u3044\u307e\u3059\u3002\u6642\u77ed\u306b\u6210\u529f\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre><code>Already have image (with digest): wordpress:php8.2-apache<\/code><\/pre>\n<p><code>&#039;Download images&#039;<\/code> \u306e\u30b9\u30c6\u30c3\u30d7\u3092\u5148\u306b\u66f8\u3044\u3066\u304a\u304f\u3068\u3001\u5229\u7528\u3059\u308b\u30a4\u30e1\u30fc\u30b8\u306e\u6570\u306b\u3088\u3063\u3066\u3001\u30d3\u30eb\u30c9\u6642\u9593\u304c\u5927\u5e45\u306b\u77ed\u7e2e\u3055\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308a\u307e\u3059\u300210\u30b9\u30c6\u30c3\u30d7\u3042\u308a\u3001\u54041\u5206\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u306b\u6642\u9593\u304c\u304b\u304b\u3063\u3066\u3044\u308b\u5834\u5408\u3001\u6700\u521d\u306e\u30b9\u30c6\u30c3\u30d7\u4ee5\u5916\u306e9\u5206\u306e\u30d3\u30eb\u30c9\u6642\u9593\u304c\u77ed\u7e2e\u3055\u308c\u308b\u53ef\u80fd\u6027\u304c\u3042\u308b\u2026\u3068\u3044\u3046\u3053\u3068\u3067\u3059\u3002<\/p>\n<p>\u30b9\u30c6\u30c3\u30d7\u304c\u591a\u3044\u5834\u5408\u3084\u3001\u8907\u96d1\u306a\u5834\u5408\u306f\u3001\u4ee5\u4e0b\u306e\u3053\u3068\u3082\u691c\u8a0e\u3057\u3066\u307f\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n<ul>\n<li>\u30a4\u30e1\u30fc\u30b8\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3092\u884c\u3046\u30b9\u30c6\u30c3\u30d7\u305d\u306e\u3082\u306e\u3092\u8907\u6570\u306b\u5206\u3051\u308b<\/li>\n<li>\u5fc5\u8981\u306b\u5fdc\u3058\u3066\u30a4\u30e1\u30fc\u30b8\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3092\u884c\u3046\u30b9\u30c6\u30c3\u30d7\u540c\u58eb\u306b <code>waitFor<\/code> \u3092\u6307\u5b9a\u3059\u308b<\/li>\n<li>\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u304c\u4e26\u884c\u3057\u3066\u884c\u308f\u308c\u308b\u3088\u3046\u306b\u3001\u30b9\u30af\u30ea\u30d7\u30c8\u3092\u5de5\u592b\u3059\u308b<\/li>\n<\/ul>\n<p>\u3053\u306e\u624b\u6cd5\u306f\u3001<code>name<\/code> \u306b\u6307\u5b9a\u3059\u308b\u30a4\u30e1\u30fc\u30b8\u3060\u3051\u3067\u306f\u306a\u304f\u3001<code>Dockerfile<\/code> \u306e <code>FROM<\/code> \u306b\u6307\u5b9a\u3059\u308b\u30a4\u30e1\u30fc\u30b8\u3082\u5bfe\u8c61\u306b\u306a\u308a\u307e\u3059\u3002\u30d3\u30eb\u30c9\u30b9\u30c6\u30c3\u30d7\u3067\u4f7f\u7528\u3059\u308b\u3059\u3079\u3066\u306e\u30a4\u30e1\u30fc\u30b8\u3092\u6700\u521d\u306b\u30d7\u30eb\u3057\u3066\u304a\u304f\u3053\u3068\u3067\u3001\u5f8c\u7d9a\u306e\u30b9\u30c6\u30c3\u30d7\u3067\u306e\u30a4\u30e1\u30fc\u30b8\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u6642\u9593\u3092\u7bc0\u7d04\u3067\u304d\u307e\u3059\u3002<\/p>\n<p>\u88dc\u8db3:<br \/>\n<code>gcr.io\/cloud-builders\/docker<\/code> \u306f<a href=\"https:\/\/cloud.google.com\/build\/docs\/cloud-builders?hl=ja\">Cloud Build \u63d0\u4f9b\u306e\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u308b\u30d3\u30eb\u30c0\u30fc \u30a4\u30e1\u30fc\u30b8<\/a>\u306e1\u3064\u3067\u3001\u3053\u306e\u30a4\u30e1\u30fc\u30b8\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u306b\u306f\u6642\u9593\u304c\u304b\u304b\u308a\u307e\u305b\u3093\u3002<\/p>\n<h2>\u307e\u3068\u3081<\/h2>\n<p>\u3053\u306e\u8a18\u4e8b\u3067\u306f\u3001Cloud Build \u3067\u30d3\u30eb\u30c9\u6642\u9593\u3092\u77ed\u7e2e\u3059\u308b\u30c6\u30af\u30cb\u30c3\u30af\u3092\u7d39\u4ecb\u3057\u307e\u3057\u305f\u3002\u30d3\u30eb\u30c9\u30d7\u30ed\u30bb\u30b9\u306e\u6700\u521d\u306b\u3001\u5f8c\u7d9a\u306e\u30b9\u30c6\u30c3\u30d7\u3067\u4f7f\u7528\u3059\u308b Docker \u30a4\u30e1\u30fc\u30b8\u3092\u5148\u306b\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u3057\u3066\u304a\u304f\u3053\u3068\u3067\u3001\u5404\u30b9\u30c6\u30c3\u30d7\u3067\u306e\u30a4\u30e1\u30fc\u30b8\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u6642\u9593\u3092\u7bc0\u7d04\u3067\u304d\u307e\u3059\u3002\u7279\u306b\u4ee5\u4e0b\u306e\u30dd\u30a4\u30f3\u30c8\u304c\u91cd\u8981\u3067\u3059:<\/p>\n<ul>\n<li><code>waitFor: [&#039;-&#039;]<\/code> \u3092\u4f7f\u3063\u3066\u3001\u30a4\u30e1\u30fc\u30b8\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u30b9\u30c6\u30c3\u30d7\u3092\u4ed6\u306e\u30b9\u30c6\u30c3\u30d7\u3068\u4e26\u884c\u3057\u3066\u5b9f\u884c\u3059\u308b<\/li>\n<li>\u30d3\u30eb\u30c9\u30b9\u30c6\u30c3\u30d7\u3067\u4f7f\u7528\u3059\u308b\u3059\u3079\u3066\u306e\u30a4\u30e1\u30fc\u30b8\u3092\u6700\u521d\u306b\u30d7\u30eb\u3057\u3066\u304a\u304f<\/li>\n<li>\u30a4\u30e1\u30fc\u30b8\u306e\u6570\u304c\u591a\u3044\u307b\u3069\u3001\u6642\u9593\u77ed\u7e2e\u306e\u52b9\u679c\u304c\u5927\u304d\u304f\u306a\u308b<\/li>\n<li>\u8907\u96d1\u306a\u30d3\u30eb\u30c9\u306e\u5834\u5408\u306f\u3001\u30a4\u30e1\u30fc\u30b8\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u30b9\u30c6\u30c3\u30d7\u3092\u8907\u6570\u306b\u5206\u3051\u308b\u306a\u3069\u306e\u5de5\u592b\u3082\u52b9\u679c\u7684<\/li>\n<li><code>Dockerfile<\/code> \u3067\u5229\u7528\u3059\u308b\u30a4\u30e1\u30fc\u30b8\u306b\u3082\u52b9\u679c\u304c\u3042\u308b<\/li>\n<\/ul>\n<p>\u3053\u306e\u65b9\u6cd5\u3092\u4f7f\u3046\u3053\u3068\u3067\u3001\u30d3\u30eb\u30c9\u306e\u5185\u5bb9\u81ea\u4f53\u306f\u5909\u3048\u305a\u306b\u3001\u30d3\u30eb\u30c9\u6642\u9593\u3060\u3051\u3092\u77ed\u7e2e\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u307e\u3059\u3002\u591a\u6570\u306e\u30b9\u30c6\u30c3\u30d7\u3092\u6301\u3064\u30d3\u30eb\u30c9\u30d7\u30ed\u30bb\u30b9\u3067\u306f\u3001\u7279\u306b\u5927\u304d\u306a\u52b9\u679c\u3092\u671f\u5f85\u3067\u304d\u308b\u3067\u3057\u3087\u3046\u3002<\/p>\n<p>\u8a18\u4e8b\u57f7\u7b46\u5f8c\u3001\u691c\u7d22\u3057\u305f\u3068\u3053\u308d<a href=\"https:\/\/gotohayato.com\/content\/536\/\">Google Cloud Build \u306e\u9ad8\u901f\u5316 tips<\/a>\u3068\u3044\u3046\u8a18\u4e8b\u304c\u3042\u308a\u3001\u300cDocker \u30a4\u30e1\u30fc\u30b8\u306e\u30c0\u30a6\u30f3\u30ed\u30fc\u30c9\u51e6\u7406\u3092\u4e26\u5217\u5316\u3059\u308b\u300d\u3068\u3044\u3046\u5185\u5bb9\u304c\u66f8\u304b\u308c\u3066\u3044\u307e\u3057\u305f\u3002\u672c\u8a18\u4e8b\u306e\u8aac\u660e\u306e\u65b9\u304c\u82e5\u5e72\u8a73\u3057\u3044\u3067\u3059\u304c\u3001<code>&amp;<\/code> \u3067\u4e26\u5217\u5b9f\u884c\u3059\u308b\u624b\u6cd5\u3092\u7d39\u4ecb\u3057\u3066\u3044\u307e\u3057\u305f\u3002<\/p>\n<h2>\u53c2\u8003<\/h2>\n<ul>\n<li><a href=\"https:\/\/cloud.google.com\/build\/docs\/configuring-builds\/configure-build-step-order?hl=ja\">\u30d3\u30eb\u30c9\u30b9\u30c6\u30c3\u30d7\u306e\u9806\u5e8f\u306e\u69cb\u6210<\/a> <a href=\"https:\/\/cloud.google.com\/build\/docs\/configuring-builds\/configure-build-step-order?hl=ja\">https:\/\/cloud.google.com\/build\/docs\/configuring-builds\/configure-build-step-order?hl=ja<\/a><\/li>\n<li><a href=\"https:\/\/cloud.google.com\/build\/docs\/cloud-builders?hl=ja\">Cloud Build \u63d0\u4f9b\u306e\u30b5\u30dd\u30fc\u30c8\u3055\u308c\u3066\u3044\u308b\u30d3\u30eb\u30c0\u30fc \u30a4\u30e1\u30fc\u30b8<\/a> <a href=\"https:\/\/cloud.google.com\/build\/docs\/cloud-builders?hl=ja\">https:\/\/cloud.google.com\/build\/docs\/cloud-builders?hl=ja<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/GoogleCloudPlatform\/cloud-builders\">Google Cloud Build official builder images<\/a> GitHub <a href=\"https:\/\/github.com\/GoogleCloudPlatform\/cloud-builders\">https:\/\/github.com\/GoogleCloudPlatform\/cloud-builders<\/a><\/li>\n<li><a href=\"https:\/\/gotohayato.com\/content\/536\/\">Google Cloud Build \u306e\u9ad8\u901f\u5316 tips<\/a><\/li>\n<\/ul>\n<hr \/>\n<h1>Cloud Build Tips Part 2<\/h1>\n<h2>Summary<\/h2>\n<p>You can reduce build time by simply running <code>pull<\/code> for all necessary images at the very beginning of your build process. The more images that appear in your build steps, the greater the time-saving effect.<br \/>\nImages specified in <code>Dockerfile<\/code> can also benefit from this technique.<\/p>\n<h2>Introduction<\/h2>\n<p>Hello everyone, are you using Cloud Build? Cloud Build is Google Cloud&#8217;s CI\/CD service. While it has many uses, it&#8217;s a powerful tool for building source code, creating container images, and deploying them.<\/p>\n<p>This is the second article in our series of Cloud Build tips. Last time, we showed how you can save a minute of build time just by using <code>gcr.io\/cloud-builders\/gcloud<\/code> instead of <code>google-cloud-cli<\/code> or <code>cloud-sdk<\/code>.<\/p>\n<p>This time again, we&#8217;ll introduce a method to reduce build time without changing the actual content of the build.<\/p>\n<h2>Details<\/h2>\n<p>Within a build process, you often use different Docker images for each step. Also, build steps usually have an &quot;order&quot; because the execution of one step often depends on the result of a previous one.<\/p>\n<p>If you look at the Cloud Build details screen, which has a URL format like <code>https:\/\/console.cloud.google.com\/cloud-build\/builds;region=global\/604d39a5-8ec1-4017-8b5e-xxxxxxxxxxxxx<\/code>, you can see what&#8217;s being executed in each build step.<\/p>\n<p>Within a step, you might see output like this:<\/p>\n<pre><code>Pulling image: wordpress:php8.2-apache\nphp8.2-apache: Pulling from library\/wordpress\n61320b01ae5e: Already exists\nb4ce612dc732: Already exists\n093338982d92: Pulling fs layer\n0c2a0ba9eb0c: Pulling fs layer\n442abaed7751: Pulling fs layer\naa4e51934eef: Pulling fs layer\n924949db942b: Pulling fs layer\n153d2fb08c64: Pulling fs layer\n26f17ce45149: Pulling fs layer\n64a857ca8a6a: Pulling fs layer<\/code><\/pre>\n<p>This indicates that the Docker image is being downloaded within that step.<\/p>\n<p>Is this &quot;image download&quot; happening in one of the later steps? This is where there&#8217;s an inefficiency. While the &quot;content&quot; of the steps must be executed in order because they depend on the results of previous steps, the image downloads can be done &quot;earlier.&quot;<\/p>\n<p>Cloud Build has a feature that allows it to &quot;run in parallel&quot; any steps that do not have a defined dependency order. This is explained in detail in <a href=\"https:\/\/cloud.google.com\/build\/docs\/configuring-builds\/configure-build-step-order\">Configuring the order of build steps<\/a>.<\/p>\n<p>Each build step can have an <code>id<\/code>. You can also use the <code>waitFor<\/code> property to specify that a step should wait until a step with a specific <code>id<\/code> is completed. If <code>waitFor<\/code> is not specified, a build step will wait for <strong>all prior build steps<\/strong> in the build request to complete successfully before running. For example, in the following build configuration file, steps A, B, and C will run sequentially.<\/p>\n<pre><code class=\"language-yaml\">steps:\n- name: foo\n  id: A\n- name: bar\n  id: B\n- name: baz\n  id: C<\/code><\/pre>\n<p>Now, if you pre-download the Docker images used in steps B and C in parallel with step A, the execution time of steps B and C should be reduced by the time it would have taken to download their respective images.<\/p>\n<pre><code class=\"language-yaml\">steps:\n- name: foo\n  id: A\n  waitFor: [&#039;-&#039;] # Runs in parallel with &#039;Download images&#039;, can be omitted\n- name: bar\n  id: B\n- name: baz\n  id: C\n- name: &#039;gcr.io\/cloud-builders\/docker&#039;\n  id: &#039;Download images&#039;\n  entrypoint: &#039;bash&#039;\n  args:\n    - &#039;-c&#039;\n    - |\n      # Pulling &#039;foo&#039; here is optional, as step A will pull it anyway.\n      docker pull foo\n      docker pull bar\n      docker pull baz\n  waitFor: [&#039;-&#039;] # Runs in parallel with A<\/code><\/pre>\n<p>If you want to place the &#8216;Download images&#8217; step earlier in the file, you&#8217;ll need to specify <code>waitFor<\/code> for steps B, C, etc.<\/p>\n<p>If you see the following in your build step log, it indicates that the image has already been downloaded. You&#8217;ve successfully saved time.<\/p>\n<pre><code>Already have image (with digest): wordpress:php8.2-apache<\/code><\/pre>\n<p>By adding a <code>&#039;Download images&#039;<\/code> step at the beginning, you can potentially reduce your build time significantly, depending on the number of images used. For example, if you have 10 steps and each takes 1 minute to download its image, you could potentially save 9 minutes of build time (for all steps after the first).<\/p>\n<p>For builds with many or complex steps, consider the following:<\/p>\n<ul>\n<li>Splitting the image download step into multiple steps.<\/li>\n<li>Using <code>waitFor<\/code> between the image download steps themselves as needed.<\/li>\n<li>Crafting your script to ensure downloads happen in parallel.<\/li>\n<\/ul>\n<p>This technique applies not only to the images specified in the <code>name<\/code> field, but also to those in a <code>Dockerfile<\/code>&#8216;s <code>FROM<\/code> instruction. By pulling all the images used in the build steps at the beginning, you can save image download time in subsequent steps.<\/p>\n<p>Note:<br \/>\n<code>gcr.io\/cloud-builders\/docker<\/code> is one of the <a href=\"https:\/\/github.com\/GoogleCloudPlatform\/cloud-builders\">Google Cloud Build official builder images<\/a>, and downloading this image itself does not take any time.<\/p>\n<h2>Summary<\/h2>\n<p>In this article, we introduced a technique to reduce build time in Cloud Build. By pre-downloading the Docker images used in subsequent steps at the beginning of the build process, you can save the image download time for each step. The following points are particularly important:<\/p>\n<ul>\n<li>Use <code>waitFor: [&#039;-&#039;]<\/code> to run the image download step in parallel with other steps.<\/li>\n<li>Pull all the images used in the build steps at the beginning.<\/li>\n<li>The more images you have, the greater the time-saving effect.<\/li>\n<li>For complex builds, strategies like splitting the image download step into multiple parts can also be effective.<\/li>\n<li>Images specified in <code>Dockerfile<\/code> can also benefit from this technique.<\/li>\n<\/ul>\n<p>By using this method, you can reduce build time without changing the content of the build itself. You can expect significant improvements, especially in build processes with many steps.<\/p>\n<h2>References<\/h2>\n<ul>\n<li><a href=\"https:\/\/cloud.google.com\/build\/docs\/configuring-builds\/configure-build-step-order\">Configuring the order of build steps<\/a> <a href=\"https:\/\/cloud.google.com\/build\/docs\/configuring-builds\/configure-build-step-order\">https:\/\/cloud.google.com\/build\/docs\/configuring-builds\/configure-build-step-order<\/a><\/li>\n<li><a href=\"https:\/\/cloud.google.com\/build\/docs\/cloud-builders\">Supported builder images provided by Cloud Build<\/a> <a href=\"https:\/\/cloud.google.com\/build\/docs\/cloud-builders\">https:\/\/cloud.google.com\/build\/docs\/cloud-builders<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/GoogleCloudPlatform\/cloud-builders\">Google Cloud Build official builder images<\/a> GitHub <a href=\"https:\/\/github.com\/GoogleCloudPlatform\/cloud-builders\">https:\/\/github.com\/GoogleCloudPlatform\/cloud-builders<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>Cloud Build \u306e\u30ef\u30b6 \u305d\u306e2 English follows Japanese. \u7d50\u8ad6 \u30d3\u30eb\u30c9\u30d7\u30ed\u30bb\u30b9\u306e\u6700\u521d\u306b\u3001\u3068\u306b\u304b\u304f pull \u3060\u3051\u3092\u5b9f\u884c\u3057\u3066\u304a\u304f\u3088\u3046\u306b\u3057\u3066\u304a\u304f\u3068\u3001\u30d3\u30eb\u30c9\u6642\u9593\u304c\u77ed\u7e2e\u3067\u304d\u308b\u3002 \u30d3\u30eb\u30c9\u30b9\u30c6\u30c3\u30d7\u306b [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[27,13],"tags":[],"class_list":["post-590","post","type-post","status-publish","format-standard","hentry","category-cloud-build","category-google-cloud"],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p4dIdP-9w","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tako.nakano.net\/blog\/wp-json\/wp\/v2\/posts\/590","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tako.nakano.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tako.nakano.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tako.nakano.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tako.nakano.net\/blog\/wp-json\/wp\/v2\/comments?post=590"}],"version-history":[{"count":2,"href":"https:\/\/tako.nakano.net\/blog\/wp-json\/wp\/v2\/posts\/590\/revisions"}],"predecessor-version":[{"id":592,"href":"https:\/\/tako.nakano.net\/blog\/wp-json\/wp\/v2\/posts\/590\/revisions\/592"}],"wp:attachment":[{"href":"https:\/\/tako.nakano.net\/blog\/wp-json\/wp\/v2\/media?parent=590"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tako.nakano.net\/blog\/wp-json\/wp\/v2\/categories?post=590"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tako.nakano.net\/blog\/wp-json\/wp\/v2\/tags?post=590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}