Last active
February 9, 2022 14:33
-
-
Save MrHassanMurtaza/637eae66721110a17d66e92ad8ea1954 to your computer and use it in GitHub Desktop.
Keycloak Import in Docker and Exit
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# If something goes wrong, this script does not run forever but times out | |
TIMEOUT_SECONDS=300 | |
# Logfile for the keycloak export instance | |
LOGFILE=/tmp/standalone.sh.log | |
# destionation export file | |
JSON_IMPORT_FILE=/opt/jboss/keycloak/imports/realm-export.json | |
rm -f ${LOGFILE} ${JSON_IMPORT_FILE} | |
# Start a new keycloak instance with exporting options enabled. | |
# Use prot offset to prevent port conflicts with the "real" keycloak instance. | |
timeout ${TIMEOUT_SECONDS}s \ | |
/opt/jboss/keycloak/bin/standalone.sh \ | |
-Dkeycloak.migration.action=import \ | |
-Dkeycloak.migration.provider=singleFile \ | |
-Dkeycloak.migration.strategy=OVERWRITE_EXISTING \ | |
-Dkeycloak.migration.file=${JSON_IMPORT_FILE} \ | |
-Djboss.socket.binding.port-offset=99 \ | |
> ${LOGFILE} & | |
# Grab the keycloak export instance process id | |
PID="${!}" | |
echo "PID is ${PID}" | |
timeout ${TIMEOUT_SECONDS}s grep -m 1 "Import finished successfully" <(tail -f ${LOGFILE}) | |
# Stop the keycloak export instance | |
kill ${PID} | |
# Reloading keycloak to pick up new configurations | |
/opt/jboss/keycloak/bin/jboss-cli.sh --connect command=:reload |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
docker ps
docker exec <keycloak_container_name_or_id> /bin/bash /tmp/keycloak-import-docker.sh