Add healthcheck endpoint, set default ENV in Dockerfile#16
Open
robwatkiss wants to merge 2 commits intoschmunk42:masterfrom
Open
Add healthcheck endpoint, set default ENV in Dockerfile#16robwatkiss wants to merge 2 commits intoschmunk42:masterfrom
robwatkiss wants to merge 2 commits intoschmunk42:masterfrom
Conversation
robwatkiss
commented
Jul 28, 2020
Comment on lines
+3
to
+11
| ENV SERVER_NAME='localhost' \ | ||
| SERVER_REDIRECT_PATH='$request_uri' \ | ||
| SERVER_REDIRECT_SCHEME='$redirect_scheme' \ | ||
| SERVER_ACCESS_LOG='/dev/stdout' \ | ||
| SERVER_ERROR_LOG='/dev/stderr' \ | ||
| SERVER_HEALTHCHECK_ENABLED=0 \ | ||
| SERVER_HEALTHCHECK_RESPONSE_CODE=200 \ | ||
| SERVER_HEALTHCHECK_RESPONSE_BODY='alive' \ | ||
| SERVER_HEALTHCHECK_PATH='healthcheck' |
Author
There was a problem hiding this comment.
Define default environment variables at build time instead of checking and overriding in run.sh.
robwatkiss
commented
Jul 28, 2020
Comment on lines
-10
to
+21
| # cherry picked from https://github.com/schmunk42/docker-nginx-redirect/pull/8 | ||
| if ($request_method = POST) { | ||
| return ${SERVER_REDIRECT_POST_CODE} ${SERVER_REDIRECT_SCHEME}://${SERVER_REDIRECT}${SERVER_REDIRECT_PATH}; | ||
| } | ||
| location / { | ||
| # cherry picked from https://github.com/schmunk42/docker-nginx-redirect/pull/8 | ||
| if ($request_method = POST) { | ||
| return ${SERVER_REDIRECT_POST_CODE} ${SERVER_REDIRECT_SCHEME}://${SERVER_REDIRECT}${SERVER_REDIRECT_PATH}; | ||
| } | ||
|
|
||
| if ($request_method ~ PUT|PATCH|DELETE) { | ||
| return ${SERVER_REDIRECT_PUT_PATCH_DELETE_CODE} ${SERVER_REDIRECT_SCHEME}://${SERVER_REDIRECT}${SERVER_REDIRECT_PATH}; | ||
| } | ||
| if ($request_method ~ PUT|PATCH|DELETE) { | ||
| return ${SERVER_REDIRECT_PUT_PATCH_DELETE_CODE} ${SERVER_REDIRECT_SCHEME}://${SERVER_REDIRECT}${SERVER_REDIRECT_PATH}; | ||
| } | ||
|
|
||
| return ${SERVER_REDIRECT_CODE} ${SERVER_REDIRECT_SCHEME}://${SERVER_REDIRECT}${SERVER_REDIRECT_PATH}; | ||
| return ${SERVER_REDIRECT_CODE} ${SERVER_REDIRECT_SCHEME}://${SERVER_REDIRECT}${SERVER_REDIRECT_PATH}; | ||
| } |
Author
There was a problem hiding this comment.
Existing directives wrapped to allow healthcheck location to be added
location / {
}
robwatkiss
commented
Jul 28, 2020
Comment on lines
+29
to
+30
| # optionally enable the healthcheck endpoint | ||
| #- SERVER_HEALTHCHECK_ENABLED=1 No newline at end of file |
Author
There was a problem hiding this comment.
I haven't added all new environment variables to this file to avoid cluttering it.
robwatkiss
commented
Jul 28, 2020
Comment on lines
-23
to
-42
| # set redirect path from optional ENV var | ||
| if [ ! -n "$SERVER_REDIRECT_PATH" ] ; then | ||
| SERVER_REDIRECT_PATH='$request_uri' | ||
| fi | ||
|
|
||
| # set redirect scheme from optional ENV var | ||
| if [ ! -n "$SERVER_REDIRECT_SCHEME" ] ; then | ||
| SERVER_REDIRECT_SCHEME='$redirect_scheme' | ||
| fi | ||
|
|
||
| # set access log location from optional ENV var | ||
| if [ ! -n "$SERVER_ACCESS_LOG" ] ; then | ||
| SERVER_ACCESS_LOG='/dev/stdout' | ||
| fi | ||
|
|
||
| # set error log location from optional ENV var | ||
| if [ ! -n "$SERVER_ERROR_LOG" ] ; then | ||
| SERVER_ERROR_LOG='/dev/stderr' | ||
| fi | ||
|
|
Author
There was a problem hiding this comment.
No longer required as defaults are set at buildtime then overridden at runtime
Owner
|
@robwatkiss Is this backward-compatible? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 settingSERVER_HEALTHCHECK_ENABLED=1SERVER_HEALTHCHECK_PATH- optionally override the location of the healthcheck endpoint/healthcheckSERVER_HEALTHCHECK_RESPONSE_CODE- optionally override the status code of the healthcheck endpoint response200SERVER_HEALTHCHECK_RESPONSE_BODY- optionally override the body of the healthcheck endpoint responsealiveIf
SERVER_HEALTHCHECK_ENABLED=1then/etc/nginx/includes/healthcheck.confis included intodefault.conf.In order for location matching against
/${SERVER_HEALTHCHECK_PATH}it was necessary to wrap existing redirects inFinally this pull request tidies up
run.shby declaring default ENV values at build time in the Dockerfile.