这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions plugins/00_dokku-standard/commands
Original file line number Diff line number Diff line change
Expand Up @@ -153,24 +153,27 @@ case "$1" in
url | urls)
[[ -z $2 ]] && echo "Please specify an app to run the command on" && exit 1
verify_app_name "$2"
APP="$2"; 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
SCHEME="https"
fi
APP="$2";

if [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then
if [[ -s "$DOKKU_ROOT/$APP/URLS" ]]; then
case "$1" in
url)
echo "$SCHEME://$(head -n1 "$DOKKU_ROOT/$APP/VHOST")"
grep "^http" "$DOKKU_ROOT/$APP/URLS" | head -1
;;
urls)
for vhost in $(< "$DOKKU_ROOT/$APP/VHOST"); do
echo "$SCHEME://$vhost"
done
grep "^http" "$DOKKU_ROOT/$APP/URLS"
;;
esac
elif [[ -f "$DOKKU_ROOT/VHOST" ]]; then

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
SCHEME="https"
fi

if [[ -f "$DOKKU_ROOT/VHOST" ]]; then
echo "$SCHEME://$(< "$DOKKU_ROOT/VHOST")"
else
echo "$SCHEME://$(< "$DOKKU_ROOT/HOSTNAME"):$(< "$DOKKU_ROOT/$APP/PORT")"
Expand Down
5 changes: 5 additions & 0 deletions plugins/nginx-vhosts/commands
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ case "$1" in
nginx:build-config)
APP="$2"; DOKKU_APP_LISTEN_PORT="$3"; DOKKU_APP_LISTEN_IP="${4}"
VHOST_PATH="$DOKKU_ROOT/$APP/VHOST"
URLS_PATH="$DOKKU_ROOT/$APP/URLS"
WILDCARD_SSL="$DOKKU_ROOT/tls"
SSL="$DOKKU_ROOT/$APP/tls"

Expand Down Expand Up @@ -94,6 +95,10 @@ EOF
echo " Reloading nginx"
restart_nginx
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
if [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then
dokku_log_info1 "VHOST support disabled, deleting $APP/VHOST"
Expand Down
43 changes: 31 additions & 12 deletions tests/unit/00_dokku-standard.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,20 @@ teardown() {
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)" {
deploy_app
run /bin/bash -c "dokku run $TEST_APP ls /app/package.json"
Expand All @@ -29,24 +43,29 @@ teardown() {
}

@test "urls (non-ssl)" {
run bash -c "dokku urls $TEST_APP | grep dokku.me"
echo "output: "$output
echo "status: "$status
assert_output "http://dokku.me"
assert_urls "http://dokku.me"
build_nginx_config
assert_urls "http://${TEST_APP}.dokku.me"
add_domain "test.dokku.me"
assert_urls "http://${TEST_APP}.dokku.me" "http://test.dokku.me"
}

@test "urls (app ssl)" {
setup_test_tls
run bash -c "dokku urls $TEST_APP | grep dokku.me"
echo "output: "$output
echo "status: "$status
assert_output "https://dokku.me"
assert_urls "https://dokku.me"
build_nginx_config
assert_urls "https://node-js-app.dokku.me" "http://${TEST_APP}.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)" {
setup_test_tls_wildcard
run bash -c "dokku urls $TEST_APP | grep dokku.me"
echo "output: "$output
echo "status: "$status
assert_output "https://dokku.me"
assert_urls "https://dokku.me"
build_nginx_config
assert_urls "https://${TEST_APP}.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"
}
4 changes: 4 additions & 0 deletions tests/unit/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ destroy_app() {
echo $TEST_APP | dokku apps:destroy $TEST_APP
}

add_domain() {
dokku domains:add $TEST_APP $1
}

deploy_app() {
APP_TYPE="$1"; APP_TYPE=${APP_TYPE:="nodejs-express"}
TMP=$(mktemp -d -t "$TARGET.XXXXX")
Expand Down