From 9f9003559f62f7e38fcb98930fdb0555d522a7c4 Mon Sep 17 00:00:00 2001 From: Jagan Gottimukkula <jgottimukkula@slb.com> Date: Fri, 18 Oct 2019 11:38:52 -0500 Subject: [PATCH] added gcp deployment scripts --- .../src/main/appengine/app.yaml | 2 +- indexer-service-gcp/src/scripts/deploy.sh | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 indexer-service-gcp/src/scripts/deploy.sh diff --git a/indexer-service-gcp/src/main/appengine/app.yaml b/indexer-service-gcp/src/main/appengine/app.yaml index fa35e0e07..730fb9b3a 100644 --- a/indexer-service-gcp/src/main/appengine/app.yaml +++ b/indexer-service-gcp/src/main/appengine/app.yaml @@ -33,4 +33,4 @@ handlers: script: this field is required, but ignored env_variables: - GOOGLE_CLOUD_PROJECT: "opendes" + GOOGLE_CLOUD_PROJECT: "GOOGLE_CLOUD_PROJECT_PLACE_HOLDER" diff --git a/indexer-service-gcp/src/scripts/deploy.sh b/indexer-service-gcp/src/scripts/deploy.sh new file mode 100644 index 000000000..9c375ce21 --- /dev/null +++ b/indexer-service-gcp/src/scripts/deploy.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +# Exit as soon as a command fails +set -e + +echo " Project = $GCLOUD_PROJECT" +echo " Source branch = $BUILD_SOURCEBRANCHNAME" +echo " Build definition = $BUILD_DEFINITIONNAME" +echo " Build number = $BUILD_BUILDNUMBER" + +echo "current working directory" +pwd + +echo "working directory contents" +ls + +DEPLOY_DIR="deploy_dir" +mkdir -p $DEPLOY_DIR + +cp app.yaml $DEPLOY_DIR +cp indexer-service-gcp-*.jar $DEPLOY_DIR + +# Go to deploy directory +cd $DEPLOY_DIR + +# apply sed to set PROJECT_ID with its value in app.yaml +echo "Replacing GOOGLE_CLOUD_PROJECT_PLACE_HOLDER with GCLOUD_PROJECT" +sed -i "s|GOOGLE_CLOUD_PROJECT_PLACE_HOLDER|$GCLOUD_PROJECT|g" app.yaml +cat app.yaml + +# check the current deployed version of the same service +SERVICE_NAME="os-indexer" +count=$(gcloud app services list --project $GCLOUD_PROJECT | grep $SERVICE_NAME | wc -l) +if [ $count -gt 0 ]; then + CURRENT_VERSION=$(gcloud app services describe $SERVICE_NAME --project $GCLOUD_PROJECT --format=json | jq --raw-output '.split.allocations | keys[0]') +else + CURRENT_VERSION="" +fi + +NEW_VERSION=$BUILD_BUILDNUMBER #to keep it unique +NEW_VERSION=$(echo "$NEW_VERSION" | tr _ - | tr . - | tr '[:upper:]' '[:lower:]') + +echo "Current version = $CURRENT_VERSION" +echo "Version to be deployed = $NEW_VERSION" + +if [ "$NEW_VERSION" != "$CURRENT_VERSION" -o "$BUILD_FORCE_DEPLOY" = "true" ] +then + gcloud app deploy --quiet --version=$NEW_VERSION --project=$GCLOUD_PROJECT app.yaml +else + echo "Not deploying the application because $NEW_VERSION is already deployed and force deploy flag is not set to true" +fi -- GitLab