-
Notifications
You must be signed in to change notification settings - Fork 212
/
cloudbuild.tmpl.yaml
99 lines (92 loc) · 2.67 KB
/
cloudbuild.tmpl.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
steps:
- id: 'Create namespace'
name: 'gcr.io/cloud-builders/kubectl'
entrypoint: 'bash'
args:
- '-c'
- |
kubectl config view
gcloud container clusters get-credentials $$CLOUDSDK_CONTAINER_CLUSTER
kubectl config view
kubectl create namespace $$TEST_NAMESPACE
- id: 'Deploy to staging'
name: 'gcr.io/k8s-skaffold/skaffold:latest'
entrypoint: 'bash'
args:
- '-c'
- |
# Builds java apps with dockerfile profile due to jib/skaffold community builder incompatibility
if [ "${_LANG}" = "java" ]
then
skaffold run -p dockerfile -l $BUILD_ID -n $$TEST_NAMESPACE -d $$SKAFFOLD_DEFAULT_REPO
else
skaffold run -p cloudbuild -l $BUILD_ID -n $$TEST_NAMESPACE -d $$SKAFFOLD_DEFAULT_REPO
fi
dir: '/workspace/${_DIR}/${_LANG}-${_APP}'
timeout: 1200s
waitFor: ['Create namespace']
- id: 'Get Endpoint'
name: 'gcr.io/cloud-builders/kubectl'
entrypoint: 'bash'
args:
- '-c'
- |
if [ "${_APP}" = "hello-world" ]
then
service=$$HELLO_WORLD_SERVICE
fi
if [ "${_APP}" = "guestbook" ]
then
service=$$GUESTBOOK_SERVICE
fi
echo 'service is' $service
get_externalIP() {
kubectl get service $service --namespace $$TEST_NAMESPACE -o jsonpath='{.status.loadBalancer.ingress[0].ip}'
}
until [[ -n "$(get_externalIP)" ]]; do
echo "Querying for external IP $service"
sleep 3
done
echo "$(get_externalIP):$(kubectl get service $service --namespace $$TEST_NAMESPACE -o jsonpath='{.spec.ports[0].port}')" > _externalIP
echo "External IP and port for $service is $(cat _externalIP)"
timeout: 1200s
waitFor: ['Deploy to staging']
- id: 'Integration tests'
name: 'gcr.io/cloud-builders/curl'
entrypoint: '/bin/bash'
args:
- '-c'
- |
set -e
# Testing connection
chmod +x test_connection.sh
./test_connection.sh -r 20 -i 3 -u http://$(cat _externalIP)
# Testing content
if [ "${_APP}" = "hello-world" ]
then
keyword='Hello'
fi
if [ "${_APP}" = "guestbook" ]
then
keyword='Guestbook'
fi
chmod +x test_content.sh
./test_content.sh -r 25 -i 3 -u http://$(cat _externalIP) -k $keyword
waitFor: ['Get Endpoint']
- id: 'Delete namespaces'
name: 'gcr.io/cloud-builders/kubectl'
entrypoint: 'bash'
args:
- '-c'
- |
kubectl delete namespace $$TEST_NAMESPACE
waitFor: ['Integration tests']
timeout: 2500s
options:
env:
- CLOUDSDK_COMPUTE_ZONE=us-central1-a
- CLOUDSDK_CONTAINER_CLUSTER=test-cluster
- SKAFFOLD_DEFAULT_REPO=gcr.io/$PROJECT_ID
- TEST_NAMESPACE=test-$BUILD_ID-$_LANG-$_APP
- HELLO_WORLD_SERVICE=${_LANG}-${_APP}-external
- GUESTBOOK_SERVICE=${_LANG}-${_APP}-frontend