It looks like the package rules for `docker_image`...
# general
m
It looks like the package rules for
docker_image
produce a file called
docker-info.json
. Is it possible for me make
docker-info.json
available as a resource? I'm trying
pants run :print_info
Copy code
docker_image(
  name="my_image",
  instructions=["FROM alpine:latest"]
)
experimental_wrap_as_resources(
  name="docker_info",
  inputs=[":my_image"],
  outputs=["my_image.docker-info.json"],
)
run_shell_command(
  name="print_info",
  command="cat my_image.docker-info.json",
  execution_dependencies=[":docker_info"],
)
Apart from the missing docker-info file there are no errors. There's no evidence that the execution_dependencies are being built. I'm not sure how to troubleshoot this since it seems to be failing silently.
g
Have you used
--keep-sandboxes=always
and looked what exists in there? I don't think you need the experimental_wrap, just take the image directly (the docs says "packages compiled for other targets"). It might just be that you need
cat {chroot}/...
or something like that.
m
Thank you, I didn't realize it was being written to chroot. You are correct,
experimental_wrap_as_resources
was not needed for
run_shell_command
I configured a macro to load the files in Python, in case anyone else comes across this...
Copy code
def docker_info_resource(
    name: str = None,
    image: str = None,
    package: str = None,
    output: str = None,
    tags: list[str] = None,
    description: str = None,
):
  shell_command(
    name=f"{name}_shell",
    command=f"""
      if [ -e {{chroot}}/{package}/{output} ]; then 
        mv {{chroot}}/{package}/{output} {output}
      else 
        echo "File not found at {{chroot}}/{package}/{output}"
        echo "Generated contents:"
        find {{chroot}}
        exit 1
      fi
    """,
    workdir=".",
    tools=['echo', 'find', 'mv'],
    output_files=[output],
    execution_dependencies=[image],
    tags=tags,
  )
  experimental_wrap_as_resources(
    name=name,
    inputs=[f":{name}_shell"],
    tags=tags,
    description=description,
  )
Then after adding it as a Python dependency you can do something like:
Copy code
from importlib import resources
import json

json.loads(resources.read_text('my.package', 'my_image.docker-info.json'))