Merge pull request #4286 from dokku/3974-templated-checks
Add support for templated CHECKS files
This commit is contained in:
@@ -157,6 +157,38 @@ https://static.dokku.me/logo.png
|
||||
|
||||
While a full URL may be used in order to invoke checks, if you are using relative URLs, the port *must* be omitted.
|
||||
|
||||
> Changed as of 0.22.5
|
||||
|
||||
Please note that dollar sign bracket characters (`{` and `}`) must be escaped when used within a `CHECKS` file. Escaping follows golang template rules. The proper way to do this is via one of the following methods:
|
||||
|
||||
```
|
||||
# escaping the `{` character
|
||||
# using double-quotes
|
||||
{{"{"}}
|
||||
|
||||
# using raw string constants
|
||||
{{`{`}}
|
||||
|
||||
# escaping the `}` character
|
||||
# using double-quotes
|
||||
{{"}"}}
|
||||
|
||||
# using raw string constants
|
||||
{{`}`}}
|
||||
```
|
||||
|
||||
### Templating Checks Files
|
||||
|
||||
> New as of 0.22.5
|
||||
|
||||
An app's `CHECKS` file is sent through a single pass of the [`sigil`](https://github.com/gliderlabs/sigil/) templating tool. This enables usage of Golang templating within application `CHECKS` files. In addition to general templating access, access to app environment variables is also allowed via the `var` function:
|
||||
|
||||
```
|
||||
{{ var "SOME_ENV_VAR" }}
|
||||
```
|
||||
|
||||
This may be useful if certain zero-downtime checks require access to an app-specific value, such as a domain name.
|
||||
|
||||
### Check settings
|
||||
|
||||
The default behavior is to wait for `5` seconds before running the checks, to timeout the checks after `30` seconds, and to attempt the checks `5` times. If the checks fail `5` times, the deployment is considered failed and the old container will continue serving traffic.
|
||||
|
||||
@@ -115,16 +115,14 @@ trigger-scheduler-docker-local-check-deploy() {
|
||||
dokku_log_verbose "Default container check successful!" && exit 0
|
||||
fi
|
||||
|
||||
# ensure CHECKS file has trailing newline
|
||||
if [[ "$(tail -c1 "$CHECKS_FILENAME")" != "" ]]; then
|
||||
# workaround for CHECKS file when owner is root. seems to only happen when running inside docker
|
||||
if [[ "$(stat -c %u "$CHECKS_FILENAME")" == "0" ]]; then
|
||||
local NEW_CHECKS_FILENAME=${CHECK_DEPLOY_TMP_WORK_DIR}/$(mktemp dokku-${FUNCNAME[0]}-CHECKS.XXXX)
|
||||
cat ${CHECKS_FILENAME} >${NEW_CHECKS_FILENAME}
|
||||
CHECKS_FILENAME=$NEW_CHECKS_FILENAME
|
||||
fi
|
||||
echo "" >>"$CHECKS_FILENAME"
|
||||
fi
|
||||
local NEW_CHECKS_FILENAME="${CHECK_DEPLOY_TMP_WORK_DIR}/NEW_CHECKS"
|
||||
template_checks() {
|
||||
eval "$(config_export app "$APP" --merged)"
|
||||
sigil -f "$CHECKS_FILENAME" | cat -s >"$NEW_CHECKS_FILENAME"
|
||||
}
|
||||
|
||||
template_checks
|
||||
CHECKS_FILENAME="$NEW_CHECKS_FILENAME"
|
||||
|
||||
# Reads name/value pairs, sets the WAIT and TIMEOUT variables
|
||||
exec <"$CHECKS_FILENAME"
|
||||
|
||||
@@ -6,6 +6,10 @@ app.get('/', function(request, response) {
|
||||
response.send('nodejs/express');
|
||||
});
|
||||
|
||||
app.get('/healthcheck', function(request, response) {
|
||||
response.send(process.env.HEALTHCHECK_ENDPOINT);
|
||||
});
|
||||
|
||||
var port = process.env.PORT || 5000;
|
||||
app.listen(port, function() {
|
||||
console.log("Listening on " + port);
|
||||
|
||||
@@ -249,3 +249,16 @@ teardown() {
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "(checks) checks:templated" {
|
||||
run /bin/bash -c "dokku config:set $TEST_APP HEALTHCHECK_ENDPOINT=/healthcheck"
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_success
|
||||
|
||||
run deploy_app nodejs-express dokku@dokku.me:$TEST_APP template_checks_file
|
||||
echo "output: $output"
|
||||
echo "status: $status"
|
||||
assert_output_contains "/healthcheck" 2
|
||||
assert_success
|
||||
}
|
||||
|
||||
@@ -484,6 +484,20 @@ some lame nginx config
|
||||
EOF
|
||||
}
|
||||
|
||||
template_checks_file() {
|
||||
local APP="$1"
|
||||
local APP_REPO_DIR="$2"
|
||||
[[ -z "$APP" ]] && local APP="$TEST_APP"
|
||||
echo "injecting templated CHECKS file -> $APP_REPO_DIR/CHECKS"
|
||||
cat <<EOF >"$APP_REPO_DIR/CHECKS"
|
||||
WAIT=2 # wait 2 seconds
|
||||
TIMEOUT=5 # set timeout to 5 seconds
|
||||
ATTEMPTS=2 # try 2 times
|
||||
|
||||
{{ var "HEALTHCHECK_ENDPOINT" }} {{ var "HEALTHCHECK_ENDPOINT" }}
|
||||
EOF
|
||||
}
|
||||
|
||||
add_release_command() {
|
||||
local APP="$1"
|
||||
local APP_REPO_DIR="$2"
|
||||
|
||||
Reference in New Issue
Block a user