Hi folks :wave:. I’m trying to build an iso/qcow i...
# general
l
Hi folks 👋. I’m trying to build an iso/qcow image inside a docker image. This docker image is being built by pants, so far so good! Now I'm trying to use the docker image target like so:
Copy code
docker_image(
    name = "image-builder",
)

adhoc_tool(
    name = "image",
    runnable = ":image-builder",
    args=["dostuff"],
    output_directories=["results/"],
    log_output=True,
)

archive(
    name = "archive",
    format = "zip",
    files = [
        ":image",
    ]
)
Now running
pants package :archive
results in
Copy code
ProcessExecutionFailure: Process 'the `adhoc_tool` at :image' failed with exit code 1.
stdout:

stderr:
the input device is not a TTY
Which is probably because the runnable target of the
docker_image
is trying to start an interactive shell 🤔. Is it possible to use a pants-created docker image to create an artefact? Using adhoc_tool like this? Or should this be solved in a different way? Thanks!
Also tried using a docker environment
Copy code
docker_environment(
  name="image-builder-env",
  platform="image-builder",
  image="//:image-builder",
)
But the target reference is not recognised 🤔
f
For
docker_environment
the image has to be available locally before the start of the Pants run.
and then the image reference would need to be an actual image reference and not a Pants target address
l
Gotcha. Is there a way to “prep” the docker environment using pants? Maybe using an entrypoint or something?
f
Not currently. The image used for an
docker_environment
has its entrypoint overridden so Pants knows the container will not exit immediately since subsequent process invocations in the container are handled via
docker exec
👍 1
l
Do you know if this is possible using adhoc_tool and/or shell_command?
I’m thinking maybe using shell_command running in the docker environment using the base image I was trying to build with pants. The shell command will run idempotent install commands before doing the actual build command. It’s not super hermetic with the package installation side effect, but I think it’s better than having to remember to do two pants invocations, one for the docker image and one for the build inside the docker image.
f
Not currently. The
docker_environment
logic is mostly in Rust and does not have the ability currently to call back into the Python rule code to allow for such setup logic.
I imagine you could work around it if you could run a shell_command as a dependency (although it would need to run on each Pants run in case the container restarted). But you would need this PR https://github.com/pantsbuild/pants/pull/21245 to allow configuring a new field
cache_scope="session"
for
shell_command
and
adhoc_tool
A more straight-forward solution would be to allow the entrypoint to be respected.
👍 1
That would just be an option and changing the line I linked earlier.
The only requirement of the respected entrypoint would be to not exit.
(Otherwise the container would stop and Pants would have to restart it in a forever loop.)