Replace password with file

This commit is contained in:
Pierre HUBERT 2024-12-06 13:10:24 +01:00
parent 39956fe2d6
commit f37c1d2c44

View File

@ -5,23 +5,19 @@ DB_PATH=/db
OLD_DB_PATH=/tmp/old_db OLD_DB_PATH=/tmp/old_db
NEW_DB_PATH=/tmp/new_db NEW_DB_PATH=/tmp/new_db
DB_PWD_FILE=/tmp/db_pwd_file
# Handle password # Handle password
if [ -z "$POSTGRES_PASSWORD" ] || [ "$POSTGRES_PASSWORD" == " " ]; if [ -z "$POSTGRES_PASSWORD" ] || [ "$POSTGRES_PASSWORD" == " " ];
then then
echo "Please specify database password in POSTGRES_PASSWORD env variable!" echo "Please specify database password in POSTGRES_PASSWORD env variable!"
exit 1; exit 1;
fi fi
echo "$POSTGRES_PASSWORD" > "$DB_PWD_FILE"
truncate -s -1 "$DB_PWD_FILE"
# Run database on a COPY of the database # Run database on a COPY of the database
cp -r "$DB_PATH" "$OLD_DB_PATH" cp -r "$DB_PATH" "$OLD_DB_PATH"
# Initialize NEW database # Initialize NEW database
mkdir "$NEW_DB_PATH" mkdir "$NEW_DB_PATH"
/postgres/17/bin/initdb -D "$NEW_DB_PATH" --username "$POSTGRES_USER" --pwfile="$DB_PWD_FILE" || exit 1 /postgres/17/bin/initdb -D "$NEW_DB_PATH" --username "$POSTGRES_USER" --pwfile=<(printf "%s\n" "$POSTGRES_PASSWORD") || exit 1
# Perform migration # Perform migration