glanceapp / glance

A self-hosted dashboard that puts all your feeds in one place
GNU Affero General Public License v3.0
8.56k stars 297 forks source link

feat: HEALTHCHECK in Dockerfile #242

Open CremaLuca opened 1 month ago

CremaLuca commented 1 month ago

In commit 9a36187 the /api/healthz was added to resolve issue #226; I used this feature to use the Docker health check functionality.

There should be two ways to do it:

  1. Add --health-cmd to docker run or healthcheck to docker-compose file
  2. Add it to the Dockerfile so it is enabled by default

I went for the second option as you can change the details of the healtz endpoint without having to change every user's configuration.

I set the timeout, start-period and interval arbitrarily, can be changed as you like.

Example

The healthcheck works even if external port is changed, I tested mine with port 8045.

As the container is starting the status is "starting"

IMAGE                              COMMAND                  CREATED         STATUS                             PORTS                                                     
cremaluca/glance:0.0.1             "/app/glance"            4 seconds ago   Up 3 seconds (health: starting)    0.0.0.0:8045->8080/tcp, [::]:8045->8080/tcp

But after a few seconds it has already changed to healthy

IMAGE                              COMMAND                  CREATED         STATUS                            PORTS                                                        
cremaluca/glance:0.0.1             "/app/glance"            9 seconds ago   Up 8 seconds (healthy)            0.0.0.0:8045->8080/tcp, [::]:8045->8080/tcp