Skip to content

Commit

Permalink
Merge branch 'mariadb-vars' into 'master'
Browse files Browse the repository at this point in the history
Uses `eval` to handle variable indirection instead of `${!var}` syntax.

See merge request docker/alpine-mariadb!30
  • Loading branch information
dominictayloruk committed Aug 29, 2024
2 parents 717ef92 + 32386e6 commit e206b79
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 51 deletions.
34 changes: 17 additions & 17 deletions alpine-mariadb-aarch64/files/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@ read_secret() {

# Set MYSQL_ variables based on MARIADB_ variables or secrets if MYSQL_ is not set
for var in ROOT_PASSWORD DATABASE USER PASSWORD CHARSET COLLATION; do
mysql_var="MYSQL_${var}"
mariadb_var="MARIADB_${var}"
eval mysql_var="\$MYSQL_${var}"
eval mariadb_var="\$MARIADB_${var}"

# Check environment variables
if [ -z "${!mysql_var}" ] && [ -n "${!mariadb_var}" ]; then
export "$mysql_var"="${!mariadb_var}"
if [ -z "$mysql_var" ] && [ -n "$mariadb_var" ]; then
eval "export MYSQL_${var}=\$mariadb_var"
fi

# Check secrets
mysql_secret="/run/secrets/mysql_${var,,}"
mariadb_secret="/run/secrets/mariadb_${var,,}"
mysql_secret="/run/secrets/mysql_$(echo $var | tr '[:upper:]' '[:lower:]')"
mariadb_secret="/run/secrets/mariadb_$(echo $var | tr '[:upper:]' '[:lower:]')"

if [ -z "${!mysql_var}" ] && [ -f "$mariadb_secret" ]; then
export "$mysql_var"=$(read_secret "$mariadb_secret")
elif [ -z "${!mysql_var}" ] && [ -f "$mysql_secret" ]; then
export "$mysql_var"=$(read_secret "$mysql_secret")
if [ -z "$mysql_var" ] && [ -f "$mariadb_secret" ]; then
eval "export MYSQL_${var}=$(read_secret "$mariadb_secret")"
elif [ -z "$mysql_var" ] && [ -f "$mysql_secret" ]; then
eval "export MYSQL_${var}=$(read_secret "$mysql_secret")"
fi
done

# Handle *_FILE variables
for var in ROOT_PASSWORD DATABASE USER PASSWORD; do
mysql_var="MYSQL_${var}"
mysql_file_var="MYSQL_${var}_FILE"
mariadb_file_var="MARIADB_${var}_FILE"
eval mysql_var="\$MYSQL_${var}"
eval mysql_file_var="\$MYSQL_${var}_FILE"
eval mariadb_file_var="\$MARIADB_${var}_FILE"

if [ -z "${!mysql_var}" ] && [ -n "${!mysql_file_var}" ]; then
export "$mysql_var"=$(read_secret "${!mysql_file_var}")
elif [ -z "${!mysql_var}" ] && [ -n "${!mariadb_file_var}" ]; then
export "$mysql_var"=$(read_secret "${!mariadb_file_var}")
if [ -z "$mysql_var" ] && [ -n "$mysql_file_var" ]; then
eval "export MYSQL_${var}=$(read_secret "$mysql_file_var")"
elif [ -z "$mysql_var" ] && [ -n "$mariadb_file_var" ]; then
eval "export MYSQL_${var}=$(read_secret "$mariadb_file_var")"
fi
done

Expand Down
34 changes: 17 additions & 17 deletions alpine-mariadb-amd64/files/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@ read_secret() {

# Set MYSQL_ variables based on MARIADB_ variables or secrets if MYSQL_ is not set
for var in ROOT_PASSWORD DATABASE USER PASSWORD CHARSET COLLATION; do
mysql_var="MYSQL_${var}"
mariadb_var="MARIADB_${var}"
eval mysql_var="\$MYSQL_${var}"
eval mariadb_var="\$MARIADB_${var}"

# Check environment variables
if [ -z "${!mysql_var}" ] && [ -n "${!mariadb_var}" ]; then
export "$mysql_var"="${!mariadb_var}"
if [ -z "$mysql_var" ] && [ -n "$mariadb_var" ]; then
eval "export MYSQL_${var}=\$mariadb_var"
fi

# Check secrets
mysql_secret="/run/secrets/mysql_${var,,}"
mariadb_secret="/run/secrets/mariadb_${var,,}"
mysql_secret="/run/secrets/mysql_$(echo $var | tr '[:upper:]' '[:lower:]')"
mariadb_secret="/run/secrets/mariadb_$(echo $var | tr '[:upper:]' '[:lower:]')"

if [ -z "${!mysql_var}" ] && [ -f "$mariadb_secret" ]; then
export "$mysql_var"=$(read_secret "$mariadb_secret")
elif [ -z "${!mysql_var}" ] && [ -f "$mysql_secret" ]; then
export "$mysql_var"=$(read_secret "$mysql_secret")
if [ -z "$mysql_var" ] && [ -f "$mariadb_secret" ]; then
eval "export MYSQL_${var}=$(read_secret "$mariadb_secret")"
elif [ -z "$mysql_var" ] && [ -f "$mysql_secret" ]; then
eval "export MYSQL_${var}=$(read_secret "$mysql_secret")"
fi
done

# Handle *_FILE variables
for var in ROOT_PASSWORD DATABASE USER PASSWORD; do
mysql_var="MYSQL_${var}"
mysql_file_var="MYSQL_${var}_FILE"
mariadb_file_var="MARIADB_${var}_FILE"
eval mysql_var="\$MYSQL_${var}"
eval mysql_file_var="\$MYSQL_${var}_FILE"
eval mariadb_file_var="\$MARIADB_${var}_FILE"

if [ -z "${!mysql_var}" ] && [ -n "${!mysql_file_var}" ]; then
export "$mysql_var"=$(read_secret "${!mysql_file_var}")
elif [ -z "${!mysql_var}" ] && [ -n "${!mariadb_file_var}" ]; then
export "$mysql_var"=$(read_secret "${!mariadb_file_var}")
if [ -z "$mysql_var" ] && [ -n "$mysql_file_var" ]; then
eval "export MYSQL_${var}=$(read_secret "$mysql_file_var")"
elif [ -z "$mysql_var" ] && [ -n "$mariadb_file_var" ]; then
eval "export MYSQL_${var}=$(read_secret "$mariadb_file_var")"
fi
done

Expand Down
34 changes: 17 additions & 17 deletions alpine-mariadb-armhf/files/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,35 @@ read_secret() {

# Set MYSQL_ variables based on MARIADB_ variables or secrets if MYSQL_ is not set
for var in ROOT_PASSWORD DATABASE USER PASSWORD CHARSET COLLATION; do
mysql_var="MYSQL_${var}"
mariadb_var="MARIADB_${var}"
eval mysql_var="\$MYSQL_${var}"
eval mariadb_var="\$MARIADB_${var}"

# Check environment variables
if [ -z "${!mysql_var}" ] && [ -n "${!mariadb_var}" ]; then
export "$mysql_var"="${!mariadb_var}"
if [ -z "$mysql_var" ] && [ -n "$mariadb_var" ]; then
eval "export MYSQL_${var}=\$mariadb_var"
fi

# Check secrets
mysql_secret="/run/secrets/mysql_${var,,}"
mariadb_secret="/run/secrets/mariadb_${var,,}"
mysql_secret="/run/secrets/mysql_$(echo $var | tr '[:upper:]' '[:lower:]')"
mariadb_secret="/run/secrets/mariadb_$(echo $var | tr '[:upper:]' '[:lower:]')"

if [ -z "${!mysql_var}" ] && [ -f "$mariadb_secret" ]; then
export "$mysql_var"=$(read_secret "$mariadb_secret")
elif [ -z "${!mysql_var}" ] && [ -f "$mysql_secret" ]; then
export "$mysql_var"=$(read_secret "$mysql_secret")
if [ -z "$mysql_var" ] && [ -f "$mariadb_secret" ]; then
eval "export MYSQL_${var}=$(read_secret "$mariadb_secret")"
elif [ -z "$mysql_var" ] && [ -f "$mysql_secret" ]; then
eval "export MYSQL_${var}=$(read_secret "$mysql_secret")"
fi
done

# Handle *_FILE variables
for var in ROOT_PASSWORD DATABASE USER PASSWORD; do
mysql_var="MYSQL_${var}"
mysql_file_var="MYSQL_${var}_FILE"
mariadb_file_var="MARIADB_${var}_FILE"
eval mysql_var="\$MYSQL_${var}"
eval mysql_file_var="\$MYSQL_${var}_FILE"
eval mariadb_file_var="\$MARIADB_${var}_FILE"

if [ -z "${!mysql_var}" ] && [ -n "${!mysql_file_var}" ]; then
export "$mysql_var"=$(read_secret "${!mysql_file_var}")
elif [ -z "${!mysql_var}" ] && [ -n "${!mariadb_file_var}" ]; then
export "$mysql_var"=$(read_secret "${!mariadb_file_var}")
if [ -z "$mysql_var" ] && [ -n "$mysql_file_var" ]; then
eval "export MYSQL_${var}=$(read_secret "$mysql_file_var")"
elif [ -z "$mysql_var" ] && [ -n "$mariadb_file_var" ]; then
eval "export MYSQL_${var}=$(read_secret "$mariadb_file_var")"
fi
done

Expand Down

0 comments on commit e206b79

Please sign in to comment.