sameersbn / docker-redmine

Docker Image for Redmine
http://www.damagehead.com/docker-redmine/
MIT License
1.27k stars 497 forks source link

Healthcheck feature #564

Open delanym opened 2 months ago

delanym commented 2 months ago

How about creating a healthcheck?

I'd like my proxy to wait until redmine container is ready before starting.

jcormier commented 2 months ago

Any suggestions would be appreciated.

delanym commented 2 months ago

A default healthcheck was added in Rails 7.1 https://guides.rubyonrails.org/action_controller_overview.html#built-in-health-check-endpoint

Which will be available in Redmine 6 https://www.redmine.org/issues/36320

So until then one would need to create a custom healthcheck as described in https://blog.saeloun.com/2023/02/27/rails-introduces-default-health-check-controller/

delanym commented 2 months ago

Dockerfile:

COPY routes.rb /usr/src/redmine/config/
COPY health_check_controller.rb /usr/src/redmine/app/controllers/
COPY healthcheck.sh /usr/src/redmine/
RUN chmod +x /usr/src/redmine/healthcheck.sh

healthcheck.sh:

#!/bin/sh
wget --no-verbose --tries=1 --spider http://localhost:3000/health_check 1>/dev/null 2>&1 

Use like

    healthcheck:
      test: ["CMD-SHELL", "healthcheck.sh"]
      start_period: 3s                                   
      interval: 10s                                
      timeout: 5s
      retries: 3

Now only problem is the logs fill up with 13 lines of health check every 10 seconds

redmine-1  | I, [2024-08-30T11:55:51.934301 #1]  INFO -- : Started HEAD "/health_check" for 127.0.0.1 at 2024-08-30 11:55:51 +0000
redmine-1  | I, [2024-08-30T11:55:51.935076 #1]  INFO -- : Processing by HealthCheckController#show as */*
redmine-1  | I, [2024-08-30T11:55:51.938317 #1]  INFO -- :   Current user: anonymous
redmine-1  | I, [2024-08-30T11:55:51.939111 #1]  INFO -- : Redirected to http://localhost:3000/login?back_url=http%3A%2F%2Flocalhost%3A3000%2Fhealth_check
redmine-1  | I, [2024-08-30T11:55:51.939247 #1]  INFO -- : Filter chain halted as :check_if_login_required rendered or redirected
redmine-1  | I, [2024-08-30T11:55:51.939408 #1]  INFO -- : Completed 302 Found in 4ms (ActiveRecord: 1.2ms | Allocations: 639)
redmine-1  | I, [2024-08-30T11:55:51.941697 #1]  INFO -- : Started HEAD "/login?back_url=http%3A%2F%2Flocalhost%3A3000%2Fhealth_check" for 127.0.0.1 at 2024-08-30 11:55:51 +0000
redmine-1  | I, [2024-08-30T11:55:51.942605 #1]  INFO -- : Processing by AccountController#login as */*
redmine-1  | I, [2024-08-30T11:55:51.942683 #1]  INFO -- :   Parameters: {"back_url"=>"http://localhost:3000/health_check"}
redmine-1  | I, [2024-08-30T11:55:51.946135 #1]  INFO -- :   Current user: anonymous
redmine-1  | I, [2024-08-30T11:55:51.949176 #1]  INFO -- :   Rendered account/login.html.erb within layouts/base (Duration: 2.0ms | Allocations: 521)
redmine-1  | I, [2024-08-30T11:55:52.109646 #1]  INFO -- :   Rendered layout layouts/base.html.erb (Duration: 162.5ms | Allocations: 28559)
redmine-1  | I, [2024-08-30T11:55:52.109955 #1]  INFO -- : Completed 200 OK in 167ms (Views: 112.2ms | ActiveRecord: 52.3ms | Allocations: 29208)
delanym commented 2 months ago

https://stackoverflow.com/questions/78932128/rails-set-alternative-log-for-endpoint

jcormier commented 2 months ago
COPY routes.rb /usr/src/redmine/config/
COPY health_check_controller.rb /usr/src/redmine/app/controllers/

I don't think we should be making changes to the redmine application in this docker image. Can we get away with fetching the /login URL until redmine adds a valid healthcheck?

delanym commented 2 months ago

Well its not the Redmine application per se we're changing - we're adding a route and a controller to the underlying Rails web server. If its set to /up then it pre-empts the coming healthcheck in Rails 7.1 anyway so there's no chance of a collision.

The problem with hitting /login (apart from confusing metrics consumers) is all the logs, and to silence them requires changing controllers anyway. I'm still figuring out how to silence calls to an endpoint.