forked from apigee/devrel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipeline.sh
executable file
·54 lines (41 loc) · 1.84 KB
/
pipeline.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/sh
# Copyright 2021 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
set -e
SCRIPTPATH=$( (cd "$(dirname "$0")" && pwd ))
APIGEE_TOKEN=$(gcloud auth print-access-token);
SA_EMAIL="cloud-log-writer@$APIGEE_X_ORG.iam.gserviceaccount.com"
EXISTING_EMAIL=$(gcloud iam service-accounts list --filter="email=$SA_EMAIL" --format="get(email)" --project "$APIGEE_X_ORG")
if [ "$EXISTING_EMAIL" != "$SA_EMAIL" ]; then
gcloud iam service-accounts create "cloud-log-writer" --project "$APIGEE_X_ORG"
gcloud projects add-iam-policy-binding "$APIGEE_X_ORG" \
--member="serviceAccount:$SA_EMAIL" \
--role="roles/logging.logWriter"
fi
sackmesser deploy --googleapi -d "$SCRIPTPATH" -t "$APIGEE_TOKEN" --deployment-sa "$SA_EMAIL"
sackmesser deploy --googleapi -d "$SCRIPTPATH/test/logging-example" -t "$APIGEE_TOKEN"
TEST_PATH="/logging-example?t=$(date +%s)"
curl "https://${APIGEE_X_HOSTNAME}${TEST_PATH}" -I
i=0
logs_count=0
while [ "$i" -lt 20 ] && [ ! "$logs_count" -gt 0 ]; do
i=$(( i + 1 ))
logs_count=$(gcloud logging read "logName=projects/$APIGEE_X_ORG/logs/apigee-runtime AND jsonPayload.requestUri=\"$TEST_PATH\"" --limit 5 --format=json --project "$APIGEE_X_ORG" | jq '. | length')
echo "(attempt $i) logs found: $logs_count"
sleep 1
done
if [ "$logs_count" -eq 0 ]; then
echo "No logs found for test path $TEST_PATH"
exit 1
fi