Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for database update scripts. #673

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 25 additions & 10 deletions 10/alpine/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,21 @@ docker_temp_server_stop() {
pg_ctl -D "$PGDATA" -m fast -w stop
}

# run stdin lines as individual commands, while a temp server is started
docker_run_with_temp_server() {
# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}"
docker_temp_server_start "$@"

while read command; do
${command}
done

docker_temp_server_stop
unset PGPASSWORD
}

# check arguments for an option that would cause postgres to stop
# return true if there is one
_pg_want_help() {
Expand Down Expand Up @@ -267,16 +282,10 @@ _main() {
docker_init_database_dir
pg_setup_hba_conf

# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}"
docker_temp_server_start "$@"

docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/*

docker_temp_server_stop
unset PGPASSWORD
docker_run_with_temp_server <<-'COMMANDS'
docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/*
COMMANDS

echo
echo 'PostgreSQL init process complete; ready for start up.'
Expand All @@ -285,6 +294,12 @@ _main() {
echo
echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization'
echo

if [ -d /docker-entrypoint-updatedb.d/ ]; then
docker_run_with_temp_server <<-'COMMANDS'
docker_process_init_files /docker-entrypoint-updatedb.d/*
COMMANDS
fi
fi
fi

Expand Down
35 changes: 25 additions & 10 deletions 10/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,21 @@ docker_temp_server_stop() {
pg_ctl -D "$PGDATA" -m fast -w stop
}

# run stdin lines as individual commands, while a temp server is started
docker_run_with_temp_server() {
# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}"
docker_temp_server_start "$@"

while read command; do
${command}
done

docker_temp_server_stop
unset PGPASSWORD
}

# check arguments for an option that would cause postgres to stop
# return true if there is one
_pg_want_help() {
Expand Down Expand Up @@ -267,16 +282,10 @@ _main() {
docker_init_database_dir
pg_setup_hba_conf

# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}"
docker_temp_server_start "$@"

docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/*

docker_temp_server_stop
unset PGPASSWORD
docker_run_with_temp_server <<-'COMMANDS'
docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/*
COMMANDS

echo
echo 'PostgreSQL init process complete; ready for start up.'
Expand All @@ -285,6 +294,12 @@ _main() {
echo
echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization'
echo

if [ -d /docker-entrypoint-updatedb.d/ ]; then
docker_run_with_temp_server <<-'COMMANDS'
docker_process_init_files /docker-entrypoint-updatedb.d/*
COMMANDS
fi
fi
fi

Expand Down
35 changes: 25 additions & 10 deletions 11/alpine/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,21 @@ docker_temp_server_stop() {
pg_ctl -D "$PGDATA" -m fast -w stop
}

# run stdin lines as individual commands, while a temp server is started
docker_run_with_temp_server() {
# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}"
docker_temp_server_start "$@"

while read command; do
${command}
done

docker_temp_server_stop
unset PGPASSWORD
}

# check arguments for an option that would cause postgres to stop
# return true if there is one
_pg_want_help() {
Expand Down Expand Up @@ -267,16 +282,10 @@ _main() {
docker_init_database_dir
pg_setup_hba_conf

# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}"
docker_temp_server_start "$@"

docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/*

docker_temp_server_stop
unset PGPASSWORD
docker_run_with_temp_server <<-'COMMANDS'
docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/*
COMMANDS

echo
echo 'PostgreSQL init process complete; ready for start up.'
Expand All @@ -285,6 +294,12 @@ _main() {
echo
echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization'
echo

if [ -d /docker-entrypoint-updatedb.d/ ]; then
docker_run_with_temp_server <<-'COMMANDS'
docker_process_init_files /docker-entrypoint-updatedb.d/*
COMMANDS
fi
fi
fi

Expand Down
35 changes: 25 additions & 10 deletions 11/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,21 @@ docker_temp_server_stop() {
pg_ctl -D "$PGDATA" -m fast -w stop
}

# run stdin lines as individual commands, while a temp server is started
docker_run_with_temp_server() {
# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}"
docker_temp_server_start "$@"

while read command; do
${command}
done

docker_temp_server_stop
unset PGPASSWORD
}

# check arguments for an option that would cause postgres to stop
# return true if there is one
_pg_want_help() {
Expand Down Expand Up @@ -267,16 +282,10 @@ _main() {
docker_init_database_dir
pg_setup_hba_conf

# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}"
docker_temp_server_start "$@"

docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/*

docker_temp_server_stop
unset PGPASSWORD
docker_run_with_temp_server <<-'COMMANDS'
docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/*
COMMANDS

echo
echo 'PostgreSQL init process complete; ready for start up.'
Expand All @@ -285,6 +294,12 @@ _main() {
echo
echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization'
echo

if [ -d /docker-entrypoint-updatedb.d/ ]; then
docker_run_with_temp_server <<-'COMMANDS'
docker_process_init_files /docker-entrypoint-updatedb.d/*
COMMANDS
fi
fi
fi

Expand Down
35 changes: 25 additions & 10 deletions 12/alpine/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,21 @@ docker_temp_server_stop() {
pg_ctl -D "$PGDATA" -m fast -w stop
}

# run stdin lines as individual commands, while a temp server is started
docker_run_with_temp_server() {
# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}"
docker_temp_server_start "$@"

while read command; do
${command}
done

docker_temp_server_stop
unset PGPASSWORD
}

# check arguments for an option that would cause postgres to stop
# return true if there is one
_pg_want_help() {
Expand Down Expand Up @@ -267,16 +282,10 @@ _main() {
docker_init_database_dir
pg_setup_hba_conf

# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}"
docker_temp_server_start "$@"

docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/*

docker_temp_server_stop
unset PGPASSWORD
docker_run_with_temp_server <<-'COMMANDS'
docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/*
COMMANDS

echo
echo 'PostgreSQL init process complete; ready for start up.'
Expand All @@ -285,6 +294,12 @@ _main() {
echo
echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization'
echo

if [ -d /docker-entrypoint-updatedb.d/ ]; then
docker_run_with_temp_server <<-'COMMANDS'
docker_process_init_files /docker-entrypoint-updatedb.d/*
COMMANDS
fi
fi
fi

Expand Down
35 changes: 25 additions & 10 deletions 12/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,21 @@ docker_temp_server_stop() {
pg_ctl -D "$PGDATA" -m fast -w stop
}

# run stdin lines as individual commands, while a temp server is started
docker_run_with_temp_server() {
# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}"
docker_temp_server_start "$@"

while read command; do
${command}
done

docker_temp_server_stop
unset PGPASSWORD
}

# check arguments for an option that would cause postgres to stop
# return true if there is one
_pg_want_help() {
Expand Down Expand Up @@ -267,16 +282,10 @@ _main() {
docker_init_database_dir
pg_setup_hba_conf

# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}"
docker_temp_server_start "$@"

docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/*

docker_temp_server_stop
unset PGPASSWORD
docker_run_with_temp_server <<-'COMMANDS'
docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/*
COMMANDS

echo
echo 'PostgreSQL init process complete; ready for start up.'
Expand All @@ -285,6 +294,12 @@ _main() {
echo
echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization'
echo

if [ -d /docker-entrypoint-updatedb.d/ ]; then
docker_run_with_temp_server <<-'COMMANDS'
docker_process_init_files /docker-entrypoint-updatedb.d/*
COMMANDS
fi
fi
fi

Expand Down
35 changes: 25 additions & 10 deletions 9.4/alpine/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,21 @@ docker_temp_server_stop() {
pg_ctl -D "$PGDATA" -m fast -w stop
}

# run stdin lines as individual commands, while a temp server is started
docker_run_with_temp_server() {
# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}"
docker_temp_server_start "$@"

while read command; do
${command}
done

docker_temp_server_stop
unset PGPASSWORD
}

# check arguments for an option that would cause postgres to stop
# return true if there is one
_pg_want_help() {
Expand Down Expand Up @@ -267,16 +282,10 @@ _main() {
docker_init_database_dir
pg_setup_hba_conf

# PGPASSWORD is required for psql when authentication is required for 'local' connections via pg_hba.conf and is otherwise harmless
# e.g. when '--auth=md5' or '--auth-local=md5' is used in POSTGRES_INITDB_ARGS
export PGPASSWORD="${PGPASSWORD:-$POSTGRES_PASSWORD}"
docker_temp_server_start "$@"

docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/*

docker_temp_server_stop
unset PGPASSWORD
docker_run_with_temp_server <<-'COMMANDS'
docker_setup_db
docker_process_init_files /docker-entrypoint-initdb.d/* /docker-entrypoint-updatedb.d/*
COMMANDS

echo
echo 'PostgreSQL init process complete; ready for start up.'
Expand All @@ -285,6 +294,12 @@ _main() {
echo
echo 'PostgreSQL Database directory appears to contain a database; Skipping initialization'
echo

if [ -d /docker-entrypoint-updatedb.d/ ]; then
docker_run_with_temp_server <<-'COMMANDS'
docker_process_init_files /docker-entrypoint-updatedb.d/*
COMMANDS
fi
fi
fi

Expand Down
Loading