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.

36 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. 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" "${KEYCLOAK_DOCKER_IMAGE}" start-dev
  14. SECONDS=0
  15. until curl --silent --output /dev/null localhost:$KEYCLOAK_PORT; do
  16. sleep 5;
  17. if [ ${SECONDS} -gt 180 ]; then
  18. echo "Timeout exceeded";
  19. exit 1;
  20. fi
  21. done
  22. }
  23. # Ensuring that keycloak is stopped in case of CTRL-C
  24. trap keycloak_stop err exit
  25. keycloak_stop # In case it did not shut down correctly last time.
  26. keycloak_start
  27. eval ${CMD_ARGS}
  28. RETURN_VALUE=$?
  29. exit ${RETURN_VALUE}