refactor: global get_yaml_array function

This commit is contained in:
ER
2023-08-13 16:59:23 +03:00
parent 7fea9a143f
commit 9ad0048fc3
2 changed files with 5 additions and 3 deletions

View File

@@ -9,8 +9,10 @@ MODULE_DIRECTORY="/tmp/modules"
# https://mikefarah.gitbook.io/yq/usage/tips-and-tricks#yq-in-a-bash-loop
get_yaml_array() {
readarray "$1" < <(yq -o=j -I=0 "$2" "$RECIPE_FILE" )
# creates array $1 with content at key $2 from $3
readarray "$1" < <(echo "$3" | yq -o=j -I=0 "$2" )
}
export -f get_yaml_array # this makes the function available to all modules
# Automatically determine which Fedora version we're building.
FEDORA_VERSION="$(grep -Po '(?<=VERSION_ID=)\d+' /usr/lib/os-release)"
@@ -23,7 +25,7 @@ IMAGE_NAME="$(yq '.name' "$RECIPE_FILE")"
echo "Building $IMAGE_NAME from Fedora $FEDORA_VERSION ($BASE_IMAGE)."
# Run each module
get_yaml_array MODULES '.modules[]'
readarray MODULES < <(yq -o=j -I=0 '.modules[]' "$RECIPE_FILE" )
for MODULE in "${MODULES[@]}"; do
TYPE=$(echo "$MODULE" | yq '.type')

View File

@@ -3,7 +3,7 @@
# Tell build process to exit if there are any errors.
set -oue pipefail
readarray RUN < <(yq -o=j -I=0 '.run[]' "$1" )
get_yaml_array RUN '.run[]' "$1"
cd "$CONFIG_DIRECTORY/scripts"