From 722b9209620ad98b9cb70c7a791569064d0e1ca5 Mon Sep 17 00:00:00 2001 From: Stanislav Zhuk Date: Mon, 22 Jul 2024 03:23:55 +0300 Subject: [PATCH] Make add-on work w/o ddev-router, update tests (#37) * Make add-on work w/o ddev-router, update tests * Move `ddev restart` back --------- Co-authored-by: tyler36 --- commands/host/xhgui | 6 +++--- docker-compose.xhgui_norouter.yaml | 4 ++++ install.yaml | 13 ++++++++++++- tests/test.bats | 23 +++++++++++++++++++++++ 4 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 docker-compose.xhgui_norouter.yaml diff --git a/commands/host/xhgui b/commands/host/xhgui index d67787e..e6f261d 100644 --- a/commands/host/xhgui +++ b/commands/host/xhgui @@ -8,8 +8,8 @@ DDEV_XHGUI_PORT=8143 DDEV_XHGUI_HTTPS_PORT=8142 -if [ ${DDEV_PRIMARY_URL%://*} = "https" ]; then - ddev launch $DDEV_PRIMARY_URL:$DDEV_XHGUI_HTTPS_PORT +if [ ${DDEV_PRIMARY_URL%://*} = "http" ] || [ -n "${GITPOD_WORKSPACE_ID:-}" ] || [ "${CODESPACES:-}" = "true" ]; then + ddev launch :$DDEV_XHGUI_PORT else - ddev launch $DDEV_PRIMARY_URL:$DDEV_XHGUI_PORT + ddev launch :$DDEV_XHGUI_HTTPS_PORT fi diff --git a/docker-compose.xhgui_norouter.yaml b/docker-compose.xhgui_norouter.yaml new file mode 100644 index 0000000..03984d0 --- /dev/null +++ b/docker-compose.xhgui_norouter.yaml @@ -0,0 +1,4 @@ +#ddev-generated +# If omit_containers[ddev-router] then this file will be replaced +# with another with a `ports` statement to directly expose port 80 to 8143 +services: {} diff --git a/install.yaml b/install.yaml index 2955f52..17e8bb4 100644 --- a/install.yaml +++ b/install.yaml @@ -2,6 +2,7 @@ name: xhgui project_files: - docker-compose.xhgui.yaml +- docker-compose.xhgui_norouter.yaml - config.xhgui.yaml - commands/host/xhgui - xhgui/Dockerfile @@ -11,12 +12,22 @@ project_files: - xhgui/nginx.conf pre_install_actions: - # Ensure we're on DDEV 1.23+. It's need for the `xhgui` command (launch by port). + # Ensure we're on DDEV 1.23+. It's required for the `xhgui` command (launch by port). - | #ddev-nodisplay #ddev-description:Checking DDEV version (ddev debug capabilities | grep corepack >/dev/null) || (echo "Please upgrade DDEV to v1.23+ to enable launching." && false) +post_install_actions: + - | + #ddev-description:If router disabled, directly expose port + # + if ( {{ contains "ddev-router" (list .DdevGlobalConfig.omit_containers | toString) }} ); then + printf "#ddev-generated\nservices:\n xhgui:\n ports:\n - 8143:80\n" > docker-compose.xhgui_norouter.yaml + fi + - | + echo "You can now use 'ddev xhgui' to launch XHGui" + removal_actions: - if [[ "$DDEV_DATABASE_FAMILY" == "postgres" ]]; then ddev psql -U db -c "drop database xhgui"; fi - if [[ "$DDEV_DATABASE_FAMILY" != "postgres" ]]; then ddev mysql -uroot -proot -e "DROP DATABASE IF EXISTS xhgui"; fi diff --git a/tests/test.bats b/tests/test.bats index 1fada5c..f8670eb 100644 --- a/tests/test.bats +++ b/tests/test.bats @@ -1,5 +1,8 @@ setup() { set -eu -o pipefail + brew_prefix=$(brew --prefix) + load "${brew_prefix}/lib/bats-support/load.bash" + load "${brew_prefix}/lib/bats-assert/load.bash" export DIR="$( cd "$( dirname "$BATS_TEST_FILENAME" )" >/dev/null 2>&1 && pwd )/.." export PROJNAME=test-ddev-xhgui @@ -18,6 +21,14 @@ teardown() { } health_checks() { + set +u # bats-assert has unset variables so turn off unset check + # Make sure we can hit the 8142 port successfully + curl -s -I -f https://${PROJNAME}.ddev.site:8142 >/tmp/curlout.txt + # Make sure `ddev xhgui` works + DDEV_DEBUG=true run ddev xhgui + assert_success + assert_output --partial "FULLURL https://${PROJNAME}.ddev.site:8142" + ddev exec "curl -s xhgui:80" | grep "XHGui - Run list" } @@ -142,3 +153,15 @@ echo 'Demo website';" >${TESTDIR}/public/index.php ddev get --remove ${DIR} ddev psql "xhgui" -c '\q' > /dev/null 2>&1 && echo "Database exists." || echo "Database missing" | grep "missing" } + +@test "install from directory with nonstandard port" { + set -eu -o pipefail + cd ${TESTDIR} + ddev config --project-name=${PROJNAME} --router-http-port=8080 --router-https-port=8443 + echo "# ddev get ${DIR} with project ${PROJNAME} in ${TESTDIR} ($(pwd))" >&3 + ddev get ${DIR} + ddev restart + + # Check service works + health_checks +}