fix: Allow special characters for export script (#128)

This commit is contained in:
Gerald Pinder 2024-03-21 16:01:46 -04:00 committed by GitHub
parent 338b9c699e
commit aa1de26ad9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 34 additions and 30 deletions

View file

@ -18,7 +18,10 @@ COPY ./modules /modules
# This stage is responsible for holding onto
# exports like the exports.sh
FROM docker.io/alpine as stage-exports
RUN printf {{ export_script.print_script() }} >> /exports.sh && chmod +x /exports.sh
COPY <<EOF /exports.sh
{{ self::print_export_script() }}
EOF
RUN chmod +x /exports.sh
FROM {{ recipe.base_image }}:{{ recipe.image_version }}
@ -57,6 +60,8 @@ COPY --from=ghcr.io/blue-build/cli:
latest-installer
{%- endif %} /out/bluebuild /usr/bin/bluebuild
SHELL ["bash", "-c"]
{%- include "modules/modules.j2" %}
# Added in case a user adds something else using the

View file

@ -1,8 +1,26 @@
#!/usr/bin/env bash
get_yaml_array() {
readarray -t "$1" < <(echo "$3" | yq -I=0 "$2")
}
# Function to retrieve module configs and populate an array
# Arguments:
# 1. Variable name to store result
# 2. jq query
# 3. Module config content
get_yaml_array() {
local -n arr=$1
local jq_query=$2
local module_config=$3
if [[ -z $jq_query || -z $module_config ]]; then
echo "Usage: get_yaml_array VARIABLE_TO_STORE_RESULTS JQ_QUERY MODULE_CONFIG" >&2
return 1
fi
readarray -t arr < <(echo "$module_config" | yq -I=0 "$jq_query")
}
# Parse OS version and export it
export OS_VERSION=$(grep -Po "(?<=VERSION_ID=)\d+" /usr/lib/os-release)
# Export functions for use in sub-shells or sourced scripts
export -f get_yaml_array
export OS_VERSION=$(grep -Po '(?<=VERSION_ID=)\d+' /usr/lib/os-release)