forked from Informasjonsforvaltning/fdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·224 lines (168 loc) · 5.68 KB
/
deploy.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
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
#!/usr/bin/env bash
set -e
# Deployment pipeline (environment order)
# UT1 -> ST2 -> TT1 -> ST1 ->PPE
# -> PP2 -> PPE
# -> UT2
# UT1: Development environment. Build server continually deploys to this environment
# ST2: Internal test server with local (mocked) authorisation
# TT1: Externally accessible test server with local (mocked) authorisation
# ST1: Internal test servew with Idporten authorisation. Uses Idporten test environment
# PPE: Pre-production environment. Runs on production cluster. Idporten production authorisation
# some input validation
if [ -z "$1" ]
then
echo "component must be specified: search, registration, search-api etc..."
echo "correct usage: ./deploy.sh <component> <environment>"
echo "example: ./deploy.sh search st2"
echo "use all to deploy all components. Example: ./deploy.sh all st2"
exit 1
fi
if [ -z "$2" ]
then
echo "environment must be specified: ut1, st1, st2, tt1. pp2, ppe or prd"
echo "correct usage: ./deploy.sh <component> <environment>"
echo "example: ./deploy.sh harvester-api tt1"
exit 1
fi
component=$1
environment=$2
git fetch
GIT_STATUS=`git status | grep "Your branch is"`
if [ "${GIT_STATUS}" != "Your branch is up to date with 'origin/develop'." ] ; then
echo "You need to be on origin/develop and be up to date with origin";
exit;
fi
components="fuseki harvester harvester-api nginx-registration nginx-search reference-data registration-react registration-api registration-auth search api-cat search-api"
# fetch all tags from github
git fetch --prune --tags
DATETIME=`date "+%Y-%m-%dT%H_%M_%S"`
# doesnt work in git bash on Windows. Log in with docker login -u user -p passwd before running script
#docker login --username ${dockerUsername} --password ${dockerPassword}
function dockerTag {
component=$1
fromEnvironment=$2
toEnvironment=$3
# pull image from docker hub (overwrites local image if it exists)
docker pull dcatno/${component}:${fromEnvironment}_latest
# tag and push latest eg. registration_latest
docker tag dcatno/${component}:${fromEnvironment}_latest dcatno/${component}:${toEnvironment}_latest
docker push dcatno/${component}:${toEnvironment}_latest
# tag and push with date eg. registration_2017-01-01T23_59_01
docker tag dcatno/${component}:${fromEnvironment}_latest dcatno/${component}:${toEnvironment}_${DATETIME}
docker push dcatno/${component}:${toEnvironment}_${DATETIME}
}
function gitTag {
component=$1
fromEnvironment=$2
toEnvironment=$3
echo "Checkout tags/${fromEnvironment}_latest"
git checkout tags/${fromEnvironment}_latest
# tag checked-out commit with ***_latest tag
echo "delete origin tag ${toEnvironment}_latest"
git push --delete origin ${toEnvironment}_latest
echo "tag ${toEnvironment}_latest"
git tag -f ${toEnvironment}_latest
echo "tag ${toEnvironment}_${DATETIME}"
git tag -f ${toEnvironment}_${DATETIME}
if [ "$component" != "all" ] ; then
# if only one component is deployed, also label it with component name
git push --delete origin ${toEnvironment}_latest_${component}
git tag -f ${toEnvironment}_latest_${component}
git tag -f ${toEnvironment}_${DATETIME}_${component}
fi
# push all tags to github
echo "push tags"
git push origin --tags
# don't forget to checkout develop again, don't want any surprises later
echo "checkout develop"
git checkout develop
}
#function openshiftDeploy {
# osEnvironment=$1
# dateTag=$2
#
# #Deply new images on openshift - assuming all services are correctly set up
# # sh runCreateAllServicesInOpenshift.sh $osEnvironment $datetag $dateTag onlyDeployImages
#}
if [ "$environment" == "st1" ] ; then
if [ "$component" == "all" ] ; then
for i in $components
do
dockerTag ${i} tt1 st1
done
else
dockerTag ${component} tt1 st1
fi
gitTag ${component} tt1 st1
elif [ "$environment" == "st2" ] ; then
if [ "$component" == "all" ] ; then
for i in $components
do
dockerTag ${i} ut1 st2
done
else
dockerTag ${component} ut1 st2
fi
gitTag ${component} ut1 st2
#temporary environment for testing elasticsearch 5.x
elif [ "$environment" == "ut2" ] ; then
if [ "$component" == "all" ] ; then
for i in $components
do
dockerTag ${i} ut1 ut2
done
else
dockerTag ${component} ut1 ut2
fi
gitTag ${component} ut1 ut2
elif [ "$environment" == "tt1" ] ; then
if [ "$component" == "all" ] ; then
for i in $components
do
dockerTag ${i} st2 tt1
done
else
dockerTag ${component} st2 tt1
fi
gitTag ${component} st2 tt1
elif [ "$environment" == "pp2" ] ; then
if [ "$component" == "all" ] ; then
for i in $components
do
dockerTag ${i} ut1 pp2
done
else
dockerTag ${component} ut1 pp2
fi
gitTag ${component} ut1 pp2
elif [ "$environment" == "ppe" ] ; then
if [ "$component" == "all" ] ; then
for i in $components
do
dockerTag ${i} st1 ppe
done
else
dockerTag ${component} st1 ppe
fi
gitTag ${component} st1 ppe
elif [ "$environment" == "prod" ] ; then
if [ "$component" == "all" ] ; then
for i in $components
do
dockerTag ${i} ppe prod
done
else
dockerTag ${component} ppe prod
fi
gitTag ${component} ppe prod
else
echo "####################################"
echo "####################################"
echo ""
echo "Non-valid environment specified"
echo ""
echo "####################################"
echo "####################################"
fi
echo "Done";