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