Hey there! Quick question: If I build and publish ...
# general
b
Hey there! Quick question: If I build and publish my Docker images using Pants (and publish them to a private repo), is there a way to export the image paths to an external file like JSON? I'm trying to figure out how to feed the Docker image paths to AWS CDK for deployment. I saw a thread about using CDK to build images using pex artifacts, but I actually want to use the Docker image path directly. Any ideas or suggestions would be much appreciated. Thanks!
b
2.16 will include https://github.com/pantsbuild/pants/pull/17299, which has docker images output a JSON file when packaged (including to
dist/
when running
./pants package path/to:docker_image
, or when using as a dependency). So, some options: 1. use a dev release like
2.16.0.dev7
, but this will likely make life a bit trickier (e.g. the docs are only published for stable (2.14 and before) and beta versions (2.15)) 2. parse the output of pants (I've heard some people doing this) 3. export the images to well-known/hard-coded tags, like
some_repo:latest
and then retag them outside paths pants before pushing (this is what we do) Am I understanding your question correctly?
b
Yes, you're understanding me correctly. I'm interested in trying the 2.16 support. But just to clarify, when you say "parsing the output of Pants," which files/output would I parse? What do you mean by "retag them outside paths"? My idea was to extract the Docker image paths from an external file, parse it in the CDK application and then use the Docker names (as specified under "BUILD") directly in CDK to find the image path. Does that make sense, or is there a better approach you'd recommend? Thanks!
b
when you say "parsing the output of Pants," which files/output would I parse?
Ah, yeah, when you run
./pants package ...
with a docker image target, pants will print something like the following to stderr:
Copy code
09:06:41.16 [INFO] Built docker image: host/repo:tag
Docker image ID: sha256:0123456789abcdef
And so a CI script could use grep/sed etc. to extract the relveant information (or save it to a file and have the CDK app parse it in a real programming language)
What do you mean by "retag them outside paths"?
Ah, typo, sorry: I mean "outside _pants_". That is, if pants tags with a hard-coded tag, run
docker tag some_repo:latest $COMPUTED_TAG
and then
docker push $COMPUTED_TAG
, where
$COMPUTED_TAG
is fed into CDK too (or some other way of retagging with the "real" tag).
b
Thanks again. I will give options 1 a try, and 3 if I run into issues. Parsing the stdout seems a bit risky.