Created
October 14, 2020 02:09
-
-
Save jtigger/a9d9c4d8b29090c568eda6a89593683a to your computer and use it in GitHub Desktop.
Convert between "ImagesLock" and kbld's "Config" files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
KIND=$(yq --raw-output '.kind' <(cat $1)) | |
case ${KIND} in | |
"Config") | |
read -r -d '' TEMPLATE <<'EOF' | |
#@ load("@ytt:data", "data") | |
--- | |
apiVersion: imgpkg.k14s.io/v1alpha1 | |
kind: ImagesLock | |
spec: | |
images: | |
#@ for/end override in data.values.overrides: | |
- url: #@ override.newImage | |
name: #@ override.image.split(":")[0] | |
tag: #@ override.image.split(":")[1] | |
metadata: "" | |
EOF | |
;; | |
"ImagesLock") | |
read -r -d '' TEMPLATE <<'EOF' | |
#@ load("@ytt:data", "data") | |
--- | |
apiVersion: kbld.k14s.io/v1alpha1 | |
kind: Config | |
overrides: | |
#@ for/end img in data.values.spec.images: | |
- image: #@ "{}:{}".format(img.name, img.tag) | |
newImage: #@ img.url | |
preresolved: true | |
EOF | |
;; | |
*) | |
echo "File $1 is an unexpected kind, "${KIND}" (expected one of 'Config', 'ImageLock')." | |
esac | |
ytt -f values.yml=<(echo -e "#@data/values\n---\n"; cat $1) -f template.yml=<(echo "${TEMPLATE}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment