code: def build_image(
      job_mode: c.JobMode,
      build_path: str,
      credentials_path: Optional[str] = None,
      adc_path: Optional[str] = None,
      no_cache: bool = False,
      **kwargs,
  ) -> str:
      """Builds a Docker image by generating a Dockerfile and passing it to `docker
      build` via stdin. All output from the `docker build` process prints to
      stdout.
  
      Returns the image ID of the new docker container; if the command fails,
      throws on error with information about the command and any issues that caused
      the problem.
  
      """
      caliban_config = kwargs.get("caliban_config", {})
  
      # Paths for resource files.
      sql_proxy_path = um.cloud_sql_proxy_path()
      launcher_path = um.launcher_path()
  
      with ufs.TempCopy(
          {
              credentials_path: ".caliban_default_creds.json",
              adc_path: ".caliban_adc_creds.json",
              sql_proxy_path: um.CLOUD_SQL_WRAPPER_SCRIPT,
              launcher_path: um.LAUNCHER_SCRIPT,
          }
      ) as creds:
          with tempfile.NamedTemporaryFile() as id_file:
              # generate our launcher configuration file
              with um.launcher_config_file(
                  path=".", caliban_config=caliban_config
              ) as launcher_config:
                  cache_args = ["--no-cache"] if no_cache else []
                  cmd = (
                      ["docker", "build", "--platform", "linux/amd64"]
                      + cache_args
                      + ["--iidfile", id_file.name]
                      + ["--rm", "-f-", build_path]
                  )
  
                  dockerfile = _dockerfile_template(
                      job_mode,
                      credentials_path=creds.get(credentials_path),
                      adc_path=creds.get(adc_path),
                      resource_files=[
                          creds.get(sql_proxy_path),
                          creds.get(launcher_path),
                          launcher_config,
                      ],
                      **kwargs,
                  )
  
                  joined_cmd = " ".join(cmd)
                  logging.info("Running command: {}".format(joined_cmd))
  
                  try:
                      _, ret_code = ufs.capture_stdout(
                          cmd, input_str=dockerfile
                      )
                      if ret_code == 0:
                          image_id = None
                          with open(id_file.name) as f:
                              image_id = f.read()
                          return image_id
  
                      else:
                          error_msg = "Docker failed with error code {}.".format(
                              ret_code
                          )
                          raise DockerError(error_msg, cmd, ret_code)
  
                  except subprocess.CalledProcessError as e:
                      logging.error(e.output)
                      logging.error(e.stderr)
  
imports: from __future__ import absolute_import, division, print_function
  import json
  import os
  import subprocess
  import tempfile
  from enum import Enum
  from pathlib import Path
  from typing import Any, Dict, List, NamedTuple, NewType, Optional, Union
  from absl import logging
  from blessings import Terminal
  import caliban.config
  import caliban.util
  import caliban.util.fs
  import caliban.util.metrics
label_desc: Use image node_id 25 for calling a global function with example usage: build_image(job_mode, build_path, credentials_path, adc_path, no_cache) and returns: image_id