code: def _dockerfile_template(
      job_mode: c.JobMode,
      workdir: Optional[str] = None,
      package: Optional[Union[List, u.Package]] = None,
      requirements_path: Optional[str] = None,
      conda_env_path: Optional[str] = None,
      setup_extras: Optional[List[str]] = None,
      adc_path: Optional[str] = None,
      credentials_path: Optional[str] = None,
      jupyter_version: Optional[str] = None,
      inject_notebook: NotebookInstall = NotebookInstall.none,
      shell: Optional[Shell] = None,
      extra_dirs: Optional[List[str]] = None,
      resource_files: Optional[List[str]] = None,
      caliban_config: Optional[Dict[str, Any]] = None,
  ) -> str:
      """Returns a Dockerfile that builds on a local CPU or GPU base image (depending
      on the value of job_mode) to create a container that:
  
      - installs any dependency specified in a requirements.txt file living at
        requirements_path, a conda environment at conda_env_path, or any
        dependencies in a setup.py file, including extra dependencies, if
        setup_extras isn't None
      - injects gcloud credentials into the container, so Cloud interaction works
        just like it does locally
      - potentially installs a custom shell, or jupyterlab for notebook support
      - copies all source needed by the main module specified by package, and
        potentially injects an entrypoint that, on run, will run that main module
  
      Most functions that call _dockerfile_template pass along any kwargs that they
      receive. It should be enough to add kwargs here, then rely on that mechanism
      to pass them along, vs adding kwargs all the way down the call chain.
      """
      uid = os.getuid()
      gid = os.getgid()
      username = u.current_user()
  
      if isinstance(package, list):
          package = u.Package(*package)
  
      if workdir is None:
          workdir = DEFAULT_WORKDIR
  
      base_image = c.base_image(
          caliban_config, job_mode
      ) or base_image_id(job_mode)
      c_home = container_home()
  
      dockerfile = f"""
  FROM {base_image}
  
  # Create the same group we're using on the host machine.
  RUN [ $(getent group {gid}) ] || groupadd --gid {gid} caliban
  
  # Create the user by name. --no-log-init guards against a crash with large user
  # IDs.
  RUN useradd --no-log-init --no-create-home -u {uid} -g {gid} --shell /bin/bash {username}
  
  # The directory is created by root. This sets permissions so that any user can
  # access the folder.
  RUN mkdir -m 777 {workdir} {CREDS_DIR} {RESOURCE_DIR} {c_home}
  
  ENV HOME={c_home}
  
  WORKDIR {workdir}
  
  USER {uid}:{gid}
  """
      dockerfile += _credentials_entries(
          uid, gid, adc_path=adc_path, credentials_path=credentials_path
      )
  
      dockerfile += _custom_packages(
          uid,
          gid,
          packages=c.apt_packages(caliban_config, job_mode),
          shell=shell,
      )
  
      dockerfile += _dependency_entries(
          workdir,
          uid,
          gid,
          requirements_path=requirements_path,
          conda_env_path=conda_env_path,
          setup_extras=setup_extras,
      )
  
      if inject_notebook.value != "none":
          install_lab = inject_notebook == NotebookInstall.lab
          dockerfile += _notebook_entries(
              lab=install_lab, version=jupyter_version
          )
  
      dockerfile += _extra_dir_entries(workdir, uid, gid, extra_dirs)
  
      dockerfile += _resource_entries(uid, gid, resource_files)
  
      if package is not None:
          # The actual entrypoint and final copied code.
          dockerfile += _package_entries(
              workdir, uid, gid, package, caliban_config
          )
  
      return dockerfile
  
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 24 for calling a global function with example usage: _dockerfile_template(job_mode, workdir, package, requirements_path, conda_env_path, setup_extras, adc_path, credentials_path, jupyter_version, inject_notebook, shell, extra_dirs, resource_files, caliban_config) and returns: dockerfile