Hello all. I would like to run a shell script (or ...
# general
b
Hello all. I would like to run a shell script (or python) after I publish a docker image and not quite able to piece together how that should work. After a docker image is published to a repo we need to run a "registration" step of sorts. I can use a run_shell_command target that depends on the docker build but as far as I can tell that runs after a "package" goal, not for publish. My other thought is to do a changed-since and which ever paths show up get piped into a normal shell command that knows image name and tag ahead of time. Any thoughts?
1
g
We do exactly this to publish images to our infra tools! Just slightly different. We run a Python script which internally invokes Pants (using
PANTS_CONCURRENT=true
) to do the following: •
pants --changed-since [...] list
to retrieve a list of changed images, if any •
pants publish
those with
--publish-output=artifacts.json
• Parse artifacts.json to figure out which things were published for what target • Publish those details to the system that need it I unfortunately don't know what pants built-in Docker backend puts in artifacts.json or if it's useful for this, though. We use another plugin for that.
All this is a single script of about 100 lines. Being able to invoke Pants from Pants is a great "hack" to get a bit more expressivity when building complex pipelines.
c
This is the exact use case for the
--publish-output
option, in there you’ll have details of all the images that was processed so you can register the details for the images as appropriate in your CI/CD systems.
b
I wasn't aware of the
--publish-output
flag. It seems promising. Thank you @gorgeous-winter-99296 and @curved-television-6568
👍 1
🙇 1
Looking at the json file and it looks like it fits the bill. Is there a schema associated with the JSON output? Just want to make sure I know all possibilities so I can cover the possible cases. Or is it if there is an exit_code 0 + status published is enough to say there was success?
g
Some are fairly standard - target, name, published status, etc. But each backend that publishes can add their own data. https://github.com/pantsbuild/pants/blob/main/src/python/pants/core/goals/publish.py#L138-L145
👍 1