Was recently looking for a quick way to update Kubernetes manifest files and came across this method which shows you how to do it both with yq
and kustomize
: https://learnk8s.io/templating-yaml-with-code
My solution used his first version which is using https://github.com/mikefarah/yq. Very awesome BTW.
For my script I ended up doing something like this:
cat scripts/update-docker-image.sh
#!/bin/sh
GIT_SHA=$(git rev-parse --short HEAD)
yq w -i all-in-one.yml 'spec.template.spec.containers[0].image' \
"registry.gitlab.com/memestonks/api:$GIT_SHA"