-
Notifications
You must be signed in to change notification settings - Fork 9
/
demo
executable file
·186 lines (140 loc) · 5.11 KB
/
demo
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/bin/bash
# Usage: demo [ --clean | --demo ] [ CLUSTER_NAME ]
# --clean will erase all old resouces from a previous run
# --demo will fly thru the setup stuff and then pause when it gets to deploying
# the apps. Basically, good for a live demo when you don't want to show the
# prep steps.
set -e
source .demoscript
RETRYONFAIL=1
export APP_IMAGE=${APP_IMAGE:-duglin/helloworld}
export REBUILD_IMAGE=${REBUILD_IMAGE:-duglin/rebuild}
export GITREPO=${GITREPO:-duglin/helloworld}
skiptodemo=""
function cleanDemo {
echo Clean from previous run and rebuild everything
(
set +e
kubectl delete \
-f service1.yaml \
-f github.yaml \
-f rebuild.yaml \
-f secrets.yaml
kubectl delete \
clusterchannelprovisioner.eventing.knative.dev/in-memory-channel
kubectl delete horizontalpodautoscaler.autoscaling/istio-pilot
kubectl delete taskrun --all
set -e
) 2> /dev/null
# kubectl delete -f https://raw.githubusercontent.com/knative/build-templates/master/kaniko/kaniko.yaml > /dev/null 2>&1
rm -f cmds out
if ! grep "\"Hello World!\"" helloworld.go > /dev/null ; then
sed -i 's/text :=.*/text := "Hello World!"/' helloworld.go
git add helloworld.go
git commit -s -m "clean"
git push origin master
fi
make
}
# Parse our command line options
while [[ "$1" == "--"* ]]; do
case "$1" in
--clean) cleanDemo ; exit 0 ;;
--demo) skiptodemo=1 ; skip=1 ;;
*) echo "Uknown option '$1'" ; exit 1 ;;
esac
shift
done
CLUSTER=${1:-${KUBECONFIG##*-}}
export CLUSTER=${CLUSTER%.yml}
comment Set our KUBECONF env var
if [[ ! -n "${useSaved}" ]]; then
ibmcloud config --check-version false
fi
doit ibmcloud ks cluster-config -s --export ${CLUSTER}
doit $(cat out)
$(cat out)
comment Create the secrets used for accessing DockerHub and Github
doit ./kapply secrets.yaml
# Clean up from previous run
# kubectl delete -f service2.yaml > /dev/null 2>&1 || true
# doit kubectl apply -f https://raw.githubusercontent.com/knative/build-templates/master/kaniko/kaniko.yaml
if [[ -n "${skiptodemo}" ]]; then
skip=""
fi
### Start of live demo stuff
comment --pause "Start of demo! Clearing the screen"
clear
scroll helloworld.go
comment Use the easy CLI first
doit ./kn service create helloworld --image ${APP_IMAGE}
APPURL=$(grep appdomain out)
wait curl -sf ${APPURL}
doit curl -sf ${APPURL}
comment Now do it using https
doit curl -sf ${APPURL/http/https}
doit ./showresources all
doit ./kn service delete helloworld
comment Now use normal kubectl command to do more advanced stuff
# scroll service1.yaml
doit ./kapply -t service1.yaml
doit ./kapply service1.yaml
comment Wait for the app to be deployed
doit --noscroll --slowoutput ./pods --grep "helloworld.*Running"
wait kubectl get ksvc \| grep helloworld-default
wait curl -sf ${APPURL}
doit curl -sf ${APPURL}
comment "Give it a name and be explicit about traffic"
doit ./kapply -t service2.yaml
doit ./kapply service2.yaml
comment "Wait for the new version to be deployed"
doit --noscroll --slowoutput ./pods --grep "helloworld-v1.*Running"
# echo
wait "curl -sf ${APPURL} | grep v1:"
doit curl -sf ${APPURL}
comment "Deploy a new version (w/MSG) and traffic split 50/50"
doit ./kapply -t service3.yaml
doit ./kapply service3.yaml
comment "Wait for v2 to be ready, then generate a load..."
wait "kubectl get ksvc | grep helloworld-v2"
doit --noscroll --slowoutput ./load 10 10 ${APPURL}
comment --pause "Show the pretty slide!"
doit ./kapply -t service4.yaml
doit ./kapply service4.yaml
comment --pause "Let's deploy the rebuild function that github will call"
# export REBUILDURL=$(kubectl get ksvc/helloworld -o custom-columns=url:status.url --no-headers | sed "s/helloworld/rebuild/")
# doit ./kapply -t rebuild.yaml
doit ./kapply rebuild.yaml
wait "kubectl get ksvc | grep rebuild.*True"
doit kubectl get ksvc
# comment "Look at the Tekton TaskRun we'll use to build"
# doit ./kapply -t -b task.yaml
# doit ./kapply -b task.yaml
comment "Now let's deploy the github webhook, linked to our 'rebuild' function"
# scroll github.yaml
doit ./kapply -t github.yaml
doit ./kapply github.yaml
wait "kubectl get ksvc | grep githubsource.*True"
comment "Now let's edit our app and push it to github"
if [[ -n "${skip}" || -n "${useSaved}" ]]; then
STRING="Dogs rule!! Cats drool!!"
doit sed -i "\"s/text :=.*/text := \\\"${STRING}\\\"/\"" helloworld.go
doit git diff helloworld.go
else
doit --noexec vi helloworld.go
vi helloworld.go
fi
STRING=$(grep "text :=" helloworld.go | sed 's/.*"\([^"]*\)".*$/\1/')
doit git add helloworld.go
doit git commit -s -m "\"demo - $(date)\""
doit git push origin master
comment "Waiting for new version (look for '$STRING')"
skip="1" doit --norepaint --untilgrep="$STRING" --pausetime=5 \
"curl -sf ${APPURL/helloworld/helloworld-helloworld-test}"
doit curl -sf ${APPURL/helloworld/helloworld-helloworld-v1}
doit curl -sf ${APPURL/helloworld/helloworld-helloworld-v2}
# doit --noexec "curl -sf ${APPURL} (20 times)"
comment "Show main URL only hits v1 and v2, not latest"
doit 'for i in `seq 1 20` ; do curl -s '${APPURL}' ; done'
doit ./showresources all
rm cmds