You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
1.2 KiB

  1. #!/usr/bin/env bash
  2. CMD_ARGS=$1
  3. KEYCLOAK_DOCKER_IMAGE_TAG="${KEYCLOAK_DOCKER_IMAGE_TAG:-latest}"
  4. KEYCLOAK_DOCKER_IMAGE="quay.io/keycloak/keycloak:$KEYCLOAK_DOCKER_IMAGE_TAG"
  5. function keycloak_stop() {
  6. if [ "$(docker ps -q -f name=unittest_keycloak)" ]; then
  7. docker logs unittest_keycloak > keycloak_test_logs.txt
  8. docker stop unittest_keycloak &> /dev/null
  9. docker rm unittest_keycloak &> /dev/null
  10. fi
  11. }
  12. function keycloak_start() {
  13. echo "Starting keycloak docker container"
  14. PWD=$(pwd)
  15. docker run -d --name unittest_keycloak -e KEYCLOAK_ADMIN="${KEYCLOAK_ADMIN}" -e KEYCLOAK_ADMIN_PASSWORD="${KEYCLOAK_ADMIN_PASSWORD}" -e KC_FEATURES="token-exchange,admin-fine-grained-authz" -p "${KEYCLOAK_PORT}:8080" -v $PWD/tests/providers:/opt/keycloak/providers "${KEYCLOAK_DOCKER_IMAGE}" start-dev
  16. SECONDS=0
  17. until curl --silent --output /dev/null localhost:$KEYCLOAK_PORT; do
  18. sleep 5;
  19. if [ ${SECONDS} -gt 180 ]; then
  20. echo "Timeout exceeded";
  21. exit 1;
  22. fi
  23. done
  24. }
  25. # Ensuring that keycloak is stopped in case of CTRL-C
  26. trap keycloak_stop err exit
  27. keycloak_stop # In case it did not shut down correctly last time.
  28. keycloak_start
  29. eval ${CMD_ARGS}
  30. RETURN_VALUE=$?
  31. exit ${RETURN_VALUE}