run.sh 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/bin/bash
  2. set -eo pipefail
  3. dir="$(dirname "$(readlink -f "$BASH_SOURCE")")"
  4. serverImage="$1"
  5. # Use a client image with curl for testing
  6. clientImage='buildpack-deps:buster-curl'
  7. # ensure the clientImage is ready and available
  8. if ! docker image inspect "$clientImage" &> /dev/null; then
  9. docker pull "$clientImage" > /dev/null
  10. fi
  11. # Create an instance of the container-under-test
  12. cid="$(docker run -d "$serverImage")"
  13. trap "docker rm -vf $cid > /dev/null" EXIT
  14. _request() {
  15. local method="$1"
  16. shift
  17. local url="${1}"
  18. shift
  19. docker run --rm \
  20. --link "$cid":ghost \
  21. "$clientImage" \
  22. curl -fs -X"$method" "$@" "http://ghost:2368/$url"
  23. }
  24. # Make sure that Ghost is listening and ready
  25. . "$dir/../../retry.sh" '_request GET / --output /dev/null'
  26. # Check that /ghost/ redirects to setup (the image is unconfigured by default)
  27. ghostVersion="$(docker inspect --format '{{range .Config.Env}}{{ . }}{{"\n"}}{{end}}' "$serverImage" | awk -F= '$1 == "GHOST_VERSION" { print $2 }')"
  28. case "$ghostVersion" in
  29. 2.*) _request GET '/ghost/api/v2/admin/authentication/setup/' |tac|tac| grep -q 'status":false' ;;
  30. 3.*) _request GET '/ghost/api/v3/admin/authentication/setup/' |tac|tac| grep -q 'status":false' ;;
  31. 4.*) _request GET '/ghost/api/v4/admin/authentication/setup/' |tac|tac| grep -q 'status":false' ;;
  32. *) echo "no tests for version ${ghostVersion}" && exit 1 ;;
  33. esac