I'm interested in using a `docker_image` as a depe...
# general
m
I'm interested in using a
docker_image
as a dependency in a python script. I've written a script for deploying my application and I would like to use pants to build and run the deployment script in one step. At the moment I'm looking at
runtime_package_dependencies
in
python_test
but there doesn't seem to be an equivalent for
python_source
unless I'm missing something. Additionally, it's not clear to me how to obtain the digest of the image built by the corresponding
pants publish
command. I'll potentially be running multiple of these in parallel and don't want to rely on fixed tags.
b
Additionally, it's not clear to me how to obtain the digest of the image built by the corresponding
pants publish
command
Metadata about the image is output as a JSON file, if you run
pants package path/to:image
you can see it in your
dist/
folder I think.
At the moment I'm looking at
runtime_package_dependencies
in
python_test
but there doesn't seem to be an equivalent for
python_source
unless I'm missing something
Unfortunately I don't think you're missing something. I believe one thing people do is build an orchestration binary that itself runs Pants, e.g.
pants package path/to:run-my-deploy && dist/path.to/run-my-deploy.pex
or similar schemes along those lines. Might that work for you?
m
This is my temporary solution, in my BUILD I've added:
Copy code
docker_image(
    ...
    image_tags=["{build_args.INVOCATION_UUID}"]
)
And in my python run script:
Copy code
# Build the docker image for this run.
  with tempfile.NamedTemporaryFile() as publish:
    await execute_and_stream(
        f"pants publish {_docker_target.value} --publish-output={publish.name}",
        env=os.environ | {
            "PANTS_CONCURRENT": "True",
            "INVOCATION_UUID": uuid.uuid4().hex,
        },
        cwd=os.environ["PWD"])
    build_result = json.load(publish)