run.sh 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  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:stretch-curl'
  7. # Create an instance of the container-under-test
  8. cid="$(docker run -d "$serverImage")"
  9. trap "docker rm -vf $cid > /dev/null" EXIT
  10. _request() {
  11. local method="$1"
  12. shift
  13. local url="${1}"
  14. shift
  15. docker run --rm --link "$cid":ghost "$clientImage" \
  16. curl -fs -X"$method" "$@" "http://ghost:2368/$url"
  17. }
  18. # Make sure that Ghost is listening and ready
  19. . "$dir/../../retry.sh" '_request GET / --output /dev/null'
  20. # Check that /ghost/ redirects to setup (the image is unconfigured by default)
  21. ghostVersion="$(docker inspect --format '{{range .Config.Env}}{{ . }}{{"\n"}}{{end}}' "$serverImage" | awk -F= '$1 == "GHOST_VERSION" { print $2 }')"
  22. case "$ghostVersion" in
  23. 0.*) _request GET '/ghost/' -I |tac|tac| grep -q '^Location: .*setup' ;;
  24. 1.*) _request GET '/ghost/api/v0.1/authentication/setup/' |tac|tac| grep -q 'status":false' ;;
  25. 2.*) _request GET '/ghost/api/v2/admin/authentication/setup/' |tac|tac| grep -q 'status":false' ;;
  26. 3.*) _request GET '/ghost/api/v3/admin/authentication/setup/' |tac|tac| grep -q 'status":false' ;;
  27. *) echo "no tests for version ${ghostVersion}" && exit 1 ;;
  28. esac