From 2c492ceade5409ebd6fed27f25db2b01b65fe887 Mon Sep 17 00:00:00 2001 From: Zeshan Ziya <132985988+zeshanziya@users.noreply.github.com> Date: Tue, 21 Jan 2025 18:38:58 +0530 Subject: [PATCH] fix: use dynamic ports for router and mailpit, fixes #23 (#30) Co-authored-by: Stanislav Zhuk --- docker-compose.varnish.yaml | 6 +++--- tests/test.bats | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/docker-compose.varnish.yaml b/docker-compose.varnish.yaml index 7ecfe7f..9bae021 100644 --- a/docker-compose.varnish.yaml +++ b/docker-compose.varnish.yaml @@ -15,8 +15,8 @@ services: - VIRTUAL_HOST=$DDEV_HOSTNAME # This defines the ports the service should be accessible from at # sitename.ddev.site. - - HTTPS_EXPOSE=443:80,8026:8025 - - HTTP_EXPOSE=80:80,8025:8025 + - HTTPS_EXPOSE=${DDEV_ROUTER_HTTPS_PORT}:80,${DDEV_MAILPIT_HTTPS_PORT}:8025 + - HTTP_EXPOSE=${DDEV_ROUTER_HTTP_PORT}:80,${DDEV_MAILPIT_PORT}:8025 volumes: # This exposes a mount to the host system `.ddev/varnish` directory where # your default.vcl should be. @@ -28,4 +28,4 @@ services: expose: - "8025" entrypoint: - /usr/local/bin/docker-varnish-entrypoint -a 0.0.0.0:8025 \ No newline at end of file + /usr/local/bin/docker-varnish-entrypoint -a 0.0.0.0:8025 diff --git a/tests/test.bats b/tests/test.bats index 543c37a..ae8babe 100644 --- a/tests/test.bats +++ b/tests/test.bats @@ -44,6 +44,30 @@ teardown() { curl -sI "https://${PROJNAME}.ddev.site:8026" | grep -i "https://novarnish.${PROJNAME}.ddev.site:8026/" >/dev/null || (echo "# https://${PROJNAME}.ddev.site:8026 did not redirect" >&3 && exit 1); } +@test "install from directory with nonstandard port" { + set -eu -o pipefail + cd ${TESTDIR} + ddev config --router-http-port 8080 --router-https-port 8443 --mailpit-http-port 18025 --mailpit-https-port 18026 + echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 + ddev get ${DIR} >/dev/null + ddev restart >/dev/null 2>&1 + for url in http://${PROJNAME}.ddev.site:8080/ http://extrahostname.ddev.site:8080/ http://extrafqdn.ddev.site:8080/ https://${PROJNAME}.ddev.site:8443/ https://extrahostname.ddev.site:8443/ https://extrafqdn.ddev.site:8443/ ; do + # It's "Via:" with http and "via:" with https. Tell me why. + echo "# test $url for via:.*varnish header" >&3 + curl -sI $url | grep -i "Via:.*varnish" >/dev/null || (echo "# varnish headers not shown for $url" >&3 && exit 1); + echo "# test $url for phpinfo content" >&3 + curl -s $url | grep "allow_url_fopen" >/dev/null || (echo "# phpinfo information not shown in curl for $url" >&3 && exit 1); + done + for url in http://novarnish.${PROJNAME}.ddev.site:8080/ http://novarnish.extrahostname.ddev.site:8080/ http://novarnish.extrafqdn.ddev.site:8080/ https://novarnish.${PROJNAME}.ddev.site:8443/ https://novarnish.extrahostname.ddev.site:8443/ https://novarnish.extrafqdn.ddev.site:8443/ ; do + echo "# test $url for phpinfo content" >&3 + curl -s $url | grep "allow_url_fopen" >/dev/null || (echo "# phpinfo information not shown in curl for $url" >&3 && exit 1); + done + echo "# test http://${PROJNAME}.ddev.site:18025 for http novarnish redirect" >&3 + curl -sI "http://${PROJNAME}.ddev.site:18025" | grep -i "http://novarnish.${PROJNAME}.ddev.site:18025/" >/dev/null || (echo "# http://${PROJNAME}.ddev.site:18025 did not redirect" >&3 && exit 1); + echo "# test https://${PROJNAME}.ddev.site:18026 for https novarnish redirect" >&3 + curl -sI "https://${PROJNAME}.ddev.site:18026" | grep -i "https://novarnish.${PROJNAME}.ddev.site:18026/" >/dev/null || (echo "# https://${PROJNAME}.ddev.site:18026 did not redirect" >&3 && exit 1); +} + @test "install from release" { set -eu -o pipefail cd ${TESTDIR} || ( printf "unable to cd to ${TESTDIR}\n" && exit 1 )