Fix URL schemes in dokku urls output
Previously, the presence of TLS certificates would cause `dokku urls` to output all https URLs, even for domains which were not configured to use TLS. This change introduces a URLS file in the app's directory which contains the URLs with schemes based on whether they have been configured to use TLS in the nginx config. Signed-off-by: Lewis Marshall <lewis@lmars.net>
This commit is contained in:
@@ -153,24 +153,27 @@ case "$1" in
|
|||||||
url | urls)
|
url | urls)
|
||||||
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
|
||||||
verify_app_name "$2"
|
verify_app_name "$2"
|
||||||
APP="$2"; SCHEME="http"; SSL="$DOKKU_ROOT/$APP/tls"; WILDCARD_SSL="$DOKKU_ROOT/tls"
|
APP="$2";
|
||||||
|
|
||||||
|
if [[ -s "$DOKKU_ROOT/$APP/URLS" ]]; then
|
||||||
|
case "$1" in
|
||||||
|
url)
|
||||||
|
grep "^http" "$DOKKU_ROOT/$APP/URLS" | head -1
|
||||||
|
;;
|
||||||
|
urls)
|
||||||
|
grep "^http" "$DOKKU_ROOT/$APP/URLS"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
SCHEME="http"; SSL="$DOKKU_ROOT/$APP/tls"; WILDCARD_SSL="$DOKKU_ROOT/tls"
|
||||||
if [[ -e "$SSL/server.crt" && -e "$SSL/server.key" ]] || [[ -e "$WILDCARD_SSL/server.crt" && -e "$WILDCARD_SSL/server.key" ]]; then
|
if [[ -e "$SSL/server.crt" && -e "$SSL/server.key" ]] || [[ -e "$WILDCARD_SSL/server.crt" && -e "$WILDCARD_SSL/server.key" ]]; then
|
||||||
SCHEME="https"
|
SCHEME="https"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then
|
if [[ -f "$DOKKU_ROOT/VHOST" ]]; then
|
||||||
case "$1" in
|
|
||||||
url)
|
|
||||||
echo "$SCHEME://$(head -n1 "$DOKKU_ROOT/$APP/VHOST")"
|
|
||||||
;;
|
|
||||||
urls)
|
|
||||||
for vhost in $(< "$DOKKU_ROOT/$APP/VHOST"); do
|
|
||||||
echo "$SCHEME://$vhost"
|
|
||||||
done
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
elif [[ -f "$DOKKU_ROOT/VHOST" ]]; then
|
|
||||||
echo "$SCHEME://$(< "$DOKKU_ROOT/VHOST")"
|
echo "$SCHEME://$(< "$DOKKU_ROOT/VHOST")"
|
||||||
else
|
else
|
||||||
echo "$SCHEME://$(< "$DOKKU_ROOT/HOSTNAME"):$(< "$DOKKU_ROOT/$APP/PORT")"
|
echo "$SCHEME://$(< "$DOKKU_ROOT/HOSTNAME"):$(< "$DOKKU_ROOT/$APP/PORT")"
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ case "$1" in
|
|||||||
nginx:build-config)
|
nginx:build-config)
|
||||||
APP="$2"; DOKKU_APP_LISTEN_PORT="$3"; DOKKU_APP_LISTEN_IP="${4}"
|
APP="$2"; DOKKU_APP_LISTEN_PORT="$3"; DOKKU_APP_LISTEN_IP="${4}"
|
||||||
VHOST_PATH="$DOKKU_ROOT/$APP/VHOST"
|
VHOST_PATH="$DOKKU_ROOT/$APP/VHOST"
|
||||||
|
URLS_PATH="$DOKKU_ROOT/$APP/URLS"
|
||||||
WILDCARD_SSL="$DOKKU_ROOT/tls"
|
WILDCARD_SSL="$DOKKU_ROOT/tls"
|
||||||
SSL="$DOKKU_ROOT/$APP/tls"
|
SSL="$DOKKU_ROOT/$APP/tls"
|
||||||
|
|
||||||
@@ -94,6 +95,10 @@ EOF
|
|||||||
echo " Reloading nginx"
|
echo " Reloading nginx"
|
||||||
restart_nginx
|
restart_nginx
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo "# THIS FILE IS GENERATED BY DOKKU - DO NOT EDIT, YOUR CHANGES WILL BE OVERWRITTEN" > $URLS_PATH
|
||||||
|
xargs -i echo "https://{}" <<< "${SSL_VHOSTS}" >> $URLS_PATH
|
||||||
|
xargs -i echo "http://{}" <<< "${NONSSL_VHOSTS}" >> $URLS_PATH
|
||||||
else
|
else
|
||||||
if [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then
|
if [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then
|
||||||
dokku_log_info1 "VHOST support disabled, deleting $APP/VHOST"
|
dokku_log_info1 "VHOST support disabled, deleting $APP/VHOST"
|
||||||
|
|||||||
@@ -12,6 +12,20 @@ teardown() {
|
|||||||
disable_tls_wildcard
|
disable_tls_wildcard
|
||||||
}
|
}
|
||||||
|
|
||||||
|
assert_urls() {
|
||||||
|
urls=$@
|
||||||
|
run dokku urls $TEST_APP
|
||||||
|
echo "output: "$output
|
||||||
|
echo "status: "$status
|
||||||
|
assert_output < <(tr ' ' '\n' <<< "${urls}")
|
||||||
|
}
|
||||||
|
|
||||||
|
build_nginx_config() {
|
||||||
|
# simulate nginx post-deploy
|
||||||
|
dokku domains:setup $TEST_APP
|
||||||
|
dokku nginx:build-config $TEST_APP
|
||||||
|
}
|
||||||
|
|
||||||
@test "run (with tty)" {
|
@test "run (with tty)" {
|
||||||
deploy_app
|
deploy_app
|
||||||
run /bin/bash -c "dokku run $TEST_APP ls /app/package.json"
|
run /bin/bash -c "dokku run $TEST_APP ls /app/package.json"
|
||||||
@@ -29,24 +43,29 @@ teardown() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "urls (non-ssl)" {
|
@test "urls (non-ssl)" {
|
||||||
run bash -c "dokku urls $TEST_APP | grep dokku.me"
|
assert_urls "http://dokku.me"
|
||||||
echo "output: "$output
|
build_nginx_config
|
||||||
echo "status: "$status
|
assert_urls "http://${TEST_APP}.dokku.me"
|
||||||
assert_output "http://dokku.me"
|
add_domain "test.dokku.me"
|
||||||
|
assert_urls "http://${TEST_APP}.dokku.me" "http://test.dokku.me"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "urls (app ssl)" {
|
@test "urls (app ssl)" {
|
||||||
setup_test_tls
|
setup_test_tls
|
||||||
run bash -c "dokku urls $TEST_APP | grep dokku.me"
|
assert_urls "https://dokku.me"
|
||||||
echo "output: "$output
|
build_nginx_config
|
||||||
echo "status: "$status
|
assert_urls "https://node-js-app.dokku.me" "http://${TEST_APP}.dokku.me"
|
||||||
assert_output "https://dokku.me"
|
add_domain "test.dokku.me"
|
||||||
|
assert_urls "https://node-js-app.dokku.me" "http://${TEST_APP}.dokku.me" "http://test.dokku.me"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "urls (wildcard ssl)" {
|
@test "urls (wildcard ssl)" {
|
||||||
setup_test_tls_wildcard
|
setup_test_tls_wildcard
|
||||||
run bash -c "dokku urls $TEST_APP | grep dokku.me"
|
assert_urls "https://dokku.me"
|
||||||
echo "output: "$output
|
build_nginx_config
|
||||||
echo "status: "$status
|
assert_urls "https://${TEST_APP}.dokku.me"
|
||||||
assert_output "https://dokku.me"
|
add_domain "test.dokku.me"
|
||||||
|
assert_urls "https://${TEST_APP}.dokku.me" "https://test.dokku.me"
|
||||||
|
add_domain "dokku.example.com"
|
||||||
|
assert_urls "https://${TEST_APP}.dokku.me" "https://test.dokku.me" "http://dokku.example.com"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,6 +92,10 @@ destroy_app() {
|
|||||||
echo $TEST_APP | dokku apps:destroy $TEST_APP
|
echo $TEST_APP | dokku apps:destroy $TEST_APP
|
||||||
}
|
}
|
||||||
|
|
||||||
|
add_domain() {
|
||||||
|
dokku domains:add $TEST_APP $1
|
||||||
|
}
|
||||||
|
|
||||||
deploy_app() {
|
deploy_app() {
|
||||||
APP_TYPE="$1"; APP_TYPE=${APP_TYPE:="nodejs-express"}
|
APP_TYPE="$1"; APP_TYPE=${APP_TYPE:="nodejs-express"}
|
||||||
TMP=$(mktemp -d -t "$TARGET.XXXXX")
|
TMP=$(mktemp -d -t "$TARGET.XXXXX")
|
||||||
|
|||||||
Reference in New Issue
Block a user