Builder Changes to get Mariadb working

This commit is contained in:
2024-07-26 11:06:27 -07:00
parent 71c2ac8aa3
commit 2f1c6757c8
8 changed files with 35 additions and 47 deletions
+11 -18
View File
@@ -8,12 +8,14 @@ process_env_vars() {
# Loop through each environment variable
while IFS= read -r env_var; do
# Split into name and value parts based on '='
var_name="${env_var%%=*}" # Variable name
var_value="${env_var#*=}" # Variable value
var_name="${env_var%%:*}" # Variable name (split by colon for YAML)
var_value="${env_var#*: }" # Variable value (remove leading space)
# 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
# Handle variables without existing braces (not previously processed)
if [[ "$var_value" != *'${'* ]]; then
modified_var="${var_name}: \${${APP_NAME}_${var_name}:-${var_value}}"
else
# Handle variables already having ${} and possible default
ref_var="${var_value#\$\{}"
ref_var="${ref_var%%[:-]*}"
@@ -23,20 +25,11 @@ process_env_vars() {
# 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}}"
# Use the reference variable as is if it already contains the prefix
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 ${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}}"
# Add APP_NAME_ prefix to reference variable
modified_var="${var_name}: \${${APP_NAME}_${ref_var}:-${default_value}}"
fi
fi
+2 -2
View File
@@ -4,10 +4,10 @@ BLDR_IMAGE_VAR="\${${BLDR_APP^^}_IMAGE:-$BLDR_DC_IMAGE}"
# Generate Docker Compose content and save it to a variable
BLDR_NEW_DCF=$(cat <<EOF
version: '3.4'
version: '3.8'
services:
stash:
$BLDR_APP:
image: $BLDR_IMAGE_VAR
restart: unless-stopped
environment:
-2
View File
@@ -1,11 +1,9 @@
#!/bin/bash
# List all directories in the current directory that don't start with an underscore
directories
directories=$(find . -maxdepth 1 -type d -not -name '_*' -exec basename {} \; | grep -v '[_\.]' | sort -r)
# Use fzf to allow the user to select a directory
selected_dir
selected_dir=$(echo "$directories" | fzf --prompt="Select a directory: ")
# Check if a directory was selected
+2 -2
View File
@@ -15,8 +15,8 @@ get_env_vars() {
local compose_content="$1"
local env_vars=""
# Use yq to extract environment variables from services
env_vars=$(echo "$compose_content" | yq eval '.services.*.environment[]' - 2>/dev/null)
# Use yq to extract the environment variables in 'key: value' format
env_vars=$(echo "$compose_content" | yq eval '.services.*.environment | to_entries | .[] | "\(.key): \(.value)"' - 2>/dev/null)
echo "$env_vars"
}