diff --git a/dokku b/dokku index f59d247f0..d4e00a68c 100755 --- a/dokku +++ b/dokku @@ -88,14 +88,12 @@ case "$1" in port=5000 id=$(docker run -d -e PORT=$port $DOCKER_ARGS $IMAGE /bin/bash -c "/start web") ipaddr=$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $id) - - echo $ipaddr > "$DOKKU_ROOT/$APP/IP" else id=$(docker run -d -p 5000 -e PORT=5000 $DOCKER_ARGS $IMAGE /bin/bash -c "/start web") port=$(docker port $id 5000 | sed 's/[0-9.]*://') - - [[ -f "$DOKKU_ROOT/$APP/IP" ]] && rm -f "$DOKKU_ROOT/$APP/IP" + ipaddr=127.0.0.1 fi + echo $ipaddr > "$DOKKU_ROOT/$APP/IP" # if we can't post-deploy successfully, kill new container function kill_new { diff --git a/plugins/nginx-vhosts/commands b/plugins/nginx-vhosts/commands index 8434f21ae..b9ef3cf02 100755 --- a/plugins/nginx-vhosts/commands +++ b/plugins/nginx-vhosts/commands @@ -15,12 +15,18 @@ restart_nginx () { case "$1" in nginx:build-config) - APP="$2"; PORT="$3"; IP="${4:-127.0.0.1}" - [[ -z "$PORT" ]] && PORT=$(< "$DOKKU_ROOT/$APP/PORT") + APP="$2"; PORT="$3"; IP="${4}" VHOST_PATH="$DOKKU_ROOT/$APP/VHOST" WILDCARD_SSL="$DOKKU_ROOT/tls" SSL="$DOKKU_ROOT/$APP/tls" + if [[ -z "$PORT" ]] && [[ -f "$DOKKU_ROOT/$APP/PORT" ]]; then + PORT=$(< "$DOKKU_ROOT/$APP/PORT") + fi + if [[ -z "$IP" ]] && [[ -f "$DOKKU_ROOT/$APP/IP" ]]; then + IP=$(< "$DOKKU_ROOT/$APP/IP") + fi + [[ -f "$DOKKU_ROOT/$APP/ENV" ]] && source $DOKKU_ROOT/$APP/ENV if [[ ! -n "$NO_VHOST" ]]; then @@ -67,15 +73,17 @@ EOF # Include SSL_VHOSTS so we can redirect http to https on that hostname as well NOSSL_SERVER_NAME=$(echo $NONSSL_VHOSTS $SSL_VHOSTS| tr '\n' ' ') - echo "-----> Creating $SCHEME nginx.conf" - echo "upstream $APP { server $IP:$PORT; }" > $DOKKU_ROOT/$APP/nginx.conf - eval "cat <<< \"$(< $NGINX_CONF)\" >> $DOKKU_ROOT/$APP/nginx.conf" + if [[ -n "$PORT" ]] && [[ -n "$IP" ]]; then + echo "-----> Creating $SCHEME nginx.conf" + echo "upstream $APP { server $IP:$PORT; }" > $DOKKU_ROOT/$APP/nginx.conf + eval "cat <<< \"$(< $NGINX_CONF)\" >> $DOKKU_ROOT/$APP/nginx.conf" - echo "-----> Running nginx-pre-reload" - pluginhook nginx-pre-reload $APP $PORT + echo "-----> Running nginx-pre-reload" + pluginhook nginx-pre-reload $APP $PORT $IP - echo " Reloading nginx" - restart_nginx + echo " Reloading nginx" + restart_nginx + fi else if [[ -f "$DOKKU_ROOT/$APP/VHOST" ]]; then echo "-----> NO_VHOST set, deleting $APP/VHOST" diff --git a/tests.mk b/tests.mk index ac45a75fe..ef84dbf5a 100644 --- a/tests.mk +++ b/tests.mk @@ -17,7 +17,7 @@ ifdef ENABLE_DOKKU_TRACE echo "export DOKKU_TRACE=1" >> /home/dokku/dokkurc endif @echo "Setting dokku.me in /etc/hosts" - sudo /bin/bash -c "[[ `ping -c1 dokku.me > /dev/null 2>&1; echo $$?` -eq 0 ]] || echo \"127.0.0.1 dokku.me *.dokku.me\" >> /etc/hosts" + sudo /bin/bash -c "[[ `ping -c1 dokku.me > /dev/null 2>&1; echo $$?` -eq 0 ]] || echo \"127.0.0.1 dokku.me *.dokku.me www.test.app.dokku.me\" >> /etc/hosts" @echo "-----> Generating keypair..." mkdir -p /root/.ssh diff --git a/tests/unit/domains.bats b/tests/unit/domains.bats index 67b8cbb72..55e33eb57 100644 --- a/tests/unit/domains.bats +++ b/tests/unit/domains.bats @@ -3,7 +3,7 @@ load test_helper setup() { - deploy_app + create_app } teardown() { diff --git a/tests/unit/ports.bats b/tests/unit/ports.bats index ebafd23a5..9e641eed3 100644 --- a/tests/unit/ports.bats +++ b/tests/unit/ports.bats @@ -66,3 +66,17 @@ teardown() { echo "status: "$status assert_success } + +@test "port exposure (domains:add)" { + 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 +} diff --git a/tests/unit/test_helper.bash b/tests/unit/test_helper.bash index d2b10dd47..763574a8c 100644 --- a/tests/unit/test_helper.bash +++ b/tests/unit/test_helper.bash @@ -90,7 +90,7 @@ destroy_app() { deploy_app() { TMP=$(mktemp -d -t "$TARGET.XXXXX") - rmdir $TMP && cp -r ./tests/apps/config $TMP + rmdir $TMP && cp -r ./tests/apps/nodejs-express $TMP cd $TMP git init git config user.email "robot@example.com"