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 # Loop through each environment variable
while IFS= read -r env_var; do while IFS= read -r env_var; do
# Split into name and value parts based on '=' # Split into name and value parts based on '='
var_name="${env_var%%=*}" # Variable name var_name="${env_var%%:*}" # Variable name (split by colon for YAML)
var_value="${env_var#*=}" # Variable value 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} # Handle variables without existing braces (not previously processed)
if [[ "$var_value" == *'${'*':'*'}'* ]]; then if [[ "$var_value" != *'${'* ]]; then
# Extract the variable inside the ${} braces modified_var="${var_name}: \${${APP_NAME}_${var_name}:-${var_value}}"
else
# Handle variables already having ${} and possible default
ref_var="${var_value#\$\{}" ref_var="${var_value#\$\{}"
ref_var="${ref_var%%[:-]*}" ref_var="${ref_var%%[:-]*}"
@@ -23,20 +25,11 @@ process_env_vars() {
# Check if the reference variable already contains APP_NAME_ prefix # Check if the reference variable already contains APP_NAME_ prefix
if [[ "$ref_var" == ${APP_NAME}_* ]]; then if [[ "$ref_var" == ${APP_NAME}_* ]]; then
# If it already contains the prefix, use it as is # Use the reference variable as is if it already contains the prefix
modified_var="${var_name}=\${${ref_var}:-${default_value}}" modified_var="${var_name}: \${${ref_var}:-${default_value}}"
else else
# If not, add the APP_NAME_ prefix # Add APP_NAME_ prefix to reference variable
modified_var="${var_name}=\${${APP_NAME}_${ref_var}:-${default_value}}" 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}}"
fi fi
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 # Generate Docker Compose content and save it to a variable
BLDR_NEW_DCF=$(cat <<EOF BLDR_NEW_DCF=$(cat <<EOF
version: '3.4' version: '3.8'
services: services:
stash: $BLDR_APP:
image: $BLDR_IMAGE_VAR image: $BLDR_IMAGE_VAR
restart: unless-stopped restart: unless-stopped
environment: environment:
-2
View File
@@ -1,11 +1,9 @@
#!/bin/bash #!/bin/bash
# List all directories in the current directory that don't start with an underscore # 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) directories=$(find . -maxdepth 1 -type d -not -name '_*' -exec basename {} \; | grep -v '[_\.]' | sort -r)
# Use fzf to allow the user to select a directory # Use fzf to allow the user to select a directory
selected_dir
selected_dir=$(echo "$directories" | fzf --prompt="Select a directory: ") selected_dir=$(echo "$directories" | fzf --prompt="Select a directory: ")
# Check if a directory was selected # Check if a directory was selected
+2 -2
View File
@@ -15,8 +15,8 @@ get_env_vars() {
local compose_content="$1" local compose_content="$1"
local env_vars="" local env_vars=""
# Use yq to extract environment variables from services # Use yq to extract the environment variables in 'key: value' format
env_vars=$(echo "$compose_content" | yq eval '.services.*.environment[]' - 2>/dev/null) env_vars=$(echo "$compose_content" | yq eval '.services.*.environment | to_entries | .[] | "\(.key): \(.value)"' - 2>/dev/null)
echo "$env_vars" echo "$env_vars"
} }
+1
View File
@@ -1,6 +1,7 @@
# Mariadb # Mariadb
Dockerhub: https://hub.docker.com/_/mariadb Dockerhub: https://hub.docker.com/_/mariadb
Proxy Port: 3306
It will be quite uncommon to just use this compose file, it's likely you are extending this from another project. It will be quite uncommon to just use this compose file, it's likely you are extending this from another project.
That's the main context of this container. That's the main context of this container.
+6 -10
View File
@@ -1,17 +1,13 @@
version: '3.8' # or any version you prefer version: '3.8'
services: services:
mariadb: mariadb:
image: ${MARIADB_IMAGE:-mariadb:latest} image: ${MARIADB_IMAGE:-mariadb:latest}
restart: unless-stopped
environment: environment:
MARIADB_ROOT_PASSWORD: ${MARIADB_ROOT_PASSWORD:-ChangeThisPassword} - MARIADB_DATABASE: ${MARIADB_MARIADB_DATABASE:-mydb}
MARIADB_DATABASE: ${MARIADB_DATABASE:-mydb} - MARIADB_PASSWORD: ${MARIADB_MARIADB_PASSWORD:-AlsoChangeThisPassword}
MARIADB_USER: ${MARIADB_USER:-dbuser} - MARIADB_ROOT_PASSWORD: ${MARIADB_MARIADB_ROOT_PASSWORD:-ChangeThisPassword}
MARIADB_PASSWORD: ${MARIADB_PASSWORD:-AlsoChangeThisPassword} - MARIADB_USER: ${MARIADB_MARIADB_USER:-dbuser}
volumes: volumes:
- ${VOL_PATH:-./data/}mariadb_data:/var/lib/mysql - ${VOL_PATH:-./data/}mariadb_data:/var/lib/mysql
ports:
- "3306:3306"
networks:
- mariadb_network
+4 -4
View File
@@ -1,7 +1,7 @@
version: '3.4' version: '3.4'
services: services:
mariadb: mariadb:
extends: extends:
file: ${COOKBOOK}/mariadb/docker-compose.yml file: ${COOKBOOK}/mariadb/docker-compose.yml
service: mariadb service: mariadb
+8 -8
View File
@@ -1,9 +1,9 @@
# Mariadb
PRODDIR=/var/www/stashdomain-com/ #HELP: project_path COOKBOOK=/git/docker-compose-cookbooks #HELP: cookbooks
COOKBOOK=/home/user/git/docker-compose-cookbooks #HELP: cookbooks # mariadb
VOL_PATH=/project-dir/project-name/data #HELP: volpath
MARIADB_IMAGE=mariadb:latest MARIADB_IMAGE=mariadb:latest
MARIADB_ROOT_PASSWORD=ChangeThisPassword #HELP: gen32 MARIADB_MARIADB_DATABASE=mydb
MARIADB_DATABASE=mydb MARIADB_MARIADB_PASSWORD=AlsoChangeThisPassword #HELP: gen32
MARIADB_USER=dbuser MARIADB_MARIADB_ROOT_PASSWORD=ChangeThisPassword #HELP: gen32
MARIADB_PASSWORD=AlsoChangeThisPassword #HELP: gen32 MARIADB_MARIADB_USER=dbuser
VOL_PATH=./data/ #HELP: volpath