builder looks like it's working

This commit is contained in:
2024-07-26 00:27:20 -07:00
parent da629c05d8
commit 2dd622db73
8 changed files with 61 additions and 52 deletions
+26 -6
View File
@@ -11,13 +11,33 @@ process_env_vars() {
var_name="${env_var%%=*}" # Variable name
var_value="${env_var#*=}" # Variable value
# Handle variables with and without default values
if [[ "$var_value" == *'${'*:*'}'* ]]; then
# For variables with default values
modified_var="${var_name}=\${${APP_NAME}_${var_value#\$\{}"
# Check if the variable value contains a reference to another variable with the format ${VAR_NAME:-default}
if [[ "$var_value" == *'${'*':'*'}'* ]]; then
# Extract the variable inside the ${} braces
ref_var="${var_value#\$\{}"
ref_var="${ref_var%%[:-]*}"
# Extract the default value part
default_value="${var_value##*:-}"
default_value="${default_value%\}}"
# Check if the reference variable already contains APP_NAME_ prefix
if [[ "$ref_var" == ${APP_NAME}_* ]]; then
# If it already contains the prefix, use it as is
modified_var="${var_name}=\${${ref_var}:-${default_value}}"
else
# If not, add the APP_NAME_ prefix
modified_var="${var_name}=\${${APP_NAME}_${ref_var}:-${default_value}}"
fi
else
# For variables without default values
modified_var="${var_name}=\${${APP_NAME}_${var_name}:-${var_value}}"
# For variables without ${VAR_NAME} references
if [[ "$var_name" == ${APP_NAME}_* ]]; then
# If the variable name already starts with APP_NAME_, do not prefix again
modified_var="${var_name}=${var_value}"
else
# Add APP_NAME_ prefix for consistency
modified_var="${var_name}=\${${APP_NAME}_${var_name}:-${var_value}}"
fi
fi
# Append the modified variable to results
+1 -2
View File
@@ -18,5 +18,4 @@ EOF
)
# Print the variable to verify the content
echo "***** NEW docker-compose.yml *****"
echo "$BLDR_NEW_DCF"
echo "$BLDR_NEW_DCF" > ${BLDR_DIR}/docker-compose.yml
+1 -2
View File
@@ -15,5 +15,4 @@ EOF
# Output the content to a file
BLDR_NEW_SE="$file_content"
echo "***** Sample Extends *****"
echo "$BLDR_NEW_SE"
echo "$BLDR_NEW_SE" > ${BLDR_DIR}/sample-extends.yml
+6 -6
View File
@@ -1,23 +1,23 @@
#!/bin/bash
BLDR_NEW_SE+="# $BLDR_APP\n"
BLDR_ENV_FILE+="# $BLDR_APP\n"
BLDR_ENV_FILE+="COOKBOOK=$BLDR_PARENT_PATH #HELP: cookbooks\n"
while IFS= read -r line; do
# Use a regex to match and extract variable names and defaults
if [[ $line =~ \$\{([A-Za-z_][A-Za-z0-9_]*)\} ]]; then
# Matched ${VAR_NAME} (without default)
var_name="${BASH_REMATCH[1]}"
BLDR_NEW_SE+="${var_name}=\n"
BLDR_ENV_FILE+="${var_name}=\n"
elif [[ $line =~ \$\{([A-Za-z_][A-Za-z0-9_]*)[:-](.*)\} ]]; then
# Matched ${VAR_DEF:-default} (with default)
var_name="${BASH_REMATCH[1]}"
default_value="${BASH_REMATCH[2]:1}"
BLDR_NEW_SE+="${var_name}=${default_value}\n"
BLDR_ENV_FILE+="${var_name}=${default_value}\n"
fi
done <<< "$BLDR_NEW_DCF"
# Remove duplicates from the output
BLDR_NEW_SE=$(echo -e "$BLDR_NEW_SE" | sort -u)
BLDR_ENV_FILE=$(echo -e "$BLDR_ENV_FILE" | sort -u)
echo "***** NEW sample.env *****"
echo "$BLDR_NEW_SE"
echo "$BLDR_ENV_FILE" > ${BLDR_DIR}/sample.env