@@ -129,14 +129,14 @@ class Config(BaseDockerBundler.Config):
129129 from flags.
130130 is_async: Whether to build asynchronously. If True, callers should invoke
131131 `wait_until_finished()` to wait for bundling to complete.
132+ private_worker_pool: If provided, should be the identifier of a private worker pool.
133+ See: https://cloud.google.com/build/docs/private-pools/private-pools-overview
132134 """
133135
134136 # GCP project.
135137 project : Required [str ] = REQUIRED
136138 # Build image asynchronously.
137139 is_async : bool = True
138- # If provided, should be the identifier of a private worker pool.
139- # See: https://cloud.google.com/build/docs/private-pools/private-pools-overview
140140 private_worker_pool : Optional [str ] = None
141141
142142 @classmethod
@@ -175,9 +175,14 @@ def _build_and_push(
175175 )
176176 image_path , image_tag = image .rsplit (":" , maxsplit = 1 )
177177 latest_tag = f"{ image_path } :latest"
178- cloudbuild_yaml = f"""
179- steps:
180- - name: "gcr.io/cloud-builders/docker"
178+
179+ # Build steps - start with main image
180+ build_steps = []
181+ images_list = [f'"{ image } "' , f'"{ latest_tag } "' ]
182+
183+ # Main image build step
184+ build_steps .append (
185+ f"""- name: "gcr.io/cloud-builders/docker"
181186 args: [
182187 "build",
183188 "-f", "{ os .path .relpath (dockerfile , context )} ",
@@ -193,11 +198,44 @@ def _build_and_push(
193198 "."
194199 ]
195200 env:
196- - "DOCKER_BUILDKIT=1"
201+ - "DOCKER_BUILDKIT=1\" """
202+ )
203+
204+ # Add sidecar image build steps
205+ for sidecar in cfg .sidecars :
206+ sidecar_target = sidecar
207+ sidecar_image_path = f"{ cfg .repo } /{ sidecar } "
208+ sidecar_image = f"{ sidecar_image_path } :{ image_tag } "
209+ sidecar_latest_image = f"{ sidecar_image_path } :latest"
210+
211+ build_steps .append (
212+ f"""- name: "gcr.io/cloud-builders/docker"
213+ args: [
214+ "build",
215+ "-f", "{ os .path .relpath (dockerfile , context )} ",
216+ "-t", "{ sidecar_image } ",
217+ "-t", "{ sidecar_latest_image } ",
218+ "--target", "{ sidecar_target } ",
219+ "--cache-from", "{ sidecar_image } ",
220+ "--cache-from", "{ sidecar_latest_image } ",
221+ { cache_from }
222+ { build_platform }
223+ { build_args }
224+ { labels }
225+ "."
226+ ]
227+ env:
228+ - "DOCKER_BUILDKIT=1\" """
229+ )
230+
231+ images_list .extend ([f'"{ sidecar_image } "' , f'"{ sidecar_latest_image } "' ])
232+
233+ cloudbuild_yaml = f"""
234+ steps:
235+ { chr (10 ).join (build_steps )}
197236timeout: 3600s
198237images:
199- - "{ image } "
200- - "{ latest_tag } "
238+ { chr (10 ).join ([f"- { img } " for img in images_list ])}
201239tags: [{ image_tag } ]
202240options:
203241 logging: CLOUD_LOGGING_ONLY
0 commit comments