Skip to content

Commit

Permalink
Make add-on work w/o ddev-router, update tests (#37)
Browse files Browse the repository at this point in the history
* Make add-on work w/o ddev-router, update tests

* Move `ddev restart` back

---------

Co-authored-by: tyler36 <[email protected]>
  • Loading branch information
stasadev and tyler36 authored Jul 22, 2024
1 parent 578bfc2 commit 722b920
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 4 deletions.
6 changes: 3 additions & 3 deletions commands/host/xhgui
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions docker-compose.xhgui_norouter.yaml
Original file line number Diff line number Diff line change
@@ -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: {}
13 changes: 12 additions & 1 deletion install.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
23 changes: 23 additions & 0 deletions tests/test.bats
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
}

Expand Down Expand Up @@ -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
}

0 comments on commit 722b920

Please sign in to comment.