-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathprovision.sh
executable file
·124 lines (100 loc) · 3.93 KB
/
provision.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
LOGGEDIN_USER=$(oc whoami)
## Validate if user is logged in OCP
if [ "$LOGGEDIN_USER" = *"Unable to connect to the server"* ]; then
echo "You need to login to an OpenShift cluster first."
exit 255
fi
################################################################################
# Functions #
################################################################################
function echo_header() {
echo
echo "########################################################################"
echo $1
echo "########################################################################"
}
function print_info() {
echo_header "Configuration"
#OPENSHIFT_MASTER=$(oc status | head -1 | sed 's#.*\(https://[^ ]*\)#\1#g') # must run after projects are created
OPENSHIFT_MASTER=$(oc version | tail -3 | head -1 | sed 's#.*\(https://[^ ]*\)#\1#g')
echo "Project name: ${PRJ[0]}"
echo "OpenShift master: $OPENSHIFT_MASTER"
echo "Current user: $LOGGEDIN_USER"
echo "Project suffix: $PRJ_SUFFIX"
}
# Create Project
function create_projects() {
echo_header "Creating project..."
echo "Creating project ${PRJ[0]}"
oc new-project "${PRJ[0]}" --display-name="${PRJ[1]}" --description="${PRJ[2]}" >/dev/null
}
function wait_while_empty() {
local _NAME=$1
local _TIMEOUT=$(($2/5))
local _CONDITION=$3
echo "Waiting for $_NAME to be ready..."
local x=1
while [ -z "$(eval ${_CONDITION})" ]
do
echo "."
sleep 5
x=$(( $x + 1 ))
if [ $x -gt $_TIMEOUT ]
then
echo "$_NAME still not ready, I GIVE UP!"
exit 255
fi
done
echo "$_NAME is ready."
}
#Runs a spinner for the time passed to the function.
function runSpinner() {
sleeptime=0.5
maxCount=$( bc <<< "$1 / $sleeptime")
counter=0
i=1
sp="/-\|"
while [ $counter -lt $maxCount ]
do
printf "\b${sp:i++%${#sp}:1}"
sleep $sleeptime
let counter=counter+1
done
}
START=`date +%s`
################################################################################
# Configuration #
################################################################################
PRJ=("rhdm-kieserver-cicd" "Decision Services CI/CD Demo" "Red Hat Decision Manager deployment automation demo")
################################################################################
# Provisioning #
################################################################################
## Create a new project for the v7 Spring-boot based cicd demo
echo_header "Creating namespace $PRJ"
create_projects
echo_header "Installing OpenShift Pipelines (Tekton) and pipeline resources"
## Install OpenShift Pipelines Operator
oc apply -f ./support/tekton-operator/sub.yaml
wait_while_empty "Openshift Pipelines Operator" 100 "oc get ClusterServiceVersion | grep redhat-openshift-pipelines | grep -i succeed | awk '{ printf \$8 }'"
runSpinner 10
oc create -f ./cicd/tekton-resources/ -n $PRJ
runSpinner 5
oc expose svc el-ba-cicd-event-listener -n $PRJ
# Front end application
echo_header "Deploying front-end application"
oc new-app quay.io/rafaeltuelho/decision-service-webclient -n $PRJ
oc expose service/decision-service-webclient -n $PRJ
echo ""
echo ""
echo "******************************************************************"
echo ""
echo "Use this URL in your GitHub Webhook configuration for automatic deployment"
echo "$(oc get route el-ba-cicd-event-listener --template='http://{{.spec.host}}' -n $PRJ)"
echo ""
echo "Use this URL to access the front-end application: "
echo "$(oc get route decision-service-webclient --template='http://{{.spec.host}}' -n $PRJ)"
echo ""
echo "******************************************************************"
END=`date +%s`
echo
echo "Provisioning done! (Completed in $(( ($END - $START)/60 )) min $(( ($END - $START)%60 )) sec)"