github.com/ddev/ddev@v1.23.2-0.20240519125000-d824ffe36ff3/containers/ddev-traefik-router/test/containertest.sh (about) 1 #!/bin/bash 2 3 set -o errexit 4 set -o pipefail 5 set -o nounset 6 7 if [ "${OS:-$(uname)}" = "Windows_NT" ]; then exit; fi 8 9 if [ $# != "1" ]; then echo "docker image spec must be \$1"; exit 1; fi 10 DOCKER_IMAGE=$1 11 CONTAINER_NAME=ddev-traefik-router-test 12 13 function cleanup { 14 echo "Removing $CONTAINER_NAME" 15 docker rm -f $CONTAINER_NAME 2>/dev/null || true 16 } 17 trap cleanup EXIT 18 19 # Wait for container to be ready. 20 function containercheck { 21 for i in {15..0}; do 22 # fail if we can't find the container 23 if ! docker inspect ${CONTAINER_NAME} >/dev/null; then 24 break 25 fi 26 27 status="$(docker inspect ${CONTAINER_NAME} | jq -r '.[0].State.Status')" 28 if [ "${status}" != "running" ]; then 29 break 30 fi 31 health="$(docker inspect --format '{{json .State.Health }}' ${CONTAINER_NAME} | jq -r .Status)" 32 case ${health} in 33 healthy) 34 return 0 35 ;; 36 *) 37 sleep 1 38 ;; 39 esac 40 done 41 echo "# --- ddev-traefik-router FAIL -----" 42 return 1 43 } 44 45 cleanup 46 47 SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) 48 49 # Make sure rootCA is created and installed on the ddev-global-cache/mkcert 50 mkcert -install 51 set -x 52 docker run -t --rm -v "$(mkcert -CAROOT):/mnt/mkcert" -v ${SCRIPT_DIR}/testdata:/mnt/testdata -v ddev-global-cache:/mnt/ddev-global-cache ${DOCKER_IMAGE} bash -c "mkdir -p /mnt/ddev-global-cache/{mkcert,traefik} && chmod -R ugo+w /mnt/ddev-global-cache/* && cp -R /mnt/mkcert /mnt/ddev-global-cache && cp /mnt/testdata/* /mnt/ddev-global-cache/traefik" 53 54 # Run the router alone 55 docker run --rm --name $CONTAINER_NAME -p 8080:80 -p 8443:443 -v ddev-global-cache:/mnt/ddev-global-cache --name ${CONTAINER_NAME} -d $DOCKER_IMAGE --configFile=/mnt/ddev-global-cache/traefik/static_config.yaml 56 57 if ! containercheck; then 58 printf "=============== FAIL: $CONTAINER_NAME failed to become ready ====================\n" 59 printf "=============== FAIL: $CONTAINER_NAME FAIL: information =================\n" 60 docker logs $CONTAINER_NAME 61 docker ps -a 62 docker inspect $CONTAINER_NAME 63 exit 101 64 fi 65 66 # Make sure we can access http and https ports successfully (and with valid cert) 67 #(curl -s -I http://127.0.0.1:8080 | grep 503) || (echo "Failed to get 503 from nginx-router by default" && exit 102) 68 ## mkcert is not respected by git-bash curl, so don't try the test on windows. 69 #if [ "${OS:-$(uname)}" != "Windows_NT" ]; then 70 # (curl -s -I https://127.0.0.1:8443 | grep 503) || (echo "Failed to get 503 from nginx-router via https by default" && exit 103) 71 #fi 72 # Make sure internal access to monitor port is working 73 docker exec -t $CONTAINER_NAME bash -c 'curl -I http://127.0.0.1:${TRAEFIK_MONITOR_PORT}/ping' || (echo "Failed to run http healthcheck inside container" && exit 104)