original_docstring: 
      Build lambda layer from Dockerfile. It is assumed that the
      Dockerfile creates a ZIP file named package_localstack in the
      /tmp directory. This ZIP file contains all the code under the
      layers' python directory.
      
docstring: Build lambda layer from Dockerfile. It is assumed that the
  Dockerfile creates a ZIP file named package_localstack in the
  tmp directory. This ZIP file contains all the code under the
  layers' python directory.
docstring_tokens: Build lambda layer from Dockerfile . It is assumed that the Dockerfile creates a ZIP file named package_localstack in the tmp directory . This ZIP file contains all the code under the layers ' python directory .
code: def create_lambda_layer_from_docker(output_dir: str, dockerfile: str, tag: str) -> None:
      """
      Build lambda layer from Dockerfile. It is assumed that the
      Dockerfile creates a ZIP file named package_localstack in the
      /tmp directory. This ZIP file contains all the code under the
      layers' python directory.
      """
      client = docker.from_env()
  
      build_result = client.images.build(
          path="./",
          dockerfile=dockerfile,
          tag=tag,
          # rm=True, # Uncomment to save space
      )
      assert len(build_result) == 2
      # print("Docker build logs:", file=sys.stderr)
      # for log_item in build_result[1]:
      #     print(f"\t{log_item}", file=sys.stderr)
  
      # Comments used while dedugging test within act, no
      # pdb... keeping for a while
      # result = subprocess.run(['pwd'], capture_output=True, text=True, check=True)
      # print(f"pwd: {result.stdout}", file=sys.stderr)
  
      # result = subprocess.run(['ls', '-l'], capture_output=True, text=True,
      #                        check=True)
      # print(f"ls: {result.stdout}", file=sys.stderr)
  
      # result = subprocess.run(['ls', '-l', 'tests'], capture_output=True, text=True,
      #                        check=True)
      # print(f"ls tests: {result.stdout}", file=sys.stderr)
  
      # Copy layer from docker container using temporary tarfile
      container = client.containers.run(image=tag, command="echo", detach=True)
  
      namedtarfile = tempfile.NamedTemporaryFile(delete=True)
      # print(namedtarfile.name, file=sys.stderr)
      bits, stat = container.get_archive(  # pylint: disable=unused-variable
          "/tmp/package_localstack.zip"
      )
      for chunk in bits:
          namedtarfile.write(chunk)
  
      with tarfile.open(namedtarfile.name) as tfile:
          tfile.extract(member="package_localstack.zip", path="./")
      os.rename("./package_localstack.zip", f"{os.path.abspath(output_dir)}/{tag}.zip")
  
      # Original way to copy the layer file from docker container
      # This does not work within act, the mounted volume is from the host
      # machine and not the docker container.
      # command = f"/bin/sh -c 'cp /tmp/package_localstack.zip /local/{tag}.zip'"
      # result = client.containers.run(
      #     image=tag,
      #     command=command,
      #     remove=True,
      #     volumes={os.path.abspath(output_dir): {"bind": "/local/", "mode": "rw"}},
      #     user=0,
      #     stdout=True,
      #     stderr=False
      # )
  
      # This uses docker cli utilities to copy the layer ZIP file to the
      # testing environment
      # Does not work within act, we do not have docker CLI utils
      # with open(os.path.abspath(output_dir) + f"/{tag}.zip", "wb") as layer_zip:
      #     result = subprocess.call(['docker', 'run', '--rm',
      #                               '--entrypoint', 'cat', tag,
      #                               '/tmp/package_localstack.zip'],
      #                              stdout=layer_zip)
code_tokens: def create_lambda_layer_from_docker ( output_dir : str , dockerfile : str , tag : str ) -> None : client = docker . from_env ( ) build_result = client . images . build ( path = "./" , dockerfile = dockerfile , tag = tag , ) assert len ( build_result ) == 2 container = client . containers . run ( image = tag , command = "echo" , detach = True ) namedtarfile = tempfile . NamedTemporaryFile ( delete = True ) bits , stat = container . get_archive ( "/tmp/package_localstack.zip" ) for chunk in bits : namedtarfile . write ( chunk ) with tarfile . open ( namedtarfile . name ) as tfile : tfile . extract ( member = "package_localstack.zip" , path = "./" ) os . rename ( "./package_localstack.zip" , f"{os.path.abspath(output_dir)}/{tag}.zip" )
short_docstring: Build lambda layer from Dockerfile.
short_docstring_tokens: Build lambda layer from Dockerfile .
comment: """
      Build lambda layer from Dockerfile. It is assumed that the
      Dockerfile creates a ZIP file named package_localstack in the
      /tmp directory. This ZIP file contains all the code under the
      layers' python directory.
      """$SEP$# rm=True, # Uncomment to save space$SEP$# print("Docker build logs:", file=sys.stderr)$SEP$# for log_item in build_result[1]:$SEP$#     print(f"\t{log_item}", file=sys.stderr)$SEP$# Comments used while dedugging test within act, no$SEP$# pdb... keeping for a while$SEP$# result = subprocess.run(['pwd'], capture_output=True, text=True, check=True)$SEP$# print(f"pwd: {result.stdout}", file=sys.stderr)$SEP$# result = subprocess.run(['ls', '-l'], capture_output=True, text=True,$SEP$#                        check=True)$SEP$# print(f"ls: {result.stdout}", file=sys.stderr)$SEP$# result = subprocess.run(['ls', '-l', 'tests'], capture_output=True, text=True,$SEP$#                        check=True)$SEP$# print(f"ls tests: {result.stdout}", file=sys.stderr)$SEP$# Copy layer from docker container using temporary tarfile$SEP$# print(namedtarfile.name, file=sys.stderr)$SEP$# pylint: disable=unused-variable$SEP$# Original way to copy the layer file from docker container$SEP$# This does not work within act, the mounted volume is from the host$SEP$# machine and not the docker container.$SEP$# command = f"/bin/sh -c 'cp /tmp/package_localstack.zip /local/{tag}.zip'"$SEP$# result = client.containers.run($SEP$#     image=tag,$SEP$#     command=command,$SEP$#     remove=True,$SEP$#     volumes={os.path.abspath(output_dir): {"bind": "/local/", "mode": "rw"}},$SEP$#     user=0,$SEP$#     stdout=True,$SEP$#     stderr=False$SEP$# )$SEP$# This uses docker cli utilities to copy the layer ZIP file to the$SEP$# testing environment$SEP$# Does not work within act, we do not have docker CLI utils$SEP$# with open(os.path.abspath(output_dir) + f"/{tag}.zip", "wb") as layer_zip:$SEP$#     result = subprocess.call(['docker', 'run', '--rm',$SEP$#                               '--entrypoint', 'cat', tag,$SEP$#                               '/tmp/package_localstack.zip'],$SEP$#                              stdout=layer_zip)