Skip to content

development: Use native healthchecks in Docker compose#1257

Open
eulerbutcooler wants to merge 3 commits intometabrainz:masterfrom
eulerbutcooler:update-docker-compose
Open

development: Use native healthchecks in Docker compose#1257
eulerbutcooler wants to merge 3 commits intometabrainz:masterfrom
eulerbutcooler:update-docker-compose

Conversation

@eulerbutcooler
Copy link
Copy Markdown
Contributor

@eulerbutcooler eulerbutcooler commented Mar 7, 2026

Problem

Docker compose used external image (waisbrot/wait) to delay startup until postgres, elasticsearch and redis were ready. This is an outdated method of doing this.

Solution

I've updated the docker compose to use the docker native health check commands for all three postgres, elasticsearch and redis services.

Areas of Impact

This makes the docker compose file more maintainable.

TESTING

  • I have run the code and manually tested the changes

AI usage

  • I have used AI in this PR (add more details below)
  • I understand all the changes made in this PR

@eulerbutcooler
Copy link
Copy Markdown
Contributor Author

@MonkeyDo do lemme know if any changes are needed

@faizanakhtar123
Copy link
Copy Markdown
Contributor

Hi @eulerbutcooler Thank you for opening this PR.... Please fill in the "AI usage" section in the PR template, it is there for a reason...

@eulerbutcooler
Copy link
Copy Markdown
Contributor Author

Hi @eulerbutcooler Thank you for opening this PR.... Please fill in the "AI usage" section in the PR template, it is there for a reason...

I don't think I used AI in this one tho

@faizanakhtar123
Copy link
Copy Markdown
Contributor

@eulerbutcooler If no AI was used in this submission, simply uncheck the AI usage box in the template. Furthermore, please ensure you use the new, mandatory PR template for your next contributions... You can refer to my PR #1248 to see how it should be properly filled out... : )

@eulerbutcooler
Copy link
Copy Markdown
Contributor Author

@eulerbutcooler If no AI was used in this submission, simply uncheck the AI usage box in the template. Furthermore, please ensure you use the new, mandatory PR template for your next contributions... You can refer to my PR #1248 to see how it should be properly filled out... : )

Ah alright. The PR still shows the old template. Will use the new one in the next PRs. Will update this one. Thanks for the heads up

@faizanakhtar123
Copy link
Copy Markdown
Contributor

@eulerbutcooler For better understanding - metabrainz/listenbrainz-server#3610

@eulerbutcooler
Copy link
Copy Markdown
Contributor Author

@eulerbutcooler For better understanding - metabrainz/listenbrainz-server#3610

ive updated the PR comment, is it fine now?

@faizanakhtar123
Copy link
Copy Markdown
Contributor

@eulerbutcooler Nice !! Please update all your open PRs according to this template

@MonkeyDo
Copy link
Copy Markdown
Member

MonkeyDo commented Mar 9, 2026

@eulerbutcooler Thanks for the PR, that's a much better way to do it, as you mentioned this was outdated.

@faizanakhtar123 I appreciate the assist, but in this case I am at faults, not having changed the PR template for the BookBrainz repo.
On it now.

Copy link
Copy Markdown
Member

@MonkeyDo MonkeyDo left a comment

Choose a reason for hiding this comment

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

Nice, good improvement thank you!
I tested locally, working fine.

You need to apply the same changes to the API docker files (docker-compose.api.yml and develop-api.sh)

As mentioned below, please also test setting up the repo from scratch and report your results

Comment thread docker-compose.yml
volumes:
- postgres-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "pg_isready -U bookbrainz -d bookbrainz"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

question: will this health check fail if you do not have the BB database set up (i.e. your very first setup run)?

If you haven't yet, it would be good to test a setup from scratch using this dockerfile to ensure we're not breaking anything.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hey! went through the postgres docs and some stackoverflow posts and no it wont fail if we don't have the BB database already set up. It only checks if the postgres server is responsive or not.

Considering this I've updated the query to psql -U bookbrainz -d bookbrainz SELECT 1 - this ensures the database exists.

And yes I've tested out locally setting up the repo from scratch using the dockerfile and had no issues.

I've added the requested changes in the upcoming commit.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@MonkeyDo let me know if any other changes are needed. Thanks!

@MonkeyDo
Copy link
Copy Markdown
Member

@faizanakhtar123 if someone didn't use the new template, you assume they are using AI?

Let's not pour oil on the fire.
Faizan made a mistake in requesting the PR template be filled in this repo (as I had not yet updated the template) and was a bit overzealous.
That being said, he's not particularly wrong, and the AI disclosure was missing in the template.

Now that it has been updated, as a maintainer, I would answer yes: if someone did not fill in the new template, I would expect they used AI and didn't even bother to fill the PR description themselves.

…eck method for postgres in docker-compose.yml and docker-compose.api.yml
Copy link
Copy Markdown
Member

@MonkeyDo MonkeyDo left a comment

Choose a reason for hiding this comment

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

Thanks, a good improvement and one less dependency!

@MonkeyDo MonkeyDo changed the title Update: Docker compose - native healthchecks development: Use native healthchecks in Docker compose Apr 13, 2026
Comment thread docker-compose.yml Outdated
volumes:
- postgres-data:/var/lib/postgresql/data
healthcheck:
test: ["CMD-SHELL", "psql -U $$POSTGRES_USER -d $$POSTGRES_DB -c 'SELECT 1'"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I spoke too soon :)

I tested this with no database, and the healthcheck passed even without a database.
Not sure exactly how you tested this, but probably not thoroughly enough in any case.

I think it's because POSTGRES_DB isn't necessarily defined and the default value results in a valid healthcheck.

At this moment I don't think we want to force checking for the bookbrainz database, so we should revert this check to the previous simpler one using pg_isready, for both files.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Hey @MonkeyDo I've reverted it back to pg_isready.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants