-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathinstall.sh
executable file
·198 lines (174 loc) · 7.48 KB
/
install.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
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
187
188
189
190
191
192
193
194
195
196
197
198
#!/bin/bash
set -e
log() {
echo
echo "##### $*"
}
terminate() {
log "$*"
exit 1
}
wait_for_resource() {
local timeout=$(($(date +%s) + 300))
while ((timeout > $(date +%s))); do
[[ "$(oc get -n "$NAMESPACE" "$@" -o 'go-template={{len .items}}' 2>/dev/null)" -gt 0 ]] && break
sleep 5
done
if [[ ${timeout} < "$(date +%s)" ]]; then
terminate "Error: timed out while waiting for '$*' (in namespace: $NAMESPACE) to exist."
fi
}
# Wait for an operator to exist and be ready.
#
# $1 the label of the operator, for showing the user
# $2 the name of the operator resource (.spec.name from Subscription)
wait_for_operator() {
local name="$1"
shift
local subscription="$1"
shift
local sel="deployment -l operators.coreos.com/${subscription}.${NAMESPACE}"
log "Waiting for $name operator"
# shellcheck disable=SC2086
wait_for_resource $sel
# shellcheck disable=SC2086
oc -n "${NAMESPACE}" wait --for=condition=Available $sel --timeout=300s
}
source install_cleanup_vars.sh
test -f .env && source .env
#--------------------------
# If Weather API keys are empty, set a default value.
#--------------------------
if [[ -z "$OWM_WEATHER_API_KEY" ]]; then
OWM_WEATHER_API_KEY='my-owm-api-key';
fi
if [[ -z "$IBM_WEATHER_API_KEY" ]]; then
IBM_WEATHER_API_KEY='my-ibm-api-key';
fi
#--------------------------
# Installing OpenShift Serverless operator (optional)
#--------------------------
if [[ "$INSTALL_KNATIVE" == true ]]; then
log "Installing OpenShift Serverless operator"
oc apply -f config/operators/serverless-operator-subscription.yaml
sleep 25
log "Waiting for OpenShift Serverless operator"
oc -n openshift-serverless wait --for=condition=Available deployment -l operators.coreos.com/serverless-operator.openshift-serverless --timeout=300s
log "Installing Knative Serving config"
oc apply -f config/knative/knative-serving.yaml
log "Installing Knative Eventing config"
oc apply -f config/knative/knative-eventing.yaml
log "Installing Knative Kafka config"
oc apply -f config/knative/knative-kafka.yaml
sleep 10
oc wait --for=condition=Ready knativeservings.v1beta1.operator.knative.dev/knative-serving --timeout 500s -n knative-serving
oc wait --for=condition=Ready knativeeventings.v1beta1.operator.knative.dev/knative-eventing --timeout 500s -n knative-eventing
oc wait --for=condition=Ready knativekafkas.v1alpha1.operator.serverless.openshift.io/knative-kafka --timeout 500s -n knative-eventing
log "OpenShift Serverless Installation has been completed!!"
fi
#--------------------------
# Installing namespaced operators: Camel-K, Datagrid, AMQ Stream, AMQ Broker is optional in case of Drogue deployment
#--------------------------
if [[ "$INSTALL_OPERATORS" == true ]]; then
log "Creating namespace $NAMESPACE for Bobbycar demo"
oc new-project "$NAMESPACE" || true
log "Installing operator group"
sed "s:{{NAMESPACE}}:$NAMESPACE:g" config/operators/operator-group.yaml | oc apply -f -
if [[ "$DROGUE_IOT" != true ]]; then
log "Installing the AMQ Broker operator"
sed "s:{{NAMESPACE}}:$NAMESPACE:g" config/operators/amq-operator-subscription.yaml | oc apply -f -
fi
log "Installing the AMQ Streams operator"
sed "s:{{NAMESPACE}}:$NAMESPACE:g" config/operators/amq-streams-operator-subscription.yaml | oc apply -f -
log "Installing the Datagrid operator"
sed "s:{{NAMESPACE}}:$NAMESPACE:g" config/operators/datagrid-subscription.yaml | oc apply -f -
log "Installing the Camel-K operator"
sed "s:{{NAMESPACE}}:$NAMESPACE:g" config/operators/camel-k-operator-subscription.yaml | oc apply -f -
#--------------------------
# Waiting until all operator deployments are available
#--------------------------
if [[ "$DROGUE_IOT" != true ]]; then
wait_for_operator "AMQ Broker" amq-broker-rhel8
fi
wait_for_operator "AMQ Streams" amq-streams
wait_for_operator "Datagrid" datagrid
wait_for_operator "Camel-K" red-hat-camel-k
fi
#--------------------------
# Installing the Infra Helm chart, Drogue Cloud is optional
#--------------------------
log "Installing the infra Helm release: $HELM_INFRA_RELEASE_NAME"
INFRA_OPTS=("-f" "helm/bobbycar-core-infra/values.yaml")
if [[ "$DROGUE_IOT" == true ]]; then
INFRA_OPTS+=("-f" "helm/bobbycar-core-infra/values.drogue.yaml")
INFRA_OPTS+=("--set-string" "global.domain=-${NAMESPACE}.${APP_DOMAIN}")
helm repo add drogue-iot https://drogue-iot.github.io/drogue-cloud-helm-charts/
helm dependency build helm/bobbycar-core-infra
fi
helm upgrade --install "$HELM_INFRA_RELEASE_NAME" helm/bobbycar-core-infra/ \
"${INFRA_OPTS[@]}" \
--set-string namespace="$NAMESPACE" \
--set-string ocpDomain="$APP_DOMAIN" \
--set drogueIoT="$DROGUE_IOT"
sleep 30
#--------------------------
# Waiting until infra components are running
#--------------------------
if [[ "$DROGUE_IOT" != true ]]; then
log "Waiting for AMQ Broker pod"
oc wait --for=condition=Ready pod/bobbycar-amq-mqtt-ss-0 --timeout 300s
fi
log "Waiting for Datagrid pod"
oc wait --for=condition=Ready pod/bobbycar-dg-0 --timeout 300s
log "Waiting for Kafka Broker pod"
oc wait --for=condition=Ready pod/bobbycar-cluster-kafka-0 --timeout 300s
log "Waiting for Kafka Bridge pod"
[[ "$DROGUE_IOT" != true ]] && oc wait --for=condition=Available deployment/bobbycar-bridge --timeout 300s
#--------------------------
# Installing the Applications Helm Chart
#--------------------------
log "Installing the apps Helm release: $HELM_APP_RELEASE_NAME"
APPS_OPTS=("-f" "helm/bobbycar-core-apps/values.yaml")
if [[ "$DROGUE_IOT" == true ]]; then
APPS_OPTS+=("-f" "helm/bobbycar-core-apps/values.drogue.yaml")
fi
helm upgrade --install "$HELM_APP_RELEASE_NAME" helm/bobbycar-core-apps \
"${APPS_OPTS[@]}" \
--set-string ocpDomain="$APP_DOMAIN" \
--set-string ocpApi="$API_DOMAIN" \
--set-string namespace="$NAMESPACE" \
--set-string dashboard.config.googleApiKey="$GOOGLE_API_KEY" \
--set-string weatherService.owm.api.key="$OWM_WEATHER_API_KEY" \
--set-string weatherService.ibm.api.key="$IBM_WEATHER_API_KEY" \
--set-string dashboard.config.ocpApiUrl="https://$API_DOMAIN:6443" \
--set drogueIoT="$DROGUE_IOT"
sleep 30
#--------------------------
# Waiting until some core app components are running
#--------------------------
log "Waiting for Bobbycar pod"
oc wait --for=condition=Available deployment/car-simulator --timeout 300s
log "Waiting for Bobbycar Dashboard pod"
oc wait --for=condition=Available dc/dashboard --timeout 300s
log "Waiting for Dashboard Streaming service pod"
oc wait --for=condition=Available deployment/dashboard-streaming --timeout 300s
#--------------------------
# Installing the Serverless Helm Chart
#--------------------------
log "Installing the Serverless Helm release: $HELM_SERVERLESS_RELEASE_NAME"
helm upgrade --install "$HELM_SERVERLESS_RELEASE_NAME" helm/bobbycar-opt-serverless \
--set-string namespace="$NAMESPACE" \
--set drogueIoT="$DROGUE_IOT" \
--set-string otaServer.url="http://ota-server-$NAMESPACE.$APP_DOMAIN"
#--------------------------
# Waiting until Camel-K integrations are build and running (takes around 5-10 minutes)
#--------------------------
log "Waiting for Camel-K integrations to complete..."
oc wait --for=condition=Ready integration/cache-service --timeout 1800s
oc wait --for=condition=Ready integration/kafka2datagrid --timeout 1800s
[[ "$DROGUE_IOT" != true ]] && oc wait --for=condition=Ready integration/mqtt2kafka --timeout 1800s
#--------------------------
# Done!
#--------------------------
log "Installation completed! Open the Bobbycar dashboard and get started:"
oc get route dashboard -o json | jq -r .spec.host