nginx-vhosts rewrite
This commit is contained in:
@@ -1,10 +1,4 @@
|
||||
FROM ubuntu:trusty
|
||||
ENV LC_ALL C
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
ENV DEBCONF_NONINTERACTIVE_SEEN true
|
||||
|
||||
RUN apt-get install -y software-properties-common && add-apt-repository ppa:chris-lea/node.js && apt-get update
|
||||
RUN apt-get install -y build-essential curl postgresql-client-9.3 nodejs git
|
||||
FROM node:4
|
||||
|
||||
COPY . /app
|
||||
WORKDIR /app
|
||||
|
||||
@@ -1,14 +1,9 @@
|
||||
FROM ubuntu:trusty
|
||||
ENV LC_ALL C
|
||||
ENV DEBIAN_FRONTEND noninteractive
|
||||
ENV DEBCONF_NONINTERACTIVE_SEEN true
|
||||
FROM node:4
|
||||
|
||||
EXPOSE 3001/udp
|
||||
EXPOSE 3000/tcp
|
||||
EXPOSE 3003
|
||||
|
||||
RUN apt-get install -y software-properties-common && add-apt-repository ppa:chris-lea/node.js && apt-get update
|
||||
RUN apt-get install -y build-essential curl postgresql-client-9.3 nodejs git
|
||||
|
||||
COPY . /app
|
||||
WORKDIR /app
|
||||
RUN npm install
|
||||
|
||||
@@ -11,3 +11,7 @@ app.get('/', function(request, response) {
|
||||
app.listen(app.get('port'), function() {
|
||||
console.log("Node app is running at localhost:" + app.get('port'))
|
||||
})
|
||||
|
||||
app.listen(3003, function() {
|
||||
console.log("Node app is running at localhost:" + 3003)
|
||||
})
|
||||
|
||||
@@ -23,6 +23,7 @@ setup_circle() {
|
||||
# sudo apt-get install -y -q "bash=$(apt-cache show bash | egrep "^Version: 4.3" | head -1 | awk -F: '{ print $2 }' | xargs)"
|
||||
bash --version
|
||||
docker version
|
||||
lsb_release -a
|
||||
# setup .dokkurc
|
||||
sudo -E mkdir -p /home/dokku/.dokkurc
|
||||
sudo -E chown dokku:ubuntu /home/dokku/.dokkurc
|
||||
|
||||
45
tests/unit/10_checks.bats
Normal file
45
tests/unit/10_checks.bats
Normal file
@@ -0,0 +1,45 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
create_app
|
||||
}
|
||||
|
||||
teardown() {
|
||||
destroy_app
|
||||
}
|
||||
|
||||
@test "(checks) checks" {
|
||||
run bash -c "dokku checks $TEST_APP | grep -q true"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "(checks) checks:disable" {
|
||||
dokku checks:disable $TEST_APP
|
||||
assert_success
|
||||
|
||||
run bash -c "dokku config:get $TEST_APP DOKKU_CHECKS_ENABLED"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_output "0"
|
||||
}
|
||||
|
||||
@test "(checks) checks:enable" {
|
||||
dokku checks:disable $TEST_APP
|
||||
assert_success
|
||||
|
||||
dokku checks:enable $TEST_APP
|
||||
assert_success
|
||||
|
||||
run bash -c "dokku config:get $TEST_APP DOKKU_CHECKS_ENABLED"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_output "1"
|
||||
}
|
||||
@@ -4,12 +4,12 @@ load test_helper
|
||||
|
||||
setup() {
|
||||
create_app
|
||||
DOCKERFILE="$BATS_TMPDIR/Dockerfile"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
rm -rf /home/dokku/$TEST_APP/tls /home/dokku/tls
|
||||
destroy_app
|
||||
disable_tls_wildcard
|
||||
dokku config:unset --global DOKKU_RM_CONTAINER
|
||||
}
|
||||
|
||||
@@ -120,3 +120,29 @@ build_nginx_config() {
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "(core) port exposure (dockerfile raw port)" {
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
cat<<EOF > $DOCKERFILE
|
||||
EXPOSE 3001/udp
|
||||
EXPOSE 3003
|
||||
EXPOSE 3000/tcp
|
||||
EOF
|
||||
run get_dockerfile_exposed_ports $DOCKERFILE
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_output "3001/udp 3003 3000/tcp"
|
||||
}
|
||||
|
||||
@test "(core) port exposure (dockerfile tcp port)" {
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
cat<<EOF > $DOCKERFILE
|
||||
EXPOSE 3001/udp
|
||||
EXPOSE 3000/tcp
|
||||
EXPOSE 3003
|
||||
EOF
|
||||
run get_dockerfile_exposed_ports $DOCKERFILE
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_output "3001/udp 3000/tcp 3003"
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ deploy_app_tar() {
|
||||
@test "(tar) non-tarbomb deploy using tar:in" {
|
||||
deploy_app_tar nodejs-express --transform 's,^,prefix/,'
|
||||
|
||||
run bash -c "response=\"$(curl -s -S my-cool-guy-test-app.dokku.me)\"; echo \$response; test \"\$response\" == \"nodejs/express\""
|
||||
run bash -c "response=\"$(curl -s -S ${TEST_APP}.dokku.me)\"; echo \$response; test \"\$response\" == \"nodejs/express\""
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
@@ -32,7 +32,7 @@ deploy_app_tar() {
|
||||
@test "(tar) tarbomb deploy using tar:in" {
|
||||
deploy_app_tar nodejs-express
|
||||
|
||||
run bash -c "response=\"$(curl -s -S my-cool-guy-test-app.dokku.me)\"; echo \$response; test \"\$response\" == \"nodejs/express\""
|
||||
run bash -c "response=\"$(curl -s -S ${TEST_APP}.dokku.me)\"; echo \$response; test \"\$response\" == \"nodejs/express\""
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
|
||||
@@ -70,6 +70,10 @@ teardown() {
|
||||
}
|
||||
|
||||
@test "(client) domains" {
|
||||
run bash -c "./contrib/dokku_client.sh domains:setup $TEST_APP"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
run bash -c "./contrib/dokku_client.sh domains $TEST_APP | grep -q ${TEST_APP}.dokku.me"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
|
||||
@@ -1,91 +0,0 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
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"
|
||||
DOCKERFILE="$BATS_TMPDIR/Dockerfile"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
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"
|
||||
}
|
||||
|
||||
|
||||
check_urls() {
|
||||
local PATTERN="$1"
|
||||
run bash -c "dokku --quiet urls $TEST_APP | egrep \"${1}\""
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "(core) port exposure (with global VHOST)" {
|
||||
echo "dokku.me" > "$DOKKU_ROOT/VHOST"
|
||||
deploy_app
|
||||
CONTAINER_ID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1)
|
||||
run bash -c "docker port $CONTAINER_ID | sed 's/[0-9.]*://' | egrep -q '[0-9]*'"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_failure
|
||||
|
||||
check_urls http://${TEST_APP}.dokku.me
|
||||
}
|
||||
|
||||
@test "(core) port exposure (without global VHOST and real HOSTNAME)" {
|
||||
rm "$DOKKU_ROOT/VHOST"
|
||||
echo "${TEST_APP}.dokku.me" > "$DOKKU_ROOT/HOSTNAME"
|
||||
deploy_app
|
||||
CONTAINER_ID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1)
|
||||
run bash -c "docker port $CONTAINER_ID | sed 's/[0-9.]*://' | egrep -q '[0-9]*'"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
|
||||
HOSTNAME=$(< "$DOKKU_ROOT/HOSTNAME")
|
||||
check_urls http://${HOSTNAME}:[0-9]+
|
||||
}
|
||||
|
||||
@test "(core) port exposure (with NO_VHOST set)" {
|
||||
deploy_app
|
||||
dokku config:set $TEST_APP NO_VHOST=1
|
||||
CONTAINER_ID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1)
|
||||
run bash -c "docker port $CONTAINER_ID | sed 's/[0-9.]*://' | egrep -q '[0-9]*'"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
|
||||
HOSTNAME=$(< "$DOKKU_ROOT/HOSTNAME")
|
||||
check_urls http://${HOSTNAME}:[0-9]+
|
||||
}
|
||||
|
||||
@test "(core) port exposure (without global VHOST and IPv4 address as HOSTNAME)" {
|
||||
rm "$DOKKU_ROOT/VHOST"
|
||||
echo "127.0.0.1" > "$DOKKU_ROOT/HOSTNAME"
|
||||
deploy_app
|
||||
CONTAINER_ID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1)
|
||||
run bash -c "docker port $CONTAINER_ID | sed 's/[0-9.]*://' | egrep -q '[0-9]*'"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
|
||||
HOSTNAME=$(< "$DOKKU_ROOT/HOSTNAME")
|
||||
check_urls http://${HOSTNAME}:[0-9]+
|
||||
}
|
||||
|
||||
@test "(core) port exposure (without global VHOST and IPv6 address as HOSTNAME)" {
|
||||
rm "$DOKKU_ROOT/VHOST"
|
||||
echo "fda5:c7db:a520:bb6d::aabb:ccdd:eeff" > "$DOKKU_ROOT/HOSTNAME"
|
||||
deploy_app
|
||||
CONTAINER_ID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1)
|
||||
run bash -c "docker port $CONTAINER_ID | sed 's/[0-9.]*://' | egrep -q '[0-9]*'"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
|
||||
HOSTNAME=$(< "$DOKKU_ROOT/HOSTNAME")
|
||||
check_urls http://${HOSTNAME}:[0-9]+
|
||||
}
|
||||
@@ -3,14 +3,19 @@
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
[[ -f "$DOKKU_ROOT/VHOST" ]] && cp -fp "$DOKKU_ROOT/VHOST" "$DOKKU_ROOT/VHOST.bak"
|
||||
[[ -f "$DOKKU_ROOT/HOSTNAME" ]] && cp -fp "$DOKKU_ROOT/HOSTNAME" "$DOKKU_ROOT/HOSTNAME.bak"
|
||||
create_app
|
||||
}
|
||||
|
||||
teardown() {
|
||||
destroy_app
|
||||
[[ -f "$DOKKU_ROOT/VHOST.bak" ]] && mv "$DOKKU_ROOT/VHOST.bak" "$DOKKU_ROOT/VHOST" && chown dokku:dokku "$DOKKU_ROOT/VHOST"
|
||||
[[ -f "$DOKKU_ROOT/HOSTNAME.bak" ]] && mv "$DOKKU_ROOT/HOSTNAME.bak" "$DOKKU_ROOT/HOSTNAME" && chown dokku:dokku "$DOKKU_ROOT/HOSTNAME"
|
||||
}
|
||||
|
||||
@test "(domains) domains" {
|
||||
dokku domains:setup $TEST_APP
|
||||
run bash -c "dokku domains $TEST_APP | grep ${TEST_APP}.dokku.me"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
@@ -35,6 +40,18 @@ teardown() {
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "(domains) domains:add (duplicate)" {
|
||||
run dokku domains:add $TEST_APP test.app.dokku.me
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
|
||||
run dokku domains:add $TEST_APP test.app.dokku.me
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_failure
|
||||
}
|
||||
|
||||
@test "(domains) domains:remove" {
|
||||
run dokku domains:add $TEST_APP test.app.dokku.me
|
||||
echo "output: "$output
|
||||
@@ -67,3 +84,15 @@ teardown() {
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "(domains) domains:set-global" {
|
||||
run dokku domains:set-global global.dokku.me
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
|
||||
run bash -c "dokku domains | grep -q global.dokku.me"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
}
|
||||
|
||||
124
tests/unit/20_nginx-vhosts_1.bats
Normal file
124
tests/unit/20_nginx-vhosts_1.bats
Normal file
@@ -0,0 +1,124 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions"
|
||||
|
||||
setup() {
|
||||
[[ -f "$DOKKU_ROOT/VHOST" ]] && cp -fp "$DOKKU_ROOT/VHOST" "$DOKKU_ROOT/VHOST.bak"
|
||||
[[ -f "$DOKKU_ROOT/HOSTNAME" ]] && cp -fp "$DOKKU_ROOT/HOSTNAME" "$DOKKU_ROOT/HOSTNAME.bak"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
destroy_app
|
||||
[[ -f "$DOKKU_ROOT/VHOST.bak" ]] && mv "$DOKKU_ROOT/VHOST.bak" "$DOKKU_ROOT/VHOST" && chown dokku:dokku "$DOKKU_ROOT/VHOST"
|
||||
[[ -f "$DOKKU_ROOT/HOSTNAME.bak" ]] && mv "$DOKKU_ROOT/HOSTNAME.bak" "$DOKKU_ROOT/HOSTNAME" && chown dokku:dokku "$DOKKU_ROOT/HOSTNAME"
|
||||
}
|
||||
|
||||
@test "(nginx-vhosts) nginx:build-config (domains:disable/enable)" {
|
||||
deploy_app
|
||||
dokku domains:disable $TEST_APP
|
||||
|
||||
HOSTNAME=$(< "$DOKKU_ROOT/HOSTNAME")
|
||||
check_urls http://${HOSTNAME}:[0-9]+
|
||||
|
||||
NGINX_PORT="$(config_get $TEST_APP DOKKU_NGINX_PORT)"
|
||||
assert_http_success http://${HOSTNAME}:${NGINX_PORT}
|
||||
|
||||
dokku domains:enable $TEST_APP
|
||||
check_urls http://${TEST_APP}.dokku.me
|
||||
assert_http_success http://${TEST_APP}.dokku.me
|
||||
}
|
||||
|
||||
@test "(nginx-vhosts) nginx:build-config (domains:add pre deploy)" {
|
||||
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
|
||||
|
||||
check_urls http://www.test.app.dokku.me
|
||||
assert_http_success http://www.test.app.dokku.me
|
||||
}
|
||||
|
||||
@test "(nginx-vhosts) nginx:build-config (with global VHOST)" {
|
||||
echo "dokku.me" > "$DOKKU_ROOT/VHOST"
|
||||
deploy_app
|
||||
|
||||
check_urls http://${TEST_APP}.dokku.me
|
||||
assert_http_success http://${TEST_APP}.dokku.me
|
||||
}
|
||||
|
||||
@test "(nginx-vhosts) nginx:build-config (without global VHOST but real HOSTNAME)" {
|
||||
rm "$DOKKU_ROOT/VHOST"
|
||||
echo "${TEST_APP}.dokku.me" > "$DOKKU_ROOT/HOSTNAME"
|
||||
deploy_app
|
||||
|
||||
HOSTNAME=$(< "$DOKKU_ROOT/HOSTNAME")
|
||||
check_urls http://${HOSTNAME}:[0-9]+
|
||||
|
||||
NGINX_PORT="$(config_get $TEST_APP DOKKU_NGINX_PORT)"
|
||||
assert_http_success http://${HOSTNAME}:${NGINX_PORT}
|
||||
}
|
||||
|
||||
@test "(nginx-vhosts) nginx:build-config (without global VHOST and IPv4 address set as HOSTNAME)" {
|
||||
rm "$DOKKU_ROOT/VHOST"
|
||||
echo "127.0.0.1" > "$DOKKU_ROOT/HOSTNAME"
|
||||
deploy_app
|
||||
|
||||
HOSTNAME=$(< "$DOKKU_ROOT/HOSTNAME")
|
||||
check_urls http://${HOSTNAME}:[0-9]+
|
||||
|
||||
NGINX_PORT="$(config_get $TEST_APP DOKKU_NGINX_PORT)"
|
||||
assert_http_success http://${HOSTNAME}:${NGINX_PORT}
|
||||
}
|
||||
|
||||
@test "(nginx-vhosts) nginx:build-config (without global VHOST and IPv6 address set as HOSTNAME)" {
|
||||
rm "$DOKKU_ROOT/VHOST"
|
||||
echo "fda5:c7db:a520:bb6d::aabb:ccdd:eeff" > "$DOKKU_ROOT/HOSTNAME"
|
||||
deploy_app
|
||||
|
||||
HOSTNAME=$(< "$DOKKU_ROOT/HOSTNAME")
|
||||
check_urls http://${HOSTNAME}:[0-9]+
|
||||
}
|
||||
|
||||
@test "(nginx-vhosts) nginx:build-config (without global VHOST and domains:add pre deploy)" {
|
||||
rm "$DOKKU_ROOT/VHOST"
|
||||
create_app
|
||||
add_domain "www.test.app.dokku.me"
|
||||
deploy_app
|
||||
assert_nonssl_domain "www.test.app.dokku.me"
|
||||
}
|
||||
|
||||
@test "(nginx-vhosts) nginx:build-config (without global VHOST and domains:add post deploy)" {
|
||||
rm "$DOKKU_ROOT/VHOST"
|
||||
deploy_app
|
||||
add_domain "www.test.app.dokku.me"
|
||||
check_urls http://www.test.app.dokku.me
|
||||
assert_http_success http://www.test.app.dokku.me
|
||||
}
|
||||
|
||||
@test "(nginx-vhosts) nginx:build-config (xip.io style hostnames)" {
|
||||
echo "127.0.0.1.xip.io" > "$DOKKU_ROOT/VHOST"
|
||||
deploy_app
|
||||
|
||||
check_urls http://${TEST_APP}.127.0.0.1.xip.io
|
||||
assert_http_success http://${TEST_APP}.127.0.0.1.xip.io
|
||||
}
|
||||
|
||||
@test "(nginx-vhosts) nginx:build-config (dockerfile expose)" {
|
||||
deploy_app dockerfile
|
||||
|
||||
add_domain "www.test.app.dokku.me"
|
||||
check_urls http://${TEST_APP}.dokku.me:3000
|
||||
check_urls http://${TEST_APP}.dokku.me:3003
|
||||
check_urls http://www.test.app.dokku.me:3000
|
||||
check_urls http://www.test.app.dokku.me:3003
|
||||
assert_http_success http://${TEST_APP}.dokku.me:3000
|
||||
assert_http_success http://${TEST_APP}.dokku.me:3003
|
||||
assert_http_success http://www.test.app.dokku.me:3000
|
||||
assert_http_success http://www.test.app.dokku.me:3003
|
||||
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
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"
|
||||
DOCKERFILE="$BATS_TMPDIR/Dockerfile"
|
||||
}
|
||||
|
||||
teardown() {
|
||||
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"
|
||||
}
|
||||
|
||||
|
||||
check_urls() {
|
||||
local PATTERN="$1"
|
||||
run bash -c "dokku --quiet urls $TEST_APP | egrep \"${1}\""
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
}
|
||||
|
||||
@test "(core) port exposure (pre-deploy 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
|
||||
|
||||
CONTAINER_ID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1)
|
||||
run bash -c "docker port $CONTAINER_ID | sed 's/[0-9.]*://' | egrep -q '[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
|
||||
|
||||
check_urls http://www.test.app.dokku.me
|
||||
}
|
||||
|
||||
@test "(core) 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
|
||||
|
||||
run dokku ps:restart $TEST_APP
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
|
||||
CONTAINER_ID=$(< $DOKKU_ROOT/$TEST_APP/CONTAINER.web.1)
|
||||
run bash -c "docker port $CONTAINER_ID | sed 's/[0-9.]*://' | egrep -q '[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
|
||||
|
||||
check_urls http://www.test.app.dokku.me
|
||||
}
|
||||
|
||||
@test "(core) port exposure (xip.io style hostnames)" {
|
||||
echo "127.0.0.1.xip.io" > "$DOKKU_ROOT/VHOST"
|
||||
deploy_app
|
||||
|
||||
run bash -c "response=\"$(curl -s -S my-cool-guy-test-app.127.0.0.1.xip.io)\"; echo \$response; test \"\$response\" == \"nodejs/express\""
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
|
||||
check_urls http://my-cool-guy-test-app.127.0.0.1.xip.io
|
||||
}
|
||||
|
||||
@test "(core) dockerfile port exposure" {
|
||||
deploy_app dockerfile
|
||||
run bash -c "grep -A1 upstream $DOKKU_ROOT/$TEST_APP/nginx.conf | grep -q 3000"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
|
||||
check_urls http://${TEST_APP}.dokku.me
|
||||
}
|
||||
|
||||
@test "(core) port exposure (dockerfile raw port)" {
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
cat<<EOF > $DOCKERFILE
|
||||
EXPOSE 3001/udp
|
||||
EXPOSE 3003
|
||||
EXPOSE 3000/tcp
|
||||
EOF
|
||||
run get_dockerfile_exposed_port $DOCKERFILE
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_output 3003
|
||||
}
|
||||
|
||||
@test "(core) port exposure (dockerfile tcp port)" {
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/common/functions"
|
||||
cat<<EOF > $DOCKERFILE
|
||||
EXPOSE 3001/udp
|
||||
EXPOSE 3000/tcp
|
||||
EXPOSE 3003
|
||||
EOF
|
||||
run get_dockerfile_exposed_port $DOCKERFILE
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_output 3000
|
||||
}
|
||||
@@ -9,7 +9,6 @@ setup() {
|
||||
teardown() {
|
||||
rm -rf /home/dokku/$TEST_APP/tls /home/dokku/tls
|
||||
destroy_app
|
||||
disable_tls_wildcard
|
||||
}
|
||||
|
||||
assert_urls() {
|
||||
@@ -17,6 +16,7 @@ assert_urls() {
|
||||
run dokku urls $TEST_APP
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
echo "urls:" $(tr ' ' '\n' <<< "${urls}")
|
||||
assert_output < <(tr ' ' '\n' <<< "${urls}")
|
||||
}
|
||||
|
||||
@@ -50,27 +50,27 @@ build_nginx_config() {
|
||||
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"
|
||||
assert_urls "http://test.dokku.me" "http://${TEST_APP}.dokku.me"
|
||||
}
|
||||
|
||||
@test "(core) urls (app ssl)" {
|
||||
setup_test_tls
|
||||
assert_urls "https://dokku.me"
|
||||
build_nginx_config
|
||||
assert_urls "http://${TEST_APP}.dokku.me"
|
||||
assert_urls "https://${TEST_APP}.dokku.me"
|
||||
add_domain "test.dokku.me"
|
||||
assert_urls "http://${TEST_APP}.dokku.me" "http://test.dokku.me"
|
||||
assert_urls "https://test.dokku.me" "https://${TEST_APP}.dokku.me"
|
||||
}
|
||||
|
||||
@test "(core) urls (wildcard ssl)" {
|
||||
setup_test_tls_wildcard
|
||||
setup_test_tls wildcard
|
||||
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"
|
||||
assert_urls "https://test.dokku.me" "https://${TEST_APP}.dokku.me"
|
||||
add_domain "dokku.example.com"
|
||||
assert_urls "https://${TEST_APP}.dokku.me" "https://test.dokku.me" "http://dokku.example.com"
|
||||
assert_urls "https://dokku.example.com" "https://test.dokku.me" "https://${TEST_APP}.dokku.me"
|
||||
}
|
||||
|
||||
@test "(core) git-remote (off-port)" {
|
||||
|
||||
@@ -1,56 +1,18 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
source "$PLUGIN_CORE_AVAILABLE_PATH/config/functions"
|
||||
|
||||
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"
|
||||
[[ -f "$DOKKU_ROOT/VHOST" ]] && cp -fp "$DOKKU_ROOT/VHOST" "$DOKKU_ROOT/VHOST.bak"
|
||||
[[ -f "$DOKKU_ROOT/HOSTNAME" ]] && cp -fp "$DOKKU_ROOT/HOSTNAME" "$DOKKU_ROOT/HOSTNAME.bak"
|
||||
create_app
|
||||
}
|
||||
|
||||
teardown() {
|
||||
destroy_app 0 $TEST_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"
|
||||
disable_tls_wildcard
|
||||
}
|
||||
|
||||
assert_ssl_domain() {
|
||||
local domain=$1
|
||||
assert_app_domain "${domain}"
|
||||
assert_http_redirect "http://${domain}" "https://${domain}:443/"
|
||||
assert_http_success "https://${domain}"
|
||||
}
|
||||
|
||||
assert_nonssl_domain() {
|
||||
local domain=$1
|
||||
assert_app_domain "${domain}"
|
||||
assert_http_success "http://${domain}"
|
||||
}
|
||||
|
||||
assert_app_domain() {
|
||||
local domain=$1
|
||||
run /bin/bash -c "dokku domains $TEST_APP | grep -xF ${domain}"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_output "${domain}"
|
||||
}
|
||||
|
||||
assert_http_redirect() {
|
||||
local from=$1
|
||||
local to=$2
|
||||
run curl -kSso /dev/null -w "%{redirect_url}" "${from}"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_output "${to}"
|
||||
}
|
||||
|
||||
assert_http_success() {
|
||||
local url=$1
|
||||
run curl -kSso /dev/null -w "%{http_code}" "${url}"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_output "200"
|
||||
[[ -f "$DOKKU_ROOT/VHOST.bak" ]] && mv "$DOKKU_ROOT/VHOST.bak" "$DOKKU_ROOT/VHOST" && chown dokku:dokku "$DOKKU_ROOT/VHOST"
|
||||
[[ -f "$DOKKU_ROOT/HOSTNAME.bak" ]] && mv "$DOKKU_ROOT/HOSTNAME.bak" "$DOKKU_ROOT/HOSTNAME" && chown dokku:dokku "$DOKKU_ROOT/HOSTNAME"
|
||||
}
|
||||
|
||||
assert_access_log() {
|
||||
@@ -80,38 +42,26 @@ assert_error_log() {
|
||||
}
|
||||
|
||||
@test "(nginx-vhosts) nginx:build-config (wildcard SSL)" {
|
||||
setup_test_tls_wildcard
|
||||
setup_test_tls wildcard
|
||||
add_domain "wildcard1.dokku.me"
|
||||
add_domain "wildcard2.dokku.me"
|
||||
add_domain "www.test.dokku.me"
|
||||
deploy_app
|
||||
cat /home/dokku/${TEST_APP}/nginx.conf
|
||||
assert_ssl_domain "wildcard1.dokku.me"
|
||||
assert_ssl_domain "wildcard2.dokku.me"
|
||||
assert_nonssl_domain "www.test.dokku.me"
|
||||
}
|
||||
|
||||
@test "(nginx-vhosts) nginx:build-config (wildcard SSL & custom nginx template)" {
|
||||
setup_test_tls_wildcard
|
||||
add_domain "wildcard1.dokku.me"
|
||||
add_domain "wildcard2.dokku.me"
|
||||
custom_ssl_nginx_template
|
||||
deploy_app
|
||||
assert_ssl_domain "wildcard1.dokku.me"
|
||||
assert_ssl_domain "wildcard2.dokku.me"
|
||||
assert_http_success "customssltemplate.dokku.me"
|
||||
}
|
||||
|
||||
@test "(nginx-vhosts) nginx:build-config (wildcard SSL & unrelated domain)" {
|
||||
destroy_app
|
||||
TEST_APP="${TEST_APP}.example.com"
|
||||
setup_test_tls_wildcard
|
||||
setup_test_tls wildcard
|
||||
deploy_app nodejs-express dokku@dokku.me:$TEST_APP
|
||||
run /bin/bash -c "egrep '*.dokku.me' $DOKKU_ROOT/${TEST_APP}/nginx.conf | wc -l"
|
||||
assert_output "0"
|
||||
}
|
||||
|
||||
@test "(nginx-vhosts) nginx:build-config (with SSL and Multiple SANs)" {
|
||||
setup_test_tls_with_sans
|
||||
setup_test_tls sans
|
||||
add_domain "test.dokku.me"
|
||||
add_domain "www.test.dokku.me"
|
||||
add_domain "www.test.app.dokku.me"
|
||||
@@ -121,27 +71,36 @@ assert_error_log() {
|
||||
assert_ssl_domain "www.test.app.dokku.me"
|
||||
}
|
||||
|
||||
@test "(nginx-vhosts) nginx:build-config (custom nginx template)" {
|
||||
@test "(nginx-vhosts) nginx:build-config (wildcard SSL & custom nginx template)" {
|
||||
setup_test_tls wildcard
|
||||
add_domain "wildcard1.dokku.me"
|
||||
add_domain "wildcard2.dokku.me"
|
||||
deploy_app nodejs-express dokku@dokku.me:$TEST_APP custom_ssl_nginx_template
|
||||
assert_ssl_domain "wildcard1.dokku.me"
|
||||
assert_ssl_domain "wildcard2.dokku.me"
|
||||
assert_http_redirect "http://${CUSTOM_TEMPLATE_SSL_DOMAIN}" "https://${CUSTOM_TEMPLATE_SSL_DOMAIN}:443/"
|
||||
assert_http_success "https://${CUSTOM_TEMPLATE_SSL_DOMAIN}"
|
||||
}
|
||||
|
||||
@test "(nginx-vhosts) nginx:build-config (custom nginx template - default path)" {
|
||||
add_domain "www.test.app.dokku.me"
|
||||
custom_nginx_template
|
||||
deploy_app
|
||||
deploy_app nodejs-express dokku@dokku.me:$TEST_APP custom_nginx_template
|
||||
assert_nonssl_domain "www.test.app.dokku.me"
|
||||
assert_http_success "customtemplate.dokku.me"
|
||||
}
|
||||
|
||||
@test "(nginx-vhosts) nginx:build-config (no global VHOST and domains:add)" {
|
||||
destroy_app
|
||||
rm "$DOKKU_ROOT/VHOST"
|
||||
create_app
|
||||
@test "(nginx-vhosts) nginx:build-config (custom nginx template - custom path)" {
|
||||
add_domain "www.test.app.dokku.me"
|
||||
deploy_app
|
||||
dokku config:set --no-restart $TEST_APP NGINX_CUSTOM_TEMPLATE_PATH=/app/.dokku
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
deploy_app nodejs-express dokku@dokku.me:$TEST_APP custom_nginx_template .dokku/
|
||||
assert_nonssl_domain "www.test.app.dokku.me"
|
||||
assert_http_success "customtemplate.dokku.me"
|
||||
}
|
||||
|
||||
@test "(nginx-vhosts) nginx:build-config (validate_nginx)" {
|
||||
deploy_app
|
||||
echo "some lame nginx config" > "$DOKKU_ROOT/$TEST_APP/nginx.conf.template"
|
||||
run /bin/bash -c "dokku nginx:build-config $TEST_APP"
|
||||
@test "(nginx-vhosts) nginx:build-config (failed validate_nginx)" {
|
||||
run deploy_app nodejs-express dokku@dokku.me:$TEST_APP bad_custom_nginx_template
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_failure
|
||||
64
tests/unit/40_proxy.bats
Normal file
64
tests/unit/40_proxy.bats
Normal file
@@ -0,0 +1,64 @@
|
||||
#!/usr/bin/env bats
|
||||
|
||||
load test_helper
|
||||
|
||||
setup() {
|
||||
[[ -f "$DOKKU_ROOT/VHOST" ]] && cp -fp "$DOKKU_ROOT/VHOST" "$DOKKU_ROOT/VHOST.bak"
|
||||
[[ -f "$DOKKU_ROOT/HOSTNAME" ]] && cp -fp "$DOKKU_ROOT/HOSTNAME" "$DOKKU_ROOT/HOSTNAME.bak"
|
||||
create_app
|
||||
}
|
||||
|
||||
teardown() {
|
||||
destroy_app 0 $TEST_APP
|
||||
[[ -f "$DOKKU_ROOT/VHOST.bak" ]] && mv "$DOKKU_ROOT/VHOST.bak" "$DOKKU_ROOT/VHOST" && chown dokku:dokku "$DOKKU_ROOT/VHOST"
|
||||
[[ -f "$DOKKU_ROOT/HOSTNAME.bak" ]] && mv "$DOKKU_ROOT/HOSTNAME.bak" "$DOKKU_ROOT/HOSTNAME" && chown dokku:dokku "$DOKKU_ROOT/HOSTNAME"
|
||||
}
|
||||
|
||||
assert_nonssl_domain() {
|
||||
local domain=$1
|
||||
assert_app_domain "${domain}"
|
||||
assert_http_success "http://${domain}"
|
||||
}
|
||||
|
||||
assert_app_domain() {
|
||||
local domain=$1
|
||||
run /bin/bash -c "dokku domains $TEST_APP | grep -xF ${domain}"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_output "${domain}"
|
||||
}
|
||||
|
||||
assert_external_port() {
|
||||
local CID="$1"; local exit_status="$2"
|
||||
local EXTERNAL_PORT_COUNT=$(docker port $CID | wc -l)
|
||||
run /bin/bash -c "[[ $EXTERNAL_PORT_COUNT -gt 0 ]]"
|
||||
if [[ "$exit_status" == "success" ]]; then
|
||||
assert_success
|
||||
else
|
||||
assert_failure
|
||||
fi
|
||||
}
|
||||
|
||||
@test "(proxy) proxy:enable/disable" {
|
||||
deploy_app
|
||||
assert_nonssl_domain "${TEST_APP}.dokku.me"
|
||||
|
||||
run dokku proxy:disable $TEST_APP
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
|
||||
for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.web.*; do
|
||||
assert_external_port $(< $CID_FILE) success
|
||||
done
|
||||
|
||||
run dokku proxy:enable $TEST_APP
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
assert_http_success "${TEST_APP}.dokku.me"
|
||||
|
||||
for CID_FILE in $DOKKU_ROOT/$TEST_APP/CONTAINER.web.*; do
|
||||
assert_external_port $(< $CID_FILE) failure
|
||||
done
|
||||
}
|
||||
@@ -8,7 +8,8 @@ PLUGIN_AVAILABLE_PATH=${PLUGIN_AVAILABLE_PATH:="$PLUGIN_PATH/available"}
|
||||
PLUGIN_ENABLED_PATH=${PLUGIN_ENABLED_PATH:="$PLUGIN_PATH/enabled"}
|
||||
PLUGIN_CORE_PATH=${PLUGIN_CORE_PATH:="$DOKKU_LIB_ROOT/core-plugins"}
|
||||
PLUGIN_CORE_AVAILABLE_PATH=${PLUGIN_CORE_AVAILABLE_PATH:="$PLUGIN_CORE_PATH/available"}
|
||||
TEST_APP=my-cool-guy-test-app
|
||||
TEST_APP=testsuiteapp
|
||||
CUSTOM_TEMPLATE_SSL_DOMAIN=customssltemplate.dokku.me
|
||||
|
||||
# test functions
|
||||
flunk() {
|
||||
@@ -21,6 +22,7 @@ flunk() {
|
||||
|
||||
# ShellCheck doesn't know about $status from Bats
|
||||
# shellcheck disable=SC2154
|
||||
# shellcheck disable=SC2120
|
||||
assert_success() {
|
||||
if [[ "$status" -ne 0 ]]; then
|
||||
flunk "command failed with exit status $status"
|
||||
@@ -115,8 +117,7 @@ create_app() {
|
||||
|
||||
destroy_app() {
|
||||
local RC="$1"; local RC=${RC:=0}
|
||||
local TEST_APP="$2"; local TEST_APP=${TEST_APP:=my-cool-guy-test-app}
|
||||
echo $TEST_APP | dokku apps:destroy $TEST_APP
|
||||
dokku --force apps:destroy $TEST_APP
|
||||
return $RC
|
||||
}
|
||||
|
||||
@@ -124,12 +125,62 @@ add_domain() {
|
||||
dokku domains:add $TEST_APP $1
|
||||
}
|
||||
|
||||
# shellcheck disable=SC2119
|
||||
check_urls() {
|
||||
local PATTERN="$1"
|
||||
run bash -c "dokku --quiet urls $TEST_APP | egrep \"${1}\""
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_success
|
||||
}
|
||||
|
||||
assert_http_success() {
|
||||
local url=$1
|
||||
run curl -kSso /dev/null -w "%{http_code}" "${url}"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_output "200"
|
||||
}
|
||||
|
||||
assert_ssl_domain() {
|
||||
local domain=$1
|
||||
assert_app_domain "${domain}"
|
||||
assert_http_redirect "http://${domain}" "https://${domain}:443/"
|
||||
assert_http_success "https://${domain}"
|
||||
}
|
||||
|
||||
assert_nonssl_domain() {
|
||||
local domain=$1
|
||||
assert_app_domain "${domain}"
|
||||
assert_http_success "http://${domain}"
|
||||
}
|
||||
|
||||
assert_app_domain() {
|
||||
local domain=$1
|
||||
run /bin/bash -c "dokku domains $TEST_APP | grep -xF ${domain}"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_output "${domain}"
|
||||
}
|
||||
|
||||
assert_http_redirect() {
|
||||
local from=$1
|
||||
local to=$2
|
||||
run curl -kSso /dev/null -w "%{redirect_url}" "${from}"
|
||||
echo "output: "$output
|
||||
echo "status: "$status
|
||||
assert_output "${to}"
|
||||
}
|
||||
|
||||
deploy_app() {
|
||||
APP_TYPE="$1"; APP_TYPE=${APP_TYPE:="nodejs-express"}
|
||||
GIT_REMOTE="$2"; GIT_REMOTE=${GIT_REMOTE:="dokku@dokku.me:$TEST_APP"}
|
||||
TMP=$(mktemp -d -t "dokku.me.XXXXX")
|
||||
local APP_TYPE="$1"; local APP_TYPE=${APP_TYPE:="nodejs-express"}
|
||||
local GIT_REMOTE="$2"; local GIT_REMOTE=${GIT_REMOTE:="dokku@dokku.me:$TEST_APP"}
|
||||
local CUSTOM_TEMPLATE="$3"; local TMP=$(mktemp -d -t "dokku.me.XXXXX")
|
||||
local CUSTOM_PATH="$4"
|
||||
|
||||
rmdir $TMP && cp -r ./tests/apps/$APP_TYPE $TMP
|
||||
cd $TMP || exit 1
|
||||
[[ -n "$CUSTOM_TEMPLATE" ]] && $CUSTOM_TEMPLATE $TEST_APP $TMP/$CUSTOM_PATH
|
||||
git init
|
||||
git config user.email "robot@example.com"
|
||||
git config user.name "Test Robot"
|
||||
@@ -143,7 +194,7 @@ deploy_app() {
|
||||
}
|
||||
|
||||
setup_client_repo() {
|
||||
TMP=$(mktemp -d -t "dokku.me.XXXXX")
|
||||
local TMP=$(mktemp -d -t "dokku.me.XXXXX")
|
||||
rmdir $TMP && cp -r ./tests/apps/nodejs-express $TMP
|
||||
cd $TMP || exit 1
|
||||
git init
|
||||
@@ -156,93 +207,114 @@ setup_client_repo() {
|
||||
}
|
||||
|
||||
setup_test_tls() {
|
||||
TLS="/home/dokku/$TEST_APP/tls"
|
||||
local TLS_TYPE="$1"; local TLS="/home/dokku/$TEST_APP/tls"
|
||||
mkdir -p $TLS
|
||||
tar xf $BATS_TEST_DIRNAME/server_ssl.tar -C $TLS
|
||||
sudo chown -R dokku:dokku $TLS
|
||||
}
|
||||
|
||||
setup_test_tls_with_sans() {
|
||||
TLS="/home/dokku/$TEST_APP/tls"
|
||||
mkdir -p $TLS
|
||||
tar xf $BATS_TEST_DIRNAME/server_ssl_sans.tar -C $TLS
|
||||
sudo chown -R dokku:dokku $TLS
|
||||
}
|
||||
|
||||
setup_test_tls_wildcard() {
|
||||
TLS="/home/dokku/tls"
|
||||
mkdir -p $TLS
|
||||
tar xf $BATS_TEST_DIRNAME/server_ssl_wildcard.tar -C $TLS
|
||||
sudo chown -R dokku:dokku $TLS
|
||||
sed -i -e "s:^# ssl_certificate $DOKKU_ROOT/tls/server.crt;:ssl_certificate $DOKKU_ROOT/tls/server.crt;:g" \
|
||||
-e "s:^# ssl_certificate_key $DOKKU_ROOT/tls/server.key;:ssl_certificate_key $DOKKU_ROOT/tls/server.key;:g" /etc/nginx/conf.d/dokku.conf
|
||||
kill -HUP "$(< /var/run/nginx.pid)"; sleep 5
|
||||
}
|
||||
|
||||
disable_tls_wildcard() {
|
||||
TLS="/home/dokku/tls"
|
||||
rm -rf $TLS
|
||||
sed -i -e "s:^ssl_certificate $DOKKU_ROOT/tls/server.crt;:# ssl_certificate $DOKKU_ROOT/tls/server.crt;:g" \
|
||||
-e "s:^ssl_certificate_key $DOKKU_ROOT/tls/server.key;:# ssl_certificate_key $DOKKU_ROOT/tls/server.key;:g" /etc/nginx/conf.d/dokku.conf
|
||||
kill -HUP "$(< /var/run/nginx.pid)"; sleep 5
|
||||
case "$TLS_TYPE" in
|
||||
wildcard)
|
||||
local TLS_ARCHIVE=server_ssl_wildcard.tar
|
||||
;;
|
||||
sans)
|
||||
local TLS_ARCHIVE=server_ssl_sans.tar
|
||||
;;
|
||||
*)
|
||||
local TLS_ARCHIVE=server_ssl.tar
|
||||
;;
|
||||
esac
|
||||
tar xf $BATS_TEST_DIRNAME/$TLS_ARCHIVE -C $TLS
|
||||
sudo chown -R dokku:dokku ${TLS}/..
|
||||
}
|
||||
|
||||
custom_ssl_nginx_template() {
|
||||
APP="$1"
|
||||
[[ -z "$APP" ]] && APP="$TEST_APP"
|
||||
cat<<EOF > $DOKKU_ROOT/$APP/nginx.conf.template
|
||||
local APP="$1"; local APP_REPO_DIR="$2"
|
||||
[[ -z "$APP" ]] && local APP="$TEST_APP"
|
||||
mkdir -p $APP_REPO_DIR
|
||||
|
||||
echo "injecting custom_ssl_nginx_template -> $APP_REPO_DIR/nginx.conf.sigil"
|
||||
cat<<EOF > "$APP_REPO_DIR/nginx.conf.sigil"
|
||||
server {
|
||||
listen [::]:\$NGINX_PORT;
|
||||
listen \$NGINX_PORT;
|
||||
server_name \$NOSSL_SERVER_NAME customssltemplate.dokku.me;
|
||||
return 301 https://\\\$host:\$NGINX_SSL_PORT\\\$request_uri;
|
||||
listen [::]:{{ .NGINX_PORT }};
|
||||
listen {{ .NGINX_PORT }};
|
||||
server_name {{ .NOSSL_SERVER_NAME }} $CUSTOM_TEMPLATE_SSL_DOMAIN;
|
||||
return 301 https://\$host:{{ .NGINX_SSL_PORT }}\$request_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen [::]:\$NGINX_SSL_PORT ssl spdy;
|
||||
listen \$NGINX_SSL_PORT ssl spdy;
|
||||
server_name \$SSL_SERVER_NAME customssltemplate.dokku.me;
|
||||
\$SSL_DIRECTIVES
|
||||
listen [::]:{{ .NGINX_SSL_PORT }} ssl spdy;
|
||||
listen {{ .NGINX_SSL_PORT }} ssl spdy;
|
||||
server_name \$SSL_SERVER_NAME $CUSTOM_TEMPLATE_SSL_DOMAIN;
|
||||
ssl_certificate {{ .APP_SSL_PATH }}/server.crt;
|
||||
ssl_certificate_key {{ .APP_SSL_PATH }}/server.key;
|
||||
|
||||
keepalive_timeout 70;
|
||||
add_header Alternate-Protocol \$NGINX_SSL_PORT:npn-spdy/2;
|
||||
add_header Alternate-Protocol {{ .NGINX_SSL_PORT }}:npn-spdy/2;
|
||||
location / {
|
||||
proxy_pass http://\$APP;
|
||||
proxy_pass http://{{ .APP }};
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade \\\$http_upgrade;
|
||||
proxy_set_header Upgrade \$http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host \\\$http_host;
|
||||
proxy_set_header X-Forwarded-Proto \\\$scheme;
|
||||
proxy_set_header X-Forwarded-For \\\$remote_addr;
|
||||
proxy_set_header X-Forwarded-Port \\\$server_port;
|
||||
proxy_set_header X-Request-Start \\\$msec;
|
||||
proxy_set_header Host \$http_host;
|
||||
proxy_set_header X-Forwarded-Proto \$scheme;
|
||||
proxy_set_header X-Forwarded-For \$remote_addr;
|
||||
proxy_set_header X-Forwarded-Port \$server_port;
|
||||
proxy_set_header X-Request-Start \$msec;
|
||||
}
|
||||
include \$DOKKU_ROOT/\$APP/nginx.conf.d/*.conf;
|
||||
include {{ .DOKKU_ROOT }}/{{ .APP }}/nginx.conf.d/*.conf;
|
||||
}
|
||||
{{ if .DOKKU_APP_LISTENERS }}
|
||||
upstream {{ .APP }} {
|
||||
{{ range .DOKKU_APP_LISTENERS | split " " }} server {{ . }};
|
||||
{{ end }}}
|
||||
{{ else if .PASSED_LISTEN_IP_PORT }}
|
||||
upstream {{ .APP }} {
|
||||
server {{ .DOKKU_APP_LISTEN_IP }}:{{ .DOKKU_APP_LISTEN_PORT }};
|
||||
}
|
||||
{{ end }}
|
||||
EOF
|
||||
}
|
||||
|
||||
custom_nginx_template() {
|
||||
APP="$1"
|
||||
[[ -z "$APP" ]] && APP="$TEST_APP"
|
||||
cat<<EOF > $DOKKU_ROOT/$APP/nginx.conf.template
|
||||
local APP="$1"; local APP_REPO_DIR="$2"
|
||||
[[ -z "$APP" ]] && local APP="$TEST_APP"
|
||||
mkdir -p $APP_REPO_DIR
|
||||
|
||||
echo "injecting custom_nginx_template -> $APP_REPO_DIR/nginx.conf.sigil"
|
||||
cat<<EOF > "$APP_REPO_DIR/nginx.conf.sigil"
|
||||
server {
|
||||
listen [::]:\$NGINX_PORT;
|
||||
listen \$NGINX_PORT;
|
||||
server_name \$NOSSL_SERVER_NAME customtemplate.dokku.me;
|
||||
listen [::]:{{ .NGINX_PORT }};
|
||||
listen {{ .NGINX_PORT }};
|
||||
server_name {{ .NOSSL_SERVER_NAME }} customtemplate.dokku.me;
|
||||
|
||||
location / {
|
||||
proxy_pass http://\$APP;
|
||||
proxy_pass http://{{ .APP }};
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade \\\$http_upgrade;
|
||||
proxy_set_header Upgrade \$http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host \\\$http_host;
|
||||
proxy_set_header X-Forwarded-Proto \\\$scheme;
|
||||
proxy_set_header X-Forwarded-For \\\$remote_addr;
|
||||
proxy_set_header X-Forwarded-Port \\\$server_port;
|
||||
proxy_set_header X-Request-Start \\\$msec;
|
||||
proxy_set_header Host \$http_host;
|
||||
proxy_set_header X-Forwarded-Proto \$scheme;
|
||||
proxy_set_header X-Forwarded-For \$remote_addr;
|
||||
proxy_set_header X-Forwarded-Port \$server_port;
|
||||
proxy_set_header X-Request-Start \$msec;
|
||||
}
|
||||
include \$DOKKU_ROOT/\$APP/nginx.conf.d/*.conf;
|
||||
include {{ .DOKKU_ROOT }}/{{ .APP }}/nginx.conf.d/*.conf;
|
||||
}
|
||||
{{ if .DOKKU_APP_LISTENERS }}
|
||||
upstream {{ .APP }} {
|
||||
{{ range .DOKKU_APP_LISTENERS | split " " }} server {{ . }};
|
||||
{{ end }}}
|
||||
{{ else if .PASSED_LISTEN_IP_PORT }}
|
||||
upstream {{ .APP }} {
|
||||
server {{ .DOKKU_APP_LISTEN_IP }}:{{ .DOKKU_APP_LISTEN_PORT }};
|
||||
}
|
||||
{{ end }}
|
||||
EOF
|
||||
}
|
||||
|
||||
bad_custom_nginx_template() {
|
||||
local APP="$1"; local APP_REPO_DIR="$2"
|
||||
[[ -z "$APP" ]] && local APP="$TEST_APP"
|
||||
echo "injecting bad_custom_nginx_template -> $APP_REPO_DIR/nginx.conf.sigil"
|
||||
cat<<EOF > "$APP_REPO_DIR/nginx.conf.sigil"
|
||||
some lame nginx config
|
||||
EOF
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user