docker-nginx-redirect icon indicating copy to clipboard operation
docker-nginx-redirect copied to clipboard

Add healthcheck endpoint, set default ENV in Dockerfile

Open robwatkiss opened this issue 5 years ago • 1 comments

This pull request adds an optional healthcheck endpoint, useful for environments such as Kubernetes where readiness needs to be probed and monitored.

Four new environment variables are introduced:

  • SERVER_HEALTHCHECK_ENABLED - optionally enable a static healthcheck endpoint by setting SERVER_HEALTHCHECK_ENABLED=1
    • useful for deploying to Kubernetes or similar infrastructure where readiness needs to be confirmed and monitored
    • disabled by default
  • SERVER_HEALTHCHECK_PATH - optionally override the location of the healthcheck endpoint
    • defaults to /healthcheck
  • SERVER_HEALTHCHECK_RESPONSE_CODE - optionally override the status code of the healthcheck endpoint response
    • defaults to 200
  • SERVER_HEALTHCHECK_RESPONSE_BODY - optionally override the body of the healthcheck endpoint response
    • defaults to alive

If SERVER_HEALTHCHECK_ENABLED=1 then /etc/nginx/includes/healthcheck.conf is included into default.conf.

In order for location matching against /${SERVER_HEALTHCHECK_PATH} it was necessary to wrap existing redirects in

location / {
    ...
    # Existing redirect directives
    ...
}

Finally this pull request tidies up run.sh by declaring default ENV values at build time in the Dockerfile.

robwatkiss avatar Jul 28 '20 16:07 robwatkiss

@robwatkiss Is this backward-compatible?

schmunk42 avatar Aug 24 '20 09:08 schmunk42