Skip to content

Commit

Permalink
Merge pull request #4 from jramsdale/jenkinsify-2
Browse files Browse the repository at this point in the history
Add looping in validate to ensure service availability
  • Loading branch information
geojaz authored Oct 12, 2018
2 parents e4cb5dd + 697285a commit daabd36
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 13 deletions.
2 changes: 0 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
# Make will use bash instead of sh
SHELL := /usr/bin/env bash

ROOT := ${CURDIR}

# lint is the first target in the file so it will get picked up when you just
# run 'make' on its own
lint: check_shell check_shebangs check_python check_golang check_terraform \
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ cluster, the Pub/Sub topic, and the Pub/Sub subscription.
gcloud services list --available
```

Identify the necessary service and enable it with the above command. Keep in
Identify the necessary service and enable it with the above command. Keep in
mind the
[principle of least privilege](https://en.wikipedia.org/wiki/Principle_of_least_privilege)
and limit access to those strictly necessary to run your applications.
Expand Down
2 changes: 1 addition & 1 deletion scripts/common.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -e
#! /usr/bin/env bash

# Copyright 2018 Google LLC
#
Expand Down
50 changes: 41 additions & 9 deletions scripts/validate.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -e
#! /usr/bin/env bash

# Copyright 2018 Google LLC
#
Expand Down Expand Up @@ -40,7 +40,7 @@ cd "$ROOT/terraform" || exit; CLUSTER_NAME=$(terraform output cluster_name) \
gcloud container clusters get-credentials "$CLUSTER_NAME" --zone="$ZONE"

SUCCESSFUL_ROLLOUT=false
for _ in {1..30}
for _ in {1..60}
do
ROLLOUT=$(kubectl rollout status -n default \
--watch=false deployment/"$APP_NAME") &> /dev/null
Expand All @@ -49,26 +49,58 @@ do
break
fi
sleep 2
echo "Waiting for application deployment..."
done

if [ "$SUCCESSFUL_ROLLOUT" = false ]
then
echo "ERROR - Application failed to deploy"
echo "ERROR - Timed out waiting for application deployment"
exit 1
fi

echo "Step 1 of the validation passed. App is deployed."

# Grab the external IP and port of the service to confirm that demo app
# deployed correctly.
EXT_IP=$(kubectl get svc "$APP_NAME" -n default \
-ojsonpath='{.status.loadBalancer.ingress[0].ip}')
# Loop for up to 60 seconds waiting for service's IP address
EXT_IP=""
for _ in {1..60}
do
EXT_IP=$(kubectl get svc "$APP_NAME" -n default \
-ojsonpath='{.status.loadBalancer.ingress[0].ip}')
[ ! -z "$EXT_IP" ] && break
sleep 2
echo "Waiting for service availability..."
done
if [ -z "$EXT_IP" ]
then
echo "ERROR - Timed out waiting for service"
exit 1
fi

# Get service's port
EXT_PORT=$(kubectl get service "$APP_NAME" -n default \
-o=jsonpath='{.spec.ports[0].port}')

echo "App is available at: http://$EXT_IP:$EXT_PORT"

[ "$(curl -s -o /dev/null -w '%{http_code}' "$EXT_IP:$EXT_PORT"/)" \
-eq 200 ] || exit 1
STATUS_CODE=""
for _ in {1..60}
do
# Test service availability
STATUS_CODE=$(curl -s -o /dev/null -w '%{http_code}' "$EXT_IP:$EXT_PORT/")
[ ! -z "$STATUS_CODE" ] && break
sleep 2
echo "Waiting for service availability..."
done
if [ -z "$STATUS_CODE" ]
then
echo "ERROR - Timed out waiting for service"
exit 1
fi

if [ "$STATUS_CODE" != "200" ]
then
echo "ERROR - Service is returning error"
exit 1
fi

echo "Step 2 of the validation passed. App handles requests."

0 comments on commit daabd36

Please sign in to comment.