diff --git a/indexer-service-gcp/src/main/appengine/app.yaml b/indexer-service-gcp/src/main/appengine/app.yaml index fa35e0e0782d4f921efe1375930c65c14fbe27ef..730fb9b3a7f858a87ea128206d7d48c434d3d078 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 0000000000000000000000000000000000000000..9c375ce2103dfde625a33d1e9c3c1b3301ee007a --- /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