Skip to content

Don't pollute output when testing Postgres connection #33

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

Closed
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
2 changes: 1 addition & 1 deletion api/.env
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TRUSTED_HOSTS=localhost,api
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Configure your db driver and server_version in config/packages/doctrine.yaml
DATABASE_URL=pgsql://api-platform:!ChangeMe!@db/api
DATABASE_URL=postgres://api-platform:!ChangeMe!@db/api
###< doctrine/doctrine-bundle ###

###> nelmio/cors-bundle ###
Expand Down
2 changes: 1 addition & 1 deletion api/.env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ TRUSTED_HOSTS=localhost,api
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Configure your db driver and server_version in config/packages/doctrine.yaml
DATABASE_URL=pgsql://api-platform:!ChangeMe!@db/api
DATABASE_URL=postgres://api-platform:!ChangeMe!@db/api
###< doctrine/doctrine-bundle ###

###> nelmio/cors-bundle ###
Expand Down
2 changes: 1 addition & 1 deletion api/docker/php/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ if [ "$1" = 'php-fpm' ] || [ "$1" = 'bin/console' ]; then
if [ "$APP_ENV" != 'prod' ]; then
composer install --prefer-dist --no-progress --no-suggest --no-interaction
>&2 echo "Waiting for Postgres to be ready..."
until bin/console doctrine:query:sql "SELECT 1" --quiet; do
until pg_isready --timeout=0 --dbname="${DATABASE_URL}"; do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if we prefer using a Postgres database for performances reasons, this command definitively connects this entrypoint to the database system & driver. I don't find it very useful, especially if the final user wants to use a different system.
WDYT @dunglas?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a better way. Thanks to the Sylius peeps who used it: https://github.com/Sylius/Sylius-Standard/blob/943125142f0267ac49903efeaab85e24de08424d/docker/php/docker-entrypoint.sh#L20-L23

Let's adopt the same method as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems the same, but what is the purpose of using >/dev/null 2>&1 instead of --quiet?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used this Doctrine command long ago, but I can't remember why we switched. pg_isready looks more reliable anyway.

Even if we prefer using a Postgres database for performances reasons, this command definitively connects this entrypoint to the database system & driver. I don't find it very useful, especially if the final user wants to use a different system.

It's the same for the PDO driver and so on. The entrypoint is part of the infrastructure, to me it's ok and intended to couple it with the services we use.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, please update api-platform/api-platform first, and the demo after by copying it.

sleep 1
done
bin/console doctrine:schema:update --force --no-interaction
Expand Down