Skip to content

Commit

Permalink
keycloak container
Browse files Browse the repository at this point in the history
  • Loading branch information
ravthiru committed Sep 13, 2020
1 parent bbad03d commit 4e4d748
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 0 deletions.
39 changes: 39 additions & 0 deletions automation-tests/keycloak/config/keycloak-init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

set -e
set -x
set -o pipefail

PATH=/opt/jboss/keycloak/bin:$PATH


authurl=http://localhost:8080/auth

authcmd() {
kcadm.sh config credentials --server $authurl --realm master --user admin --password admin
}

echo Waiting for Keycloak to become ready while we try and get an access token
while ! authcmd; do
sleep 3
done

echo Logged in

echo Configuring Keycloak...

kcadm.sh create realms -s realm=springboot-keycloak -s id=springbook-keycloak -s displayName=springboot-keycloak -s enabled=true -s sslRequired=external

kcadm.sh create clients -r springboot-keycloak -s bearerOnly=true -s clientId=employee-service-app -s enabled=true

kcadm.sh create clients -r springboot-keycloak -s clientId=automation-tester -s publicClient=true -s protocol=openid-connect -s "redirectUris=[\"http://localhost:8081/*\"]" -s enabled=true

#kcadm.sh create roles -r springboot-keycloak -s name=user -o -s 'description=Allows access to get employee details.'


kcadm.sh create users -r springboot-keycloak -s username=test-user -s enabled=true

kcadm.sh set-password -r springboot-keycloak --username test-user --new-password test123


#kcadm.sh add-roles --uusername test-user --rolename user -r springboot-keycloak
31 changes: 31 additions & 0 deletions automation-tests/keycloak/run-docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash

set -e

### constants ##################################################################

path="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

KEYCLOAK_VERSION="11.0.2"
IMAGE_NAME="quay.io/keycloak/keycloak"


### Run Test cases ###################################################

chmod a+x $path/config/keycloak-init.sh

docker stop keycloak || true

docker run --rm -itd -p 8080:8080 \
--name=keycloak \
-e KEYCLOAK_USER=admin \
-e KEYCLOAK_PASSWORD=admin \
-v "$path/config":/opt/jboss/config \
"$IMAGE_NAME:$KEYCLOAK_VERSION"

docker exec -it --user 1000 keycloak /usr/bin/sh -c /opt/jboss/config/keycloak-init.sh

# docker run -p 8080:8080 -e KEYCLOAK_USER=admin -e KEYCLOAK_PASSWORD=admin quay.io/keycloak/keycloak:11.0.2

#docker run -itd --name=myContainer myImage /bin/bash
#docker exec -it myContainer /bin/bash -c /init.sh

0 comments on commit 4e4d748

Please sign in to comment.