forked from dora-team/fourkeys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
e2e_tests.cloudbuild.yaml
100 lines (86 loc) · 3.21 KB
/
e2e_tests.cloudbuild.yaml
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
steps:
- id: Setup Script
name: 'google/cloud-sdk'
entrypoint: /bin/bash
args:
- '-c'
- |
pip3 install --upgrade pip
cd setup/
export FOURKEYS_PROJECT=${PROJECT_ID}
# passing in responses to the prompts
# "n\ny\n2\n1\nn\ny\n" maps to:
### No, do not make new project
### Yes, it's the correct project id
### 2, Using github for version control
### 1, Using Cloud Build for deployments
### No, do not create a test project
### Yes, make mock data
printf "n\ny\n2\n1\nn\ny\n" | ./setup.sh
- id: Check Tables are Populated
name: 'google/cloud-sdk'
entrypoint: /bin/bash
args:
- '-c'
- |
result_check="import sys, json
results = int(json.load(sys.stdin)[0]['vol'])
try:
if results < 1:
sys.exit('Table is empty')
except Exception as e:
sys.exit(e)"
echo "Checking events_raw table"
bq query --format=json \
'SELECT count(*) as vol FROM four_keys.events_raw' | \
python3 -c "$result_check"
echo "Checking deployments table"
bq query --format=json \
'SELECT count(*) as vol FROM four_keys.deployments' | \
python3 -c "$result_check"
echo "Checking changes table"
bq query --format=json \
'SELECT count(*) as vol FROM four_keys.changes' | \
python3 -c "$result_check"
echo "Checking incidents table"
bq query --format=json \
'SELECT count(*) as vol FROM four_keys.incidents' | \
python3 -c "$result_check"
- id: Tear Down Resources
name: 'google/cloud-sdk'
entrypoint: /bin/bash
args:
- '-c'
- |
echo "Dropping BQ Resources"
set -x
bq rm -r -f -d ${PROJECT_ID}:four_keys
set +x
configs=$(bq ls --transfer_config --transfer_location us --format=json)
config_ids=$(python3 -c "import json, subprocess
for config in $configs:
print(config['name'])")
set -x
for config in $config_ids
do
bq rm -f --transfer_config $config
done
echo "Removing secret"
gcloud beta secrets delete event-handler -q
echo "Delete Cloud Run services"
gcloud run services delete event-handler --platform managed --region us-central1 -q
gcloud run services delete github-worker --platform managed --region us-central1 -q
gcloud run services delete cloud-build-worker --platform managed --region us-central1 -q
echo "Delete Pub/Sub topics and subscriptions"
gcloud pubsub topics delete GitHub-Hookshot -q
gcloud pubsub subscriptions delete GithubSubscription -q
gcloud pubsub subscriptions delete CloudBuildSubscription -q
echo "Turning off APIs"
gcloud services disable compute.googleapis.com
gcloud services disable run.googleapis.com
gcloud services disable bigquery.googleapis.com
gcloud services disable bigquerydatatransfer.googleapis.com
gcloud services disable bigqueryconnection.googleapis.com
gcloud services disable secretmanager.googleapis.com
set +x
timeout: '3600s'