diff --git a/provider/indexer-azure/pom.xml b/provider/indexer-azure/pom.xml index 6a2af2e26db20948d59062e5192dee7fe865042f..1144ad4adcefc33a0bf04653e9f7d094ced2c3e5 100644 --- a/provider/indexer-azure/pom.xml +++ b/provider/indexer-azure/pom.xml @@ -24,6 +24,7 @@ <groupId>org.opengroup.osdu.indexer</groupId> <artifactId>indexer-service</artifactId> <version>1.0-SNAPSHOT</version> + <relativePath>../../pom.xml</relativePath> </parent> <artifactId>indexer-azure</artifactId> diff --git a/provider/indexer-gcp/scripts/config.sh b/provider/indexer-gcp/scripts/config.sh new file mode 100644 index 0000000000000000000000000000000000000000..102b1bc9b5e86f5a8d93cc5697a7dd0739fbeb5e --- /dev/null +++ b/provider/indexer-gcp/scripts/config.sh @@ -0,0 +1,6 @@ +#!/bin/bash + +if [ "$PROJECT_ID" = "" ] +then + export PROJECT_ID=$(gcloud config get-value project) +fi diff --git a/provider/indexer-gcp/scripts/deploy.sh b/provider/indexer-gcp/scripts/deploy.sh new file mode 100644 index 0000000000000000000000000000000000000000..c36f68dbb7d325840f0b89efb7bb9230e99fda07 --- /dev/null +++ b/provider/indexer-gcp/scripts/deploy.sh @@ -0,0 +1,44 @@ +#!/bin/bash + +# deploy script + +# Exit as soon as a command fails +set -e + +SCRIPTS_DIR=$(dirname $0) +DROP_DIR=$(dirname $SCRIPTS_DIR) + +# Go to drop directory +cd $DROP_DIR +# convert to full path +DROP_DIR=`pwd` +echo "Current working directory: $DROP_DIR" + +DEPLOY_DIR=$DROP_DIR/deploy + +if [ -s $DEPLOY_DIR ]; then + rm -rf $DEPLOY_DIR/* +else + mkdir $DEPLOY_DIR +fi + +DEPLOY_SCRIPTS_DIR=$DEPLOY_DIR/scripts + +mkdir -p $DEPLOY_SCRIPTS_DIR + +echo "Copy artifacts to folder: $DEPLOY_DIR" +cp $DROP_DIR/app.yaml $DEPLOY_DIR +cp $DROP_DIR/indexer-gcp-*.jar $DEPLOY_DIR +cp $DROP_DIR/testing.zip $DEPLOY_DIR +cp $SCRIPTS_DIR/* $DEPLOY_SCRIPTS_DIR +chmod a+x $DEPLOY_SCRIPTS_DIR/*.sh + +# Go to deploy directory +cd $DEPLOY_DIR +echo "Current working directory: $DEPLOY_DIR" + +source $DEPLOY_SCRIPTS_DIR/config.sh + +echo "Deploying to gcp" +$DEPLOY_SCRIPTS_DIR/deploy2gcp.sh +echo "Deployed to gcp" \ No newline at end of file diff --git a/provider/indexer-gcp/scripts/deploy2gcp.sh.tmpl b/provider/indexer-gcp/scripts/deploy2gcp.sh.tmpl new file mode 100644 index 0000000000000000000000000000000000000000..d9ab34ffd0ac1e18b969f9e4e8929ad94e3ca713 --- /dev/null +++ b/provider/indexer-gcp/scripts/deploy2gcp.sh.tmpl @@ -0,0 +1,85 @@ +#!/bin/bash + +# Exit as soon as a command fails +set -e + +{{$definitionName := getenv "BUILD_DEFINITIONNAME" -}} +{{$sourceBranchName := getenv "BUILD_SOURCEBRANCHNAME" -}} +{{$buildNumber := getenv "BUILD_BUILDNUMBER" -}} + +BUILD_DEFINITIONNAME={{$definitionName}} +BUILD_SOURCEBRANCHNAME={{$sourceBranchName}} +BUILD_BUILDNUMBER={{$buildNumber}} + +SCRIPTS_DIR=$(dirname $0) +DEPLOY_DIR=$(dirname $SCRIPTS_DIR) + +# Go to deploy directory +cd $DEPLOY_DIR +# convert to full path +DEPLOY_DIR=`pwd` +echo "Current working directory: $DEPLOY_DIR" + +source $SCRIPTS_DIR/config.sh + +echo "This script will deploy the app to $PROJECT_ID" + +if [ "$REGION" = "" ] +then + REGION=$(gcloud config get-value compute/region) +fi + +echo "Environment" +echo " Project = $PROJECT_ID" +echo " Compute zone = $CLOUDSDK_COMPUTE_ZONE" +echo " Build definition = $BUILD_DEFINITIONNAME" +echo " Source branch = $BUILD_SOURCEBRANCHNAME" +echo " Build number = $BUILD_BUILDNUMBER" +echo " Directory = $DEPLOY_DIR" + +VERSION_NUMBER=$BUILD_BUILDNUMBER +VERSION_NUMBER=$(echo "$VERSION_NUMBER" | tr _ - | tr . - | tr '[:upper:]' '[:lower:]') + +count=$(gcloud app services list --project $PROJECT_ID | grep legal-service | wc -l) +if [ $count -gt 0 ]; then + CURRENT_VERSION=$(gcloud app services describe legal-service --project $PROJECT_ID --format=json | jq --raw-output '.split.allocations | keys[0]') +else + CURRENT_VERSION="" +fi + +echo "Current version = $CURRENT_VERSION" +echo "Version to be deployed = $VERSION_NUMBER" + +if [ "$VERSION_NUMBER" != "$CURRENT_VERSION" -o "$BUILD_FORCE_DEPLOY" = "true" -o "$BUILD_FORCE_DEPLOY" = "True" -o "$BUILD_FORCE_DEPLOY" = "TRUE" ] +then + if [ "$BUILD_SOURCEBRANCHNAME" = "master" -o "$BUILD_FORCE_DEPLOY" = "true" -o "$BUILD_FORCE_DEPLOY" = "True" -o "$BUILD_FORCE_DEPLOY" = "TRUE" ] + then + SERVICE_NAME="legal-service" + # If the version $VERSION_NUMBER already exists, but not serving traffic, gcloud app deploy will fail. In this case, simply start that version and migrate traffic to it + doesVersionExist=`gcloud app versions list --service=$SERVICE_NAME --project=$PROJECT_ID | grep $VERSION_NUMBER | wc -l` + if [ "$doesVersionExist" -eq "1" ] + then + echo "Starting version $VERSION_NUMBER" + gcloud app versions start $VERSION_NUMBER --service=$SERVICE_NAME --project=$PROJECT_ID --quiet + echo "Migrating all traffic to version $VERSION_NUMBER" + gcloud app services set-traffic $SERVICE_NAME --splits $VERSION_NUMBER=1 --project=$PROJECT_ID --quiet + else + export LEGAL_HOSTNAME="legal-service-dot-$PROJECT_ID.appspot.com" + + echo "Replacing GOOGLE_CLOUD_PROJECT_PLACE_HOLDER with $PROJECT_ID" + sed -i "s|GOOGLE_CLOUD_PROJECT_PLACE_HOLDER|$PROJECT_ID|g" app.yaml + + echo "Content of app.yaml:" + cat app.yaml + + echo "Deploying $LEGAL_HOSTNAME service" + gcloud app deploy --project=$PROJECT_ID --version=$VERSION_NUMBER app.yaml + echo "$LEGAL_HOSTNAME service deployed successfully" + + fi + else + echo "Not deploying the application because build source branch was not master" + fi +else + echo "Not deploying the application because $VERSION_NUMBER is already deployed and force deploy flag is not set to true" +fi diff --git a/provider/indexer-gcp/scripts/stage-artifacts.sh b/provider/indexer-gcp/scripts/stage-artifacts.sh new file mode 100644 index 0000000000000000000000000000000000000000..a1243e30639332dde9791cb51281f29a63fef0c6 --- /dev/null +++ b/provider/indexer-gcp/scripts/stage-artifacts.sh @@ -0,0 +1,41 @@ +#!/bin/bash + +# Exit as soon as a command fails +set -e + +if [ ! $# = 1 ]; then + echo "Usage: $0 dir" + exit 1 +fi + +STAGE_DIR=$1 + +cd $BUILD_REPOSITORY_LOCALPATH/provider/indexer-gcp/scripts + +source ./config.sh + +#apply gomplate to deploy2gcp.sh.tmpl +gomplate -f ./deploy2gcp.sh.tmpl -o ./deploy2gcp.sh +chmod a+x ./*.sh +echo "Contents of deploy2gcp.sh:" +cat ./deploy2gcp.sh + +cd .. + +# Upload all build and deploy scripts as artifacts +cp -R ./scripts $STAGE_DIR +# Upload the build generated .jar file as an artifact +cp ./target/indexer-gcp-0.0.1.jar $STAGE_DIR + +echo "Staging deployment artifacts to folder: $STAGE_DIR" +cp ./src/main/appengine/app.yaml $STAGE_DIR + +# set current directory back to build repo root +cd $BUILD_REPOSITORY_LOCALPATH + +# Zip integration tests and upload it as artifact +pushd testing +zip -r testing.zip * +cp testing.zip $STAGE_DIR +popd +