Support any level of nested templated conf

This commit is contained in:
Daniel Berteaud 2024-01-22 11:41:47 +01:00
parent 34a00e5576
commit ea3461c523
1 changed files with 7 additions and 4 deletions

11
ctctl
View File

@ -613,8 +613,10 @@ ctctl_render_templates(){
done
gomplate "${GOMPLATE_COMMON_ARGS[@]}" --context "${VAR_FILES[@]}" -i "[[ . | toYAML ]]" > ${CONFIG}
# And render it again so we can replace any templated values in the config itself
gomplate "${GOMPLATE_COMMON_ARGS[@]}" --context ${VAR_FILES} -f ${CONFIG} -o ${CONFIG}
gomplate "${GOMPLATE_COMMON_ARGS[@]}" --context ${VAR_FILES} -f ${CONFIG} -o ${CONFIG}
# Render it as many time as needed until no [[ ]] are found
while grep -q '\[\[' ${CONFIG}; do
gomplate "${GOMPLATE_COMMON_ARGS[@]}" --context ${VAR_FILES} -f ${CONFIG} -o ${CONFIG}
done
GOMPLATE_COMMON_ARGS+=(--context .=file://${CONFIG})
echo "Redering bundles with gomplate ${GOMPLATE_COMMON_ARGS[@]} ${GOMPLATE_BUNDLE_ARGS[@]} ${GOMPLATE_OUT_ARGS[@]}"
@ -665,8 +667,9 @@ ctctl_render_templates(){
done
gomplate "${GOMPLATE_COMMON_ARGS[@]}" --context "${VAR_FILES[@]}" -i "[[ . | toYAML ]]" > ${CONFIG}
# And render it again so we can replace any templated values in the config itself
gomplate "${GOMPLATE_COMMON_ARGS[@]}" --context ${VAR_FILES} -f ${CONFIG} -o ${CONFIG}
gomplate "${GOMPLATE_COMMON_ARGS[@]}" --context ${VAR_FILES} -f ${CONFIG} -o ${CONFIG}
while grep -q '\[\[' ${CONFIG}; do
gomplate "${GOMPLATE_COMMON_ARGS[@]}" --context ${VAR_FILES} -f ${CONFIG} -o ${CONFIG}
done
# First, cleanup any previously rendered files
rm -rf bundles/${NAME}/example/*