Skip to content

Commit d3ba552

Browse files
author
Ravi Pranjal
committed
Keycloak stack flakiness fix
1 parent 9bb8a9f commit d3ba552

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

recipes/res/res_demo_env/assets/keycloak.yaml

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,19 @@ Resources:
163163
exec > /root/bootstrap/logs/userdata.log 2>&1
164164
165165
#Install java17
166-
sudo yum -y install java-17-amazon-corretto-headless
166+
MAX_ATTEMPTS=5
167+
RETRY_INTERVAL=5
168+
attempt=0
169+
while [ $attempt -lt $MAX_ATTEMPTS ]; do
170+
#Clean yum cache
171+
sudo yum clean packages
172+
#Install java-17
173+
sudo yum -y install java-17-amazon-corretto-headless
174+
which java && break
175+
sleep $RETRY_INTERVAL
176+
((attempt++))
177+
done
178+
167179
export KEYCLOAK_VERSION=${KeycloakVersion}
168180
wget https://github.com/keycloak/keycloak/releases/download/$KEYCLOAK_VERSION/keycloak-$KEYCLOAK_VERSION.zip
169181
unzip keycloak-$KEYCLOAK_VERSION.zip
@@ -183,23 +195,23 @@ Resources:
183195
SERVER_URL="http://0.0.0.0:80"
184196
MAX_ATTEMPTS=15
185197
RETRY_INTERVAL=10
186-
187198
attempt=0
188199
while [ $attempt -lt $MAX_ATTEMPTS ]; do
189200
response=$(curl -s -o /dev/null -w "%{http_code}" "$SERVER_URL")
190-
if [ "$response" == "302" ]; then
201+
if [ "$response" == "200" ] || [ "$response" == "302" ]; then
191202
echo "Server is up!"
192203
break
193204
else
194205
echo "Server is not yet up. Retrying in $RETRY_INTERVAL seconds..."
195206
sleep $RETRY_INTERVAL
196207
((attempt++))
208+
if [ $attempt == $MAX_ATTEMPTS ]; then
209+
echo "Server is not up, exiting.."
210+
/opt/aws/bin/cfn-signal -e 1 --stack "${AWS::StackName}" --resource "KeycloakEC2Instance" --region "${AWS::Region}"
211+
sleep 30
212+
fi
197213
fi
198214
done
199-
200-
if [ $(curl -s -o /dev/null -w "%{http_code}" "$SERVER_URL") != 302 ]; then
201-
/opt/aws/bin/cfn-signal -e 1 --stack "${AWS::StackName}" --resource "KeycloakEC2Instance" --region "${AWS::Region}"
202-
fi
203215
204216
echo "Keycloak server is up"
205217
# Login to Keycloak

0 commit comments

Comments
 (0)