Skip to content

Commit

Permalink
feat(mariadb): Add support for reading password from file
Browse files Browse the repository at this point in the history
Signed-off-by: Riddhi Gupta <[email protected]>
  • Loading branch information
riddhig-coder committed Jul 17, 2024
1 parent dfc5fdc commit 11e0e29
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions runmariadb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 11e0e29

Please sign in to comment.