Replaces our current host-based HTTP healthchecks with Docker healthchecks, and adds a new `healthcheck.cmd` config option that can be used to define a custom health check command. Also removes Traefik's healthchecks, since they are no longer necessary. When deploying a container that has a healthcheck defined, we wait for it to report a healthy status before stopping the old container that it replaces. Containers that don't have a healthcheck defined continue to wait for `MRSK.config.readiness_delay`. There are some pros and cons to using Docker healthchecks rather than checking from the host. The main advantages are: - Supports non-HTTP checks, and app-specific check scripts provided by a container. - When booting a container, allows MRSK to wait for a container to be healthy before shutting down the old container it replaces. This should be safer than relying on a timeout. - Containers with healthchecks won't be active in Traefik until they reach a healthy state, which prevents any traffic from being routed to them before they are ready. The main _disadvantage_ is that containers are now required to provide some way to check their health. Our default check assumes that `curl` is available in the container which, while common, won't always be the case.
20 lines
645 B
Ruby
20 lines
645 B
Ruby
class Mrsk::Cli::Healthcheck < Mrsk::Cli::Base
|
|
default_command :perform
|
|
|
|
desc "perform", "Health check current app version"
|
|
def perform
|
|
on(MRSK.primary_host) do
|
|
begin
|
|
execute *MRSK.healthcheck.run
|
|
Mrsk::Utils::HealthcheckPoller.wait_for_healthy { capture_with_info(*MRSK.healthcheck.status) }
|
|
rescue Mrsk::Utils::HealthcheckPoller::HealthcheckError => e
|
|
error capture_with_info(*MRSK.healthcheck.logs)
|
|
raise
|
|
ensure
|
|
execute *MRSK.healthcheck.stop, raise_on_non_zero_exit: false
|
|
execute *MRSK.healthcheck.remove, raise_on_non_zero_exit: false
|
|
end
|
|
end
|
|
end
|
|
end
|