-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add healthcheck endpoint, set default ENV in Dockerfile #16
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,16 +7,18 @@ server { | |
listen 80; | ||
server_name ${SERVER_NAME}; | ||
|
||
# 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}; | ||
} | ||
Comment on lines
-10
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Existing directives wrapped to allow healthcheck location to be added location / {
} |
||
|
||
# redirect server error pages to the static page /50x.html | ||
# | ||
|
@@ -25,4 +27,5 @@ server { | |
root /usr/share/nginx/html; | ||
} | ||
|
||
${HEALTHCHECK_LOCATION_BLOCK} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,3 +26,5 @@ to: | |
# optionally define the location for the nginx error log | ||
# if not set /dev/stderr is used | ||
#- SERVER_ERROR_LOG=/dev/null | ||
# optionally enable the healthcheck endpoint | ||
#- SERVER_HEALTHCHECK_ENABLED=1 | ||
Comment on lines
+29
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I haven't added all new environment variables to this file to avoid cluttering it. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# return status code 200 on healthcheck route | ||
location = /${SERVER_HEALTHCHECK_PATH} { | ||
return ${SERVER_HEALTHCHECK_RESPONSE_CODE} ${SERVER_HEALTHCHECK_RESPONSE_BODY}; | ||
add_header Content-Type text/plain; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,6 @@ if [ ! -n "$SERVER_REDIRECT" ] ; then | |
exit 1 | ||
fi | ||
|
||
# set server name from optional ENV var | ||
if [ ! -n "$SERVER_NAME" ] ; then | ||
SERVER_NAME='localhost' | ||
fi | ||
|
||
# set redirect code from optional ENV var | ||
# allowed Status Codes are: 301, 302, 303, 307, 308 | ||
expr match "$SERVER_REDIRECT_CODE" '30[12378]$' > /dev/null || SERVER_REDIRECT_CODE='301' | ||
|
@@ -20,26 +15,6 @@ expr match "$SERVER_REDIRECT_POST_CODE" '30[12378]$' > /dev/null || SERVER_REDIR | |
# set redirect code from optional ENV var for PUT, PATCH and DELETE requests | ||
expr match "$SERVER_REDIRECT_PUT_PATCH_DELETE_CODE" '30[12378]$' > /dev/null || SERVER_REDIRECT_PUT_PATCH_DELETE_CODE=$SERVER_REDIRECT_CODE | ||
|
||
# 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 | ||
|
||
Comment on lines
-23
to
-42
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No longer required as defaults are set at buildtime then overridden at runtime |
||
sed -i "s|\${SERVER_REDIRECT}|${SERVER_REDIRECT}|" /etc/nginx/conf.d/default.conf | ||
sed -i "s|\${SERVER_NAME}|${SERVER_NAME}|" /etc/nginx/conf.d/default.conf | ||
sed -i "s|\${SERVER_REDIRECT_CODE}|${SERVER_REDIRECT_CODE}|" /etc/nginx/conf.d/default.conf | ||
|
@@ -48,6 +23,17 @@ sed -i "s|\${SERVER_REDIRECT_PUT_PATCH_DELETE_CODE}|${SERVER_REDIRECT_PUT_PATCH_ | |
sed -i "s|\${SERVER_REDIRECT_PATH}|${SERVER_REDIRECT_PATH}|" /etc/nginx/conf.d/default.conf | ||
sed -i "s|\${SERVER_REDIRECT_SCHEME}|${SERVER_REDIRECT_SCHEME}|" /etc/nginx/conf.d/default.conf | ||
|
||
# optionally add healthcheck endpoint | ||
if [ $SERVER_HEALTHCHECK_ENABLED = 1 ]; then | ||
sed -i "s|\${HEALTHCHECK_LOCATION_BLOCK}|include includes/healthcheck.conf;|" /etc/nginx/conf.d/default.conf | ||
|
||
sed -i "s|\${SERVER_HEALTHCHECK_PATH}|${SERVER_HEALTHCHECK_PATH}|" /etc/nginx/includes/healthcheck.conf | ||
sed -i "s|\${SERVER_HEALTHCHECK_RESPONSE_CODE}|${SERVER_HEALTHCHECK_RESPONSE_CODE}|" /etc/nginx/includes/healthcheck.conf | ||
sed -i "s|\${SERVER_HEALTHCHECK_RESPONSE_BODY}|${SERVER_HEALTHCHECK_RESPONSE_BODY}|" /etc/nginx/includes/healthcheck.conf | ||
else | ||
sed -i "s|\${HEALTHCHECK_LOCATION_BLOCK}||" /etc/nginx/conf.d/default.conf | ||
fi | ||
|
||
ln -sfT "$SERVER_ACCESS_LOG" /var/log/nginx/access.log | ||
ln -sfT "$SERVER_ERROR_LOG" /var/log/nginx/error.log | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Define default environment variables at build time instead of checking and overriding in
run.sh
.