Search code examples
pythondockerextractkubernetes-helmdocker-image

extract docker images from helm chart


Is there any way to extract docker images from the helm chart via python?

I would like to avoid any :

helm install --dry-run helm-chart > log

bash scripts to extract this information.

If the helm chart contains two images (for example), I would like to extract these images

Example:

image: repo/image1:1.0     image1.yaml file
image: repo/image2:1.0     image2.yaml file

Solution

  • helm template will render the contents of a Helm chart to YAML files and print it to stdout. A quick-and-dirty answer would be

    helm template helm-chart | grep 'image:'
    

    but you could also use tools like yq to do queries based on the YAML structure.

    You do have to use some sort of Helm command to render the template, since it's common enough to specify things like

    image: 'some/image:{{ .Values.tag }}'
    

    that depend on the input file. The flip side of this is that you can use the usual Helm --set or -f options to specify values, so if you would use different images in different environments (or different builds, or would only include some deployments based on settings) you'll get an accurate reflection of what would be deployed.