allow users to add a domain to an app if there is no global vhost
This commit is contained in:
@@ -16,6 +16,19 @@ RE_IPV6="${RE_IPV6}fe08:(:[0-9a-fA-F]{1,4}){2,2}%[0-9a-zA-Z]{1,}|" # TEST: f
|
|||||||
RE_IPV6="${RE_IPV6}::(ffff(:0{1,4}){0,1}:){0,1}${RE_IPV4}|" # TEST: ::255.255.255.255 ::ffff:255.255.255.255 ::ffff:0:255.255.255.255 (IPv4-mapped IPv6 addresses and IPv4-translated addresses)
|
RE_IPV6="${RE_IPV6}::(ffff(:0{1,4}){0,1}:){0,1}${RE_IPV4}|" # TEST: ::255.255.255.255 ::ffff:255.255.255.255 ::ffff:0:255.255.255.255 (IPv4-mapped IPv6 addresses and IPv4-translated addresses)
|
||||||
RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,4}:${RE_IPV4}" # TEST: 2001:db8:3:4::192.0.2.33 64:ff9b::192.0.2.33
|
RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,4}:${RE_IPV4}" # TEST: 2001:db8:3:4::192.0.2.33 64:ff9b::192.0.2.33
|
||||||
|
|
||||||
|
domains_restart_app() {
|
||||||
|
APP="$1";
|
||||||
|
|
||||||
|
if [[ -f "$DOKKU_ROOT/$APP/CONTAINER" ]]; then
|
||||||
|
echo "-----> Releasing $APP ..."
|
||||||
|
dokku release $APP
|
||||||
|
echo "-----> Release complete!"
|
||||||
|
echo "-----> Deploying $APP ..."
|
||||||
|
dokku deploy $APP
|
||||||
|
echo "-----> Deploy complete!"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
domains)
|
domains)
|
||||||
[[ -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
|
||||||
@@ -38,22 +51,24 @@ case "$1" in
|
|||||||
else
|
else
|
||||||
VHOST=$(< "$DOKKU_ROOT/HOSTNAME")
|
VHOST=$(< "$DOKKU_ROOT/HOSTNAME")
|
||||||
fi
|
fi
|
||||||
if [[ "$VHOST" =~ $RE_IPV4 ]] || [[ "$VHOST" =~ $RE_IPV6 ]] || [[ ! -f "$DOKKU_ROOT/VHOST" ]];then
|
if [[ "$VHOST" =~ $RE_IPV4 ]] || [[ "$VHOST" =~ $RE_IPV6 ]];then
|
||||||
echo "unsupported vhost config found. disabling vhost support"
|
echo "unsupported vhost config found. disabling vhost support"
|
||||||
[[ ! $(grep -q NO_VHOST "$DOKKU_ROOT/$APP/ENV") ]] && echo "export NO_VHOST='1'" >> "$DOKKU_ROOT/$APP/ENV"
|
[[ ! $(grep -q NO_VHOST "$DOKKU_ROOT/$APP/ENV") ]] && echo "export NO_VHOST='1'" >> "$DOKKU_ROOT/$APP/ENV"
|
||||||
else
|
else
|
||||||
echo "-----> Creating new $VHOST_PATH..."
|
if [[ -f "$DOKKU_ROOT/VHOST" ]]; then
|
||||||
SUBDOMAIN=${APP/%\.${VHOST}/}
|
echo "-----> Creating new $VHOST_PATH..."
|
||||||
hostname=$(: | pluginhook nginx-hostname $APP $SUBDOMAIN $VHOST)
|
SUBDOMAIN=${APP/%\.${VHOST}/}
|
||||||
if [[ ! -n $hostname ]]; then
|
hostname=$(: | pluginhook nginx-hostname $APP $SUBDOMAIN $VHOST)
|
||||||
if [[ "$APP" == *.* ]] && [[ "$SUBDOMAIN" == "$APP" ]]; then
|
if [[ ! -n $hostname ]]; then
|
||||||
hostname="${APP/\//-}"
|
if [[ "$APP" == *.* ]] && [[ "$SUBDOMAIN" == "$APP" ]]; then
|
||||||
else
|
hostname="${APP/\//-}"
|
||||||
hostname="${APP/\//-}.$VHOST"
|
else
|
||||||
|
hostname="${APP/\//-}.$VHOST"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
echo "$hostname" > $VHOST_PATH
|
echo "$hostname" > $VHOST_PATH
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
@@ -76,6 +91,8 @@ case "$1" in
|
|||||||
|
|
||||||
dokku domains:setup $APP
|
dokku domains:setup $APP
|
||||||
echo "$3" >> "$DOKKU_ROOT/$APP/VHOST"
|
echo "$3" >> "$DOKKU_ROOT/$APP/VHOST"
|
||||||
|
# we need to restart the app to make sure we're binding to the appropriate network interface
|
||||||
|
domains_restart_app $APP
|
||||||
pluginhook post-domains-update $APP
|
pluginhook post-domains-update $APP
|
||||||
echo "-----> Added $3 to $APP"
|
echo "-----> Added $3 to $APP"
|
||||||
|
|
||||||
|
|||||||
@@ -21,10 +21,12 @@ RE_IPV6="${RE_IPV6}([0-9a-fA-F]{1,4}:){1,4}:${RE_IPV4}" # TEST: 2
|
|||||||
|
|
||||||
[[ -f "$DOKKU_ROOT/VHOST" ]] && GLOBAL_VHOST=$(< "$DOKKU_ROOT/VHOST")
|
[[ -f "$DOKKU_ROOT/VHOST" ]] && GLOBAL_VHOST=$(< "$DOKKU_ROOT/VHOST")
|
||||||
|
|
||||||
if [[ -n "$NO_VHOST" ]] || [[ -z "$GLOBAL_VHOST" ]]; then
|
if [[ -n "$NO_VHOST" ]]; then
|
||||||
echo true # bind to external ip. VHOST is disabled
|
echo true # bind to external ip. VHOST is disabled
|
||||||
elif [[ "$GLOBAL_VHOST" =~ $RE_IPV4 ]] || [[ "$GLOBAL_VHOST" =~ $RE_IPV6 ]]; then
|
elif [[ "$GLOBAL_VHOST" =~ $RE_IPV4 ]] || [[ "$GLOBAL_VHOST" =~ $RE_IPV6 ]]; then
|
||||||
echo true # bind to external ip. GLOBAL_VHOST is somehow an IPv4 or IPv6 address
|
echo true # bind to external ip. GLOBAL_VHOST is somehow an IPv4 or IPv6 address
|
||||||
|
elif [[ -z "$GLOBAL_VHOST" ]] && [[ ! -f "$DOKKU_ROOT/$APP/VHOST" ]]; then
|
||||||
|
echo true # bind to external ip. no GLOBAL_VHOST and no app vhost
|
||||||
elif [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then
|
elif [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then
|
||||||
echo false # bind to docker ip. this app has a vhost defined
|
echo false # bind to docker ip. this app has a vhost defined
|
||||||
else
|
else
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ case "$1" in
|
|||||||
|
|
||||||
[[ -f "$DOKKU_ROOT/$APP/ENV" ]] && source $DOKKU_ROOT/$APP/ENV
|
[[ -f "$DOKKU_ROOT/$APP/ENV" ]] && source $DOKKU_ROOT/$APP/ENV
|
||||||
|
|
||||||
if [[ ! -n "$NO_VHOST" ]]; then
|
if [[ ! -n "$NO_VHOST" ]] && [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then
|
||||||
NONSSL_VHOSTS=$(cat $VHOST_PATH)
|
NONSSL_VHOSTS=$(cat $VHOST_PATH)
|
||||||
if [[ -e "$SSL/server.crt" ]] && [[ -e "$SSL/server.key" ]]; then
|
if [[ -e "$SSL/server.crt" ]] && [[ -e "$SSL/server.key" ]]; then
|
||||||
SSL_INUSE="$SSL"
|
SSL_INUSE="$SSL"
|
||||||
@@ -86,14 +86,14 @@ EOF
|
|||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
if [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then
|
if [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then
|
||||||
echo "-----> NO_VHOST set, deleting $APP/VHOST"
|
echo "-----> VHOST support disabled, deleting $APP/VHOST"
|
||||||
rm "$DOKKU_ROOT/$APP/VHOST"
|
rm "$DOKKU_ROOT/$APP/VHOST"
|
||||||
fi
|
fi
|
||||||
if [[ -f "$DOKKU_ROOT/$APP/nginx.conf" ]]; then
|
if [[ -f "$DOKKU_ROOT/$APP/nginx.conf" ]]; then
|
||||||
echo "-----> NO_VHOST set, deleting nginx.conf"
|
echo "-----> VHOST support disabled, deleting nginx.conf"
|
||||||
rm "$DOKKU_ROOT/$APP/nginx.conf"
|
rm "$DOKKU_ROOT/$APP/nginx.conf"
|
||||||
|
|
||||||
echo "-----> NO_VHOST set, reloading nginx after nginx.conf deletion"
|
echo "-----> VHOST support disabled, reloading nginx after nginx.conf deletion"
|
||||||
restart_nginx
|
restart_nginx
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|||||||
@@ -3,11 +3,15 @@
|
|||||||
load test_helper
|
load test_helper
|
||||||
|
|
||||||
setup() {
|
setup() {
|
||||||
|
[[ -f "$DOKKU_ROOT/VHOST" ]] && cp -f "$DOKKU_ROOT/VHOST" "$DOKKU_ROOT/VHOST.bak"
|
||||||
|
[[ -f "$DOKKU_ROOT/HOSTNAME" ]] && cp -f "$DOKKU_ROOT/HOSTNAME" "$DOKKU_ROOT/HOSTNAME.bak"
|
||||||
create_app
|
create_app
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
destroy_app
|
destroy_app
|
||||||
|
[[ -f "$DOKKU_ROOT/VHOST.bak" ]] && mv "$DOKKU_ROOT/VHOST.bak" "$DOKKU_ROOT/VHOST"
|
||||||
|
[[ -f "$DOKKU_ROOT/HOSTNAME.bak" ]] && mv "$DOKKU_ROOT/HOSTNAME.bak" "$DOKKU_ROOT/HOSTNAME"
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "nginx (no server tokens)" {
|
@test "nginx (no server tokens)" {
|
||||||
@@ -26,3 +30,19 @@ teardown() {
|
|||||||
echo "status: "$status
|
echo "status: "$status
|
||||||
assert_output "node-js-app.dokku.me"
|
assert_output "node-js-app.dokku.me"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "nginx:build-config (no global VHOST and domains:add)" {
|
||||||
|
destroy_app
|
||||||
|
rm "$DOKKU_ROOT/VHOST"
|
||||||
|
create_app
|
||||||
|
run dokku domains:add $TEST_APP www.test.app.dokku.me
|
||||||
|
echo "output: "$output
|
||||||
|
echo "status: "$status
|
||||||
|
assert_success
|
||||||
|
deploy_app
|
||||||
|
sleep 5 # wait for nginx to reload
|
||||||
|
run bash -c "response=\"$(curl -s -S www.test.app.dokku.me)\"; echo \$response; test \"\$response\" == \"nodejs/express\""
|
||||||
|
echo "output: "$output
|
||||||
|
echo "status: "$status
|
||||||
|
assert_success
|
||||||
|
}
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ load test_helper
|
|||||||
setup() {
|
setup() {
|
||||||
[[ -f "$DOKKU_ROOT/VHOST" ]] && cp -f "$DOKKU_ROOT/VHOST" "$DOKKU_ROOT/VHOST.bak"
|
[[ -f "$DOKKU_ROOT/VHOST" ]] && cp -f "$DOKKU_ROOT/VHOST" "$DOKKU_ROOT/VHOST.bak"
|
||||||
[[ -f "$DOKKU_ROOT/HOSTNAME" ]] && cp -f "$DOKKU_ROOT/HOSTNAME" "$DOKKU_ROOT/HOSTNAME.bak"
|
[[ -f "$DOKKU_ROOT/HOSTNAME" ]] && cp -f "$DOKKU_ROOT/HOSTNAME" "$DOKKU_ROOT/HOSTNAME.bak"
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
teardown() {
|
teardown() {
|
||||||
@@ -67,14 +66,43 @@ teardown() {
|
|||||||
assert_success
|
assert_success
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "port exposure (domains:add)" {
|
@test "port exposure (pre-deploy domains:add)" {
|
||||||
create_app
|
create_app
|
||||||
run dokku domains:add $TEST_APP www.test.app.dokku.me
|
run dokku domains:add $TEST_APP www.test.app.dokku.me
|
||||||
echo "output: "$output
|
echo "output: "$output
|
||||||
echo "status: "$status
|
echo "status: "$status
|
||||||
assert_success
|
assert_success
|
||||||
|
|
||||||
deploy_app
|
deploy_app
|
||||||
sleep 5 # wait for nginx to reload
|
sleep 5 # wait for nginx to reload
|
||||||
|
|
||||||
|
CONTAINER_ID=$(docker ps --no-trunc| grep dokku/$TEST_APP | grep "start web" | awk '{ print $1 }')
|
||||||
|
run bash -c "docker port $CONTAINER_ID | sed 's/[0-9.]*://' | egrep '[0-9]*'"
|
||||||
|
echo "output: "$output
|
||||||
|
echo "status: "$status
|
||||||
|
assert_failure
|
||||||
|
|
||||||
|
run bash -c "response=\"$(curl -s -S www.test.app.dokku.me)\"; echo \$response; test \"\$response\" == \"nodejs/express\""
|
||||||
|
echo "output: "$output
|
||||||
|
echo "status: "$status
|
||||||
|
assert_success
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "port exposure (no global VHOST and domains:add post deploy)" {
|
||||||
|
rm "$DOKKU_ROOT/VHOST"
|
||||||
|
deploy_app
|
||||||
|
|
||||||
|
run dokku domains:add $TEST_APP www.test.app.dokku.me
|
||||||
|
echo "output: "$output
|
||||||
|
echo "status: "$status
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
CONTAINER_ID=$(docker ps --no-trunc| grep dokku/$TEST_APP | grep "start web" | awk '{ print $1 }')
|
||||||
|
run bash -c "docker port $CONTAINER_ID | sed 's/[0-9.]*://' | egrep '[0-9]*'"
|
||||||
|
echo "output: "$output
|
||||||
|
echo "status: "$status
|
||||||
|
assert_failure
|
||||||
|
|
||||||
run bash -c "response=\"$(curl -s -S www.test.app.dokku.me)\"; echo \$response; test \"\$response\" == \"nodejs/express\""
|
run bash -c "response=\"$(curl -s -S www.test.app.dokku.me)\"; echo \$response; test \"\$response\" == \"nodejs/express\""
|
||||||
echo "output: "$output
|
echo "output: "$output
|
||||||
echo "status: "$status
|
echo "status: "$status
|
||||||
|
|||||||
Reference in New Issue
Block a user