code: def main() -> int:
      config_logging()
  
      logging.info("MXNet container based build tool.")
      log_environment()
      chdir_to_script_directory()
  
      parser = argparse.ArgumentParser(
          description="""Utility for building and testing MXNet on docker
      containers""",
          epilog="",
      )
      parser.add_argument(
          "-p",
          "--platform",
          type=str,
          help="Platform. See ci/docker/docker-compose.yml for list of supported "
          "platforms (services).",
      )
  
      parser.add_argument(
          "-b",
          "--build-only",
          help="Only build the container, don't build the project",
          action="store_true",
      )
  
      parser.add_argument(
          "-R",
          "--run-only",
          help="Only run the container, don't rebuild the container",
          action="store_true",
      )
  
      parser.add_argument(
          "-n",
          "--nvidiadocker",
          help="Use nvidia docker",
          action="store_true",
      )
  
      parser.add_argument(
          "--shm-size",
          help="Size of the shared memory /dev/shm allocated in the container (e.g '1g')",
          default="500m",
          dest="shared_memory_size",
      )
  
      parser.add_argument(
          "-l", "--list", help="List platforms", action="store_true"
      )
  
      parser.add_argument(
          "--print-docker-run",
          help="print docker run command for manual inspection",
          action="store_true",
      )
  
      parser.add_argument(
          "-d",
          "--docker-registry",
          help="Dockerhub registry name to retrieve cache from.",
          default="mxnetci",
          type=str,
      )
  
      parser.add_argument(
          "-r",
          "--docker-build-retries",
          help="Number of times to retry building the docker image. Default is 1",
          default=1,
          type=int,
      )
  
      parser.add_argument(
          "--no-pull",
          action="store_true",
          help="Don't pull from dockerhub registry to initialize cache.",
      )
  
      parser.add_argument(
          "--no-cache",
          action="store_true",
          help="passes --no-cache to docker build",
      )
  
      parser.add_argument(
          "--cache-intermediate",
          action="store_true",
          help="passes --rm=false to docker build",
      )
  
      parser.add_argument(
          "-e",
          "--environment",
          nargs="*",
          default=[],
          help="Environment variables for the docker container. "
          "Specify with a list containing either names or name=value",
      )
  
      parser.add_argument(
          "command",
          help="command to run in the container",
          nargs="*",
          action="append",
          type=str,
      )
  
      parser.add_argument(
          "--ccache-dir",
          default=default_ccache_dir(),
          help="ccache directory",
          type=str,
      )
  
      args = parser.parse_args()
  
      command = list(chain.from_iterable(args.command))
      environment = dict(
          [
              (e.split("=")[:2] if "=" in e else (e, os.environ[e]))
              for e in args.environment
          ]
      )
  
      if args.list:
          print(list_platforms())
      elif args.platform:
          platform = args.platform
          tag = get_docker_tag(
              platform=platform, registry=args.docker_registry
          )
          if args.docker_registry and not args.no_pull:
              load_docker_cache(
                  platform=platform,
                  tag=tag,
                  docker_registry=args.docker_registry,
              )
          if not args.run_only:
              build_docker(
                  platform=platform,
                  registry=args.docker_registry,
                  num_retries=args.docker_build_retries,
                  no_cache=args.no_cache,
                  cache_intermediate=args.cache_intermediate,
              )
          else:
              logging.info("Skipping docker build step.")
  
          if args.build_only:
              logging.warning(
                  "Container was just built. Exiting due to build-only."
              )
              return 0
  
          # noinspection PyUnusedLocal
          ret = 0
          if command:
              ret = container_run(
                  platform=platform,
                  nvidia_runtime=args.nvidiadocker,
                  shared_memory_size=args.shared_memory_size,
                  command=command,
                  docker_registry=args.docker_registry,
                  local_ccache_dir=args.ccache_dir,
                  environment=environment,
              )
          elif args.print_docker_run:
              command = []
              ret = container_run(
                  platform=platform,
                  nvidia_runtime=args.nvidiadocker,
                  shared_memory_size=args.shared_memory_size,
                  command=command,
                  docker_registry=args.docker_registry,
                  local_ccache_dir=args.ccache_dir,
                  dry_run=True,
                  environment=environment,
              )
          else:
              # With no commands, execute a build function for the target platform
              command = [
                  "/work/mxnet/ci/docker/runtime_functions.sh",
                  "build_{}".format(platform),
              ]
              logging.info(
                  "No command specified, trying default build: %s",
                  " ".join(command),
              )
              ret = container_run(
                  platform=platform,
                  nvidia_runtime=args.nvidiadocker,
                  shared_memory_size=args.shared_memory_size,
                  command=command,
                  docker_registry=args.docker_registry,
                  local_ccache_dir=args.ccache_dir,
                  environment=environment,
              )
  
          if ret != 0:
              logging.critical(
                  "Execution of %s failed with status: %d", command, ret
              )
              return ret
  
      else:
          parser.print_help()
          list_platforms()
          print(
              """
  Examples:
  
  ./build.py -p armv7
  
      Will build a docker container with cross compilation tools and build MXNet for armv7 by
      running: ci/docker/runtime_functions.sh build_armv7 inside the container.
  
  ./build.py -p armv7 ls
  
      Will execute the given command inside the armv7 container
  
  ./build.py -p armv7 --print-docker-run
  
      Will print a docker run command to get inside the container in a shell
  
  ./build.py -a
  
      Builds for all platforms and leaves artifacts in build_<platform>
  
      """
          )
  
      return 0
  
file_path: mxnet/ci/build.py
imports: import argparse
  import pprint
  import os
  import signal
  import subprocess
  from itertools import chain
  from subprocess import check_call
  from typing import *
  import yaml
  from util import *
label_desc: Use image node_id 10 for calling a global function with example usage: main() and returns: int, int, ret