code: def build(
      target_image: str,
      base_image: Optional[str] = None,
      dockerfile_name: Optional[str] = None,
      setup_py_filename: Optional[str] = None,
  ) -> str:
      """Build containers.
  
      Generates a dockerfile if needed and build a container image using docker SDK.
  
      Args:
        target_image: the target image path to be built.
        base_image: the image path to use as the base image.
        dockerfile_name: the dockerfile name, which is stored in the workspace
          directory. The default workspace directory is '.' and cannot be changed
          for now.
        setup_py_filename: the setup.py file name, which is used to build a python
          package for the workspace directory. If not specified, the whole directory
          is copied and PYTHONPATH is configured.
  
      Returns:
        Built image name with sha256 id.
      """
      dockerfile_name = dockerfile_name or os.path.join(
          labels.BUILD_CONTEXT, labels.DOCKERFILE_NAME
      )
  
      dockerfile.Dockerfile(
          filename=dockerfile_name,
          setup_py_filename=setup_py_filename,
          base_image=base_image,
      )
  
      # Uses Low-level API for log streaming.
      docker_low_client = docker.APIClient(
          **docker_utils.kwargs_from_env(), timeout=_BUILD_TIMEOUT_SECS
      )
      log_stream = docker_low_client.build(
          path=labels.BUILD_CONTEXT,
          dockerfile=dockerfile_name,
          tag=target_image,
          rm=True,
          decode=True,
      )
      _print_docker_log_stream(log_stream, "stream")
  
      docker_client = docker.from_env(timeout=_BUILD_TIMEOUT_SECS)
      log_stream = docker_client.images.push(
          repository=target_image, stream=True, decode=True
      )
      _print_docker_log_stream(log_stream, "status", newline=True)
  
      image_id = docker_client.images.get_registry_data(target_image).id
      return f"{_get_image_repo(target_image)}@{image_id}"
  
file_path: tfx/tfx/tools/cli/container_builder/builder.py
imports: import os
  from typing import Any, Dict, Iterable, Optional
  import click
  import docker
  from docker import utils
  from tfx.tools.cli.container_builder import dockerfile
  from tfx.tools.cli.container_builder import labels
label_desc: Use image node_id 3 for calling a global function with example usage: build(target_image, base_image, dockerfile_name, setup_py_filename) and returns: _get_image_repo, str, image_id