2017-11-30 03:20:15 +08:00
#!/bin/bash
2017-10-20 07:26:52 +08:00
2017-11-30 03:20:15 +08:00
set -exu -o pipefail
2018-08-17 03:12:52 +08:00
if [ [ -f /VERSION ] ] ; then
cat /VERSION
fi
2017-11-30 03:20:15 +08:00
KOKORO_GAE_SERVICE = "java-gae-interop-test"
# We deploy as different versions of a single service, this way any stale
# lingering deploys can be easily cleaned up by purging all running versions
# of this service.
KOKORO_GAE_APP_VERSION = $( hostname)
# A dummy version that can be the recipient of all traffic, so that the kokoro test version can be
# set to 0 traffic. This is a requirement in order to delete it.
DUMMY_DEFAULT_VERSION = 'dummy-default'
function cleanup( ) {
echo "Performing cleanup now."
gcloud app services delete $KOKORO_GAE_SERVICE --version $KOKORO_GAE_APP_VERSION --quiet
}
trap cleanup SIGHUP SIGINT SIGTERM EXIT
2018-08-17 03:12:52 +08:00
readonly GRPC_JAVA_DIR = " $( cd " $( dirname " $0 " ) " /../.. && pwd ) "
cd " $GRPC_JAVA_DIR "
2017-11-30 03:20:15 +08:00
##
## Deploy the dummy 'default' version of the service
##
2020-01-10 07:20:41 +08:00
GRADLE_FLAGS = "--stacktrace -DgaeStopPreviousVersion=false -PskipCodegen=true -PskipAndroid=true"
2022-07-07 22:26:38 +08:00
export GRADLE_OPTS = "-Dorg.gradle.jvmargs='-Xmx1g'"
2017-12-29 02:53:59 +08:00
# Deploy the dummy 'default' version. We only require that it exists when cleanup() is called.
2018-04-06 04:19:36 +08:00
# It ok if we race with another run and fail here, because the end result is idempotent.
2017-12-29 02:53:59 +08:00
set +e
2018-08-17 04:43:49 +08:00
if ! gcloud app versions describe " $DUMMY_DEFAULT_VERSION " --service= " $KOKORO_GAE_SERVICE " ; then
./gradlew $GRADLE_FLAGS -DgaeDeployVersion= " $DUMMY_DEFAULT_VERSION " -DgaePromote= true :grpc-gae-interop-testing-jdk8:appengineDeploy
2017-12-29 02:53:59 +08:00
else
echo " default version already exists: $DUMMY_DEFAULT_VERSION "
2017-11-30 03:20:15 +08:00
fi
2018-04-06 04:19:36 +08:00
set -e
2017-11-30 03:20:15 +08:00
# Deploy and test the real app (jdk8)
2018-08-17 03:02:39 +08:00
./gradlew $GRADLE_FLAGS -DgaeDeployVersion= " $KOKORO_GAE_APP_VERSION " :grpc-gae-interop-testing-jdk8:runInteropTestRemote
2017-11-30 03:20:15 +08:00
2017-12-29 04:35:03 +08:00
set +e
echo "Cleaning out stale deploys from previous runs, it is ok if this part fails"
# Sometimes the trap based cleanup fails.
2018-08-17 03:12:52 +08:00
# Delete all versions whose name is not 'dummy-default' and is older than 1 hour.
2018-04-06 04:19:36 +08:00
# This expression is an ISO8601 relative date:
2017-12-29 04:35:03 +08:00
# https://cloud.google.com/sdk/gcloud/reference/topic/datetimes
2018-08-17 03:12:52 +08:00
gcloud app versions list --format= "get(version.id)" --filter= " service= $KOKORO_GAE_SERVICE AND NOT version : 'dummy-default' AND version.createTime<'-p1h' " | xargs -i gcloud app services delete " $KOKORO_GAE_SERVICE " --version { } --quiet
2017-12-29 05:03:53 +08:00
exit 0