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.

37 lines
1.1 KiB

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