code: def _rebuild_containers(
      jobs: Iterable[Job],
      project_id: Optional[str] = None,
  ) -> Dict[Job, str]:
      """this utility rebuilds all the needed containers for the given jobs
  
      This also tags and uploads the containers to the appropriate project
      cloud registry if necessary.
  
      Args:
      jobs: iterable of jobs for which to rebuild containers
      project_id: project id
  
      Returns:
      dictionary mapping jobs to new image tags
      """
  
      image_id_map = {}
  
      container_specs = set([j.experiment.container_spec for j in jobs])
      for c in container_specs:
          image_id = build_image(**c.spec)
          cs_jobs = filter(
              lambda x: x.experiment.container_spec == c, jobs
          )
  
          image_tag = None
          for j in cs_jobs:
              if j.spec.platform in [Platform.CAIP, Platform.GKE]:
                  assert (
                      project_id != None
                  ), "project id must be specified for CAIP, GKE jobs"
  
                  if image_tag is None:
                      image_tag = push_uuid_tag(project_id, image_id)
                  image_id_map[j] = image_tag
              else:
                  image_id_map[j] = image_id
  
      return image_id_map
  
imports: import logging
  import os
  from typing import Any, Dict, Iterable, List, Optional
  from sqlalchemy import or_
  from sqlalchemy.orm import Session
  from caliban.docker.build import build_image
  from caliban.docker.push import push_uuid_tag
  from caliban.history.submit import submit_job_specs
  from caliban.history.types import ContainerSpec, Experiment, ExperimentGroup, Job, JobStatus, Platform
  from caliban.history.util import get_gke_job_name, get_sql_engine, replace_job_spec_image, session_scope, stop_job, update_job_status
  from caliban.platform.gke.util import credentials, user_verify
  from caliban.util import Package, current_user
label_desc: Use image node_id 9 for calling a global function with example usage: _rebuild_containers(jobs, project_id) and returns: image_id_map