docker-library / postgres

Docker Official Image packaging for Postgres
http://www.postgresql.org
MIT License
2.16k stars 1.13k forks source link

Export `docker_process_sql` for availability in executed initdb bash #1117

Closed scop closed 8 months ago

scop commented 1 year ago

This way, executed bash initdb scripts do not need to source the entrypoint script (nor hardcode its path) to be able to use the function.

Note that the export only works for executed bash scripts.

Not crucial by any means, but I think it'd be nice to have.

Could apply to < 16 entrypoints too, if this is seen desirable.

tianon commented 9 months ago

:eyes:

https://github.com/docker-library/postgres/blob/f85674ce472bc78b8b8a0478dacd595e44cb9616/docker-entrypoint.sh#L166-L174

(If you remove the excitability bit on your initdb scripts, they'll be sourced instead and have direct access.)

scop commented 8 months ago

(If you remove the excitability bit on your initdb scripts, they'll be sourced instead and have direct access.)

I know, but the executability check is unreliable, and doing that causes other problems: https://github.com/docker-library/postgres/issues/1108

A reliable workaround against that is to make all .sh scripts executable, which then leads to this issue. Could you reconsider reopening/applying this?

tianon commented 8 months ago

If you need to work around #1108 too, I'd suggest something like this:

if ! command -v docker_process_sql > /dev/null; then
    source /usr/local/bin/docker-entrypoint.sh
fi

...

(the script is officially intended to be sourced in this way, and that is the canonical supported path for doing so)