Wednesday, 12 January 2022

Today I Learned - IBM Container Registry - Formatting the output ...

Having got into the use of JSON to format the output from various different IBM Cloud CLI tools, using jq and jsonpath as per this example: -

JQ vs jsonpath

However, for reasons known to them, the Container Registry (CR) plugin uses a different mechanism to format output, namely Go templates.

This is well documented here: -

Formatting and filtering the CLI output for IBM Cloud Container Registry commands

So, as an example, if I want to look for images that are greater than 1,000,000 bytes ( 1 Mb ) and wish to display the repository, tag and security status, this is what I'd run: -

ic cr image-list --format "{{ if gt .Size 1000000 }}{{ .Repository }}:{{ .Tag }} {{ .SecurityStatus.Status }}{{end}}"

Similarly, if I want to list all images, regardless of size, but including the namespace: -

ic cr image-list --format "{{ .Repository }}:{{ .Tag }} {{ .Namespace }} {{ .SecurityStatus.Status }}"

The documentation covers the formatting options in WAAAAAY more detail: -

No comments:

TIL - read-only variables in Linux

 A co-worker was seeing an exception: -  line 8: TMOUT: readonly variable when trying to SCP a file from a remote Linux box. I did some digg...