From 11e0e299d7cd8672fe03a4552a5682b132b85799 Mon Sep 17 00:00:00 2001 From: Riddhi Gupta Date: Wed, 17 Jul 2024 13:20:45 +0530 Subject: [PATCH] feat(mariadb): Add support for reading password from file Signed-off-by: Riddhi Gupta --- runmariadb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/runmariadb b/runmariadb index cf57945..d213e17 100755 --- a/runmariadb +++ b/runmariadb @@ -2,9 +2,19 @@ set -eu -if [[ -z "${MARIADB_PASSWORD:-}" ]]; then - echo "FATAL: Missing database password, set the MARIADB_PASSWORD variable" - exit 1 +PASSWORD_FILE="/run/secrets/mariadb-password" # Specify the password file location + +if [ -f "$PASSWORD_FILE" ]; then + # Password file exists, read from it + MARIADB_PASSWORD=$(cat "$PASSWORD_FILE") + echo "Using password from file" +elif [ -n "$MARIADB_PASSWORD" ]; then + # Password file doesn't exist, but environment variable is set, use it + echo "Using MARIADB_PASSWORD from environment variable" +else + # Neither file nor environment variable exists, handle the error + echo "FATAL: MARIADB_PASSWORD not found in file or environment variable" + exit 1 fi set -x