1*e07d83d3SAndroid Build Coastguard Worker#!/bin/bash 2*e07d83d3SAndroid Build Coastguard Worker 3*e07d83d3SAndroid Build Coastguard Workerset -exu -o pipefail 4*e07d83d3SAndroid Build Coastguard Workerif [[ -f /VERSION ]]; then 5*e07d83d3SAndroid Build Coastguard Worker cat /VERSION 6*e07d83d3SAndroid Build Coastguard Workerfi 7*e07d83d3SAndroid Build Coastguard Worker 8*e07d83d3SAndroid Build Coastguard WorkerKOKORO_GAE_SERVICE="java-gae-interop-test" 9*e07d83d3SAndroid Build Coastguard Worker 10*e07d83d3SAndroid Build Coastguard Worker# We deploy as different versions of a single service, this way any stale 11*e07d83d3SAndroid Build Coastguard Worker# lingering deploys can be easily cleaned up by purging all running versions 12*e07d83d3SAndroid Build Coastguard Worker# of this service. 13*e07d83d3SAndroid Build Coastguard WorkerKOKORO_GAE_APP_VERSION=$(hostname) 14*e07d83d3SAndroid Build Coastguard Worker 15*e07d83d3SAndroid Build Coastguard Worker# A dummy version that can be the recipient of all traffic, so that the kokoro test version can be 16*e07d83d3SAndroid Build Coastguard Worker# set to 0 traffic. This is a requirement in order to delete it. 17*e07d83d3SAndroid Build Coastguard WorkerDUMMY_DEFAULT_VERSION='dummy-default' 18*e07d83d3SAndroid Build Coastguard Worker 19*e07d83d3SAndroid Build Coastguard Workerfunction cleanup() { 20*e07d83d3SAndroid Build Coastguard Worker echo "Performing cleanup now." 21*e07d83d3SAndroid Build Coastguard Worker gcloud app services delete $KOKORO_GAE_SERVICE --version $KOKORO_GAE_APP_VERSION --quiet 22*e07d83d3SAndroid Build Coastguard Worker} 23*e07d83d3SAndroid Build Coastguard Workertrap cleanup SIGHUP SIGINT SIGTERM EXIT 24*e07d83d3SAndroid Build Coastguard Worker 25*e07d83d3SAndroid Build Coastguard Workerreadonly GRPC_JAVA_DIR="$(cd "$(dirname "$0")"/../.. && pwd)" 26*e07d83d3SAndroid Build Coastguard Workercd "$GRPC_JAVA_DIR" 27*e07d83d3SAndroid Build Coastguard Worker 28*e07d83d3SAndroid Build Coastguard Worker## 29*e07d83d3SAndroid Build Coastguard Worker## Deploy the dummy 'default' version of the service 30*e07d83d3SAndroid Build Coastguard Worker## 31*e07d83d3SAndroid Build Coastguard WorkerGRADLE_FLAGS="--stacktrace -DgaeStopPreviousVersion=false -PskipCodegen=true -PskipAndroid=true" 32*e07d83d3SAndroid Build Coastguard Workerexport GRADLE_OPTS="-Dorg.gradle.jvmargs='-Xmx1g'" 33*e07d83d3SAndroid Build Coastguard Worker 34*e07d83d3SAndroid Build Coastguard Worker# Deploy the dummy 'default' version. We only require that it exists when cleanup() is called. 35*e07d83d3SAndroid Build Coastguard Worker# It ok if we race with another run and fail here, because the end result is idempotent. 36*e07d83d3SAndroid Build Coastguard Workerset +e 37*e07d83d3SAndroid Build Coastguard Workerif ! gcloud app versions describe "$DUMMY_DEFAULT_VERSION" --service="$KOKORO_GAE_SERVICE"; then 38*e07d83d3SAndroid Build Coastguard Worker ./gradlew $GRADLE_FLAGS -DgaeDeployVersion="$DUMMY_DEFAULT_VERSION" -DgaePromote=true :grpc-gae-interop-testing-jdk8:appengineDeploy 39*e07d83d3SAndroid Build Coastguard Workerelse 40*e07d83d3SAndroid Build Coastguard Worker echo "default version already exists: $DUMMY_DEFAULT_VERSION" 41*e07d83d3SAndroid Build Coastguard Workerfi 42*e07d83d3SAndroid Build Coastguard Workerset -e 43*e07d83d3SAndroid Build Coastguard Worker 44*e07d83d3SAndroid Build Coastguard Worker# Deploy and test the real app (jdk8) 45*e07d83d3SAndroid Build Coastguard Worker./gradlew $GRADLE_FLAGS -DgaeDeployVersion="$KOKORO_GAE_APP_VERSION" :grpc-gae-interop-testing-jdk8:runInteropTestRemote 46*e07d83d3SAndroid Build Coastguard Worker 47*e07d83d3SAndroid Build Coastguard Workerset +e 48*e07d83d3SAndroid Build Coastguard Workerecho "Cleaning out stale deploys from previous runs, it is ok if this part fails" 49*e07d83d3SAndroid Build Coastguard Worker 50*e07d83d3SAndroid Build Coastguard Worker# Sometimes the trap based cleanup fails. 51*e07d83d3SAndroid Build Coastguard Worker# Delete all versions whose name is not 'dummy-default' and is older than 1 hour. 52*e07d83d3SAndroid Build Coastguard Worker# This expression is an ISO8601 relative date: 53*e07d83d3SAndroid Build Coastguard Worker# https://cloud.google.com/sdk/gcloud/reference/topic/datetimes 54*e07d83d3SAndroid Build Coastguard Workergcloud 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 55*e07d83d3SAndroid Build Coastguard Workerexit 0 56