-
Notifications
You must be signed in to change notification settings - Fork 0
/
init.sh
executable file
·59 lines (51 loc) · 1.45 KB
/
init.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
#!/usr/bin/env bash
# check if all required variables are set
if [ -z "$APP" ] || [ -z "$PHASE" ] || [ -z "$PIPELINE" ] || [ -z "$REPOSITORY" ] || [ -z "$TAG" ] || [ -z "$SERVICE_ACCOUNT" ] || [ -z "$BUILDER" ] || [ -z "$URL" ] || [ -z "$REVISION" ]; then
echo "$(date) One or more required variables are not set"
exit 1
fi
kubectl apply -f - <<EOF
apiVersion: kpack.io/v1alpha2
kind: Build
metadata:
name: ${APP}-${TAG}
spec:
tags:
- ${REPOSITORY}:${TAG}
serviceAccountName: ${SERVICE_ACCOUNT}
builder:
image: ${BUILDER}
source:
git:
url: ${URL}
revision: ${REVISION}
EOF
# check if kubectl command failed
if [ $? -ne 0 ]; then
echo "$(date) Failed to create build pod"
exit 1
fi
sleep 2
## check with kubectl if the pod is completed
while true; do
PHASE=$(kubectl get pod ${APP}-${TAG}-build-pod -o jsonpath='{.status.phase}')
if [ "$PHASE" == "Succeeded" ]; then
echo "$(date) Build completed successfully"
break
fi
if [ "$PHASE" == "Failed" ]; then
echo "$(date) uild failed"
break
fi
echo "$(date) Waiting for build to complete...$PHASE"
sleep 1
done
sleep 2
# patch kuberoes resource with the new image
kubectl patch --type=merge kuberoapps.application.kubero.dev ${APP} -p "{\"spec\":{\"image\":{\"repository\":\"${REPOSITORY}\",\"tag\":\"${TAG}\"}}}"
if [ $? -ne 0 ]; then
echo "$(date) Failed to patch kubero app resource"
exit 1
fi
echo "$(date) Successfully patched kubero app resource"
exit 0