-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path4-installKeptn.sh
executable file
·179 lines (156 loc) · 6.27 KB
/
4-installKeptn.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
#!/bin/bash
# load in the shared library and validate argument
source ./deploymentArgument.lib
DEPLOYMENT=$1
validate_deployment_argument $DEPLOYMENT
if ! [ "$2" == "skip" ]; then
clear
fi
echo "-------------------------------------------------------"
echo -n "Validating keptn CLI installed. "
type keptn &> /dev/null
if [ $? -ne 0 ]; then
echo "Error"
echo ">>> Missing 'keptn' CLI utility"
echo ""
exit 1
fi
echo ""
echo "OK, found: $(command -v keptn)"
echo "$(keptn version)"
echo "-------------------------------------------------------"
echo ""
KEPTN_BRANCH=$(cat creds.json | jq -r '.keptnBranch')
echo "========================================================="
echo "About to install Keptn using branch: $KEPTN_BRANCH"
echo "and to prepare credential files for Keptn installation."
if ! [ "$2" == "skip" ]; then
read -rsp $'Press ctrl-c to abort. Press any key to continue...\n' -n1 key
fi
echo ""
# get values needed for file
SOURCE_CREDS_FILE=creds.json
GITHUB_PERSONAL_ACCESS_TOKEN=$(cat $SOURCE_CREDS_FILE | jq -r '.githubPersonalAccessToken')
GITHUB_USER_NAME=$(cat $SOURCE_CREDS_FILE | jq -r '.githubUserName')
GITHUB_USER_EMAIL=$(cat $SOURCE_CREDS_FILE | jq -r '.githubUserEmail')
GITHUB_ORGANIZATION=$(cat $SOURCE_CREDS_FILE | jq -r '.githubOrg')
RESOURCE_PREFIX=$(cat creds.json | jq -r '.resourcePrefix')
CLUSTER_NAME="$RESOURCE_PREFIX"-keptn-orders-cluster
# GKE
GKE_PROJECT=$(cat $SOURCE_CREDS_FILE | jq -r '.gkeProject')
GKE_CLUSTER_ZONE=$(cat $SOURCE_CREDS_FILE | jq -r '.gkeClusterZone')
GKE_CLUSTER_REGION=$(cat $SOURCE_CREDS_FILE | jq -r '.gkeClusterRegion')
# AKS
AKS_RESOURCEGROUP="$RESOURCE_PREFIX"-keptn-orders-group
AKS_SUBSCRIPTION_ID=$(cat $SOURCE_CREDS_FILE | jq -r '.aksSubscriptionId')
# EKS
EKS_CLUSTER_REGION=$(cat $SOURCE_CREDS_FILE | jq -r '.eksClusterRegion')
echo "-------------------------------------------------------"
echo "Cloning Keptn installer repo and building credential file"
KEPTN_GIT_REPO=https://github.com/keptn/installer
echo -e "Cloning $KEPTN_GIT_REPO branch $KEPTN_BRANCH"
rm -rf installer
git clone --branch $KEPTN_BRANCH $KEPTN_GIT_REPO --single-branch
echo "-------------------------------------------------------"
echo "Creating Keptn credential files"
# copy the values we already captured
# and use them to create the creds.json file and the creds_dt.json
# files that the installers expect
case $DEPLOYMENT in
aks)
cd installer/scripts/aks
KEPTN_CREDS_FILE=creds.json
KEPTN_CREDS_SAVE_FILE=creds.sav
rm $KEPTN_CREDS_FILE 2> /dev/null
cat $KEPTN_CREDS_SAVE_FILE | \
sed 's~GITHUB_USER_NAME_PLACEHOLDER~'"$GITHUB_USER_NAME"'~' | \
sed 's~PERSONAL_ACCESS_TOKEN_PLACEHOLDER~'"$GITHUB_PERSONAL_ACCESS_TOKEN"'~' | \
sed 's~GITHUB_USER_EMAIL_PLACEHOLDER~'"$GITHUB_USER_EMAIL"'~' | \
sed 's~GITHUB_ORG_PLACEHOLDER~'"$GITHUB_ORGANIZATION"'~' | \
sed 's~CLUSTER_NAME_PLACEHOLDER~'"$CLUSTER_NAME"'~' | \
sed 's~AZURE_SUBSCRIPTION~'"$AKS_SUBSCRIPTION_ID"'~' | \
sed 's~AZURE_RESOURCE_GROUP~'"$AKS_RESOURCEGROUP"'~' >> $KEPTN_CREDS_FILE
;;
gke)
cd installer/scripts/gke
KEPTN_CREDS_FILE=creds.json
KEPTN_CREDS_SAVE_FILE=creds.sav
rm $KEPTN_CREDS_FILE 2> /dev/null
cat $KEPTN_CREDS_SAVE_FILE | \
sed 's~GITHUB_USER_NAME_PLACEHOLDER~'"$GITHUB_USER_NAME"'~' | \
sed 's~PERSONAL_ACCESS_TOKEN_PLACEHOLDER~'"$GITHUB_PERSONAL_ACCESS_TOKEN"'~' | \
sed 's~GITHUB_USER_EMAIL_PLACEHOLDER~'"$GITHUB_USER_EMAIL"'~' | \
sed 's~GITHUB_ORG_PLACEHOLDER~'"$GITHUB_ORGANIZATION"'~' | \
sed 's~CLUSTER_NAME_PLACEHOLDER~'"$CLUSTER_NAME"'~' | \
sed 's~CLUSTER_ZONE_PLACEHOLDER~'"$GKE_CLUSTER_ZONE"'~' | \
sed 's~GKE_PROJECT_PLACEHOLDER~'"$GKE_PROJECT"'~' >> $KEPTN_CREDS_FILE
;;
eks)
cd installer/scripts/gke
KEPTN_CREDS_FILE=creds.json
KEPTN_CREDS_SAVE_FILE=creds.sav
rm $KEPTN_CREDS_FILE 2> /dev/null
cat $KEPTN_CREDS_SAVE_FILE | \
sed 's~GITHUB_USER_NAME_PLACEHOLDER~'"$GITHUB_USER_NAME"'~' | \
sed 's~PERSONAL_ACCESS_TOKEN_PLACEHOLDER~'"$GITHUB_PERSONAL_ACCESS_TOKEN"'~' | \
sed 's~GITHUB_USER_EMAIL_PLACEHOLDER~'"$GITHUB_USER_EMAIL"'~' | \
sed 's~GITHUB_ORG_PLACEHOLDER~'"$GITHUB_ORGANIZATION"'~' | \
sed 's~CLUSTER_NAME_PLACEHOLDER~'"$CLUSTER_NAME"'~' | \
sed 's~CLUSTER_ZONE_PLACEHOLDER~'"$EKS_CLUSTER_REGION"'~' >> $KEPTN_CREDS_FILE
# TODO update once CLI updated
# sed 's~CLUSTER_REGION_PLACEHOLDER~'"$EKS_CLUSTER_REGION"'~' >> $KEPTN_CREDS_FILE
;;
*)
echo "Skipping keptn install. $DEPLOYMENT_NAME not supported"
exit
esac
echo ""
echo "======================================================="
echo About to install Keptn with these parameters:
echo ""
echo "cat creds.json"
cat creds.json
echo ""
echo "======================================================="
if ! [ "$2" == "skip" ]; then
read -rsp $'Press ctrl-c to abort. Press any key to continue...\n' -n1 key
fi
echo ""
echo "-------------------------------------------------------"
echo "Running keptn install This will take several minutes"
echo "-------------------------------------------------------"
START_TIME=$(date)
case $DEPLOYMENT in
gke)
keptn install -c=creds.json --platform=gke
;;
aks)
keptn install -c=creds.json --platform=aks
;;
eks)
# TODO update once CLI updated
keptn install -c=creds.json --platform=eks --keptn-version=develop --verbose
;;
esac
cd ../../..
echo "-------------------------------------------------------"
echo "Finished Running keptn install"
echo "-------------------------------------------------------"
echo "Script start time : $START_TIME"
echo "Script end time : "$(date)
echo "-------------------------------------------------------"
# show Keptn
./showKeptn.sh
case $DEPLOYMENT in
eks)
# TODO remove once CLI updated
EKS_DOMAIN=$(cat creds.json | jq -r '.eksDomain')
GITHUB_ORGANIZATION=$(cat creds.json | jq -r '.githubOrg')
GITHUB_USER_NAME=$(cat creds.json | jq -r '.githubUserName')
GITHUB_PERSONAL_ACCESS_TOKEN=$(cat creds.json | jq -r '.githubPersonalAccessToken')
echo "Updating the domain..."
keptn configure domain $EKS_DOMAIN --keptn-version=develop
echo "Updating the Keptn GitHub organization..."
keptn configure --org=$GITHUB_ORGANIZATION --user=$GITHUB_USER_NAME --token=$GITHUB_PERSONAL_ACCESS_TOKEN
;;
esac