forked from Kong/docker-kong
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbintray-release.sh
executable file
·343 lines (284 loc) · 9.56 KB
/
bintray-release.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
#!/usr/bin/env bash
set -o errexit
function usage {
cat << EOF
Build Kong EE Docker images and upload to our Bintray registry
usage: $0 options
-e Kong Enterprise
-v Kong EE version to target (REQUIRED)
-u Bintray username (REQUIRED)
-k Bintray API key (REQUIRED)
-o Bintray organization
-r Bintray Docker registry address
-i Build internal preview
-p Platforms to build for
-b Build only
-P Push only
-l Create 'latest' tag - which is a link to alpine distro
-a Disable anonymous reports (a stands for anonymous)
-h Print this help message
EOF
exit 1
}
if ! hash python &> /dev/null; then
echo "Python is required, please install it."
exit 1
fi
BINTRAY_ORG="kong"
BINTRAY_USR=
BINTRAY_KEY=
PLATFORMS=all
NO_PHONE_HOME=
NO_PHONE_HOME_NAME=reports-off
KONG_EDITION="community-edition"
while getopts "R:v:u:k:o:r:bPp:hliea" option; do
case $option in
v)
KONG_VERSION=$OPTARG
;;
u)
BINTRAY_USR=$OPTARG
;;
k)
BINTRAY_KEY=$OPTARG
;;
o)
BINTRAY_ORG=$OPTARG
;;
r)
BINTRAY_REGISTRY_URL=$OPTARG
;;
R)
KONG_RELEASE=$OPTARG
;;
e)
KONG_ENTERPRISE=true
KONG_EDITION="enterprise-edition"
;;
i)
INTERNAL_PREVIEW=true
;;
l)
TAG_LATEST=true
;;
b)
BUILD_ONLY=true
;;
P)
PUSH_ONLY=true
;;
p)
PLATFORMS=$OPTARG
;;
h)
usage
;;
a)
NO_PHONE_HOME=1
;;
esac
done
if [[ "$KONG_RELEASE" == rc* ]] ; then
KONG_RC=$KONG_RELEASE
fi
if [[ "$KONG_RELEASE" == "internal-preview" ]] ; then
INTERNAL_PREVIEW=true
fi
if [[ -z $BINTRAY_USR ]] || [[ -z $BINTRAY_KEY ]] || [[ -z $KONG_VERSION ]]; then
usage
fi
if { [[ -n $INTERNAL_PREVIEW ]] || [[ -n $KONG_RC ]] ;} && [[ -n $NO_PHONE_HOME ]]; then
echo "We do not build nor push internal preview images or rcs without phone home"
echo "Doing nothing --> No error, keep jenkins happy"
exit 0
fi
BINTRAY_REGISTRY_URL="kong-docker-kong-enterprise-edition-docker.bintray.io"
if [[ -n $INTERNAL_PREVIEW ]]; then
BINTRAY_REGISTRY_URL="kong-docker-kong-community-edition-internal-preview-docker.bintray.io"
if [[ -n $KONG_ENTERPRISE ]]; then
BINTRAY_REGISTRY_URL="kong-docker-kong-enterprise-edition-internal-preview-docker.bintray.io"
fi
BINTRAY_INTERNAL_PACKAGE_REPO="kong-community-edition-internal-preview"
if [[ -n $KONG_ENTERPRISE ]]; then
BINTRAY_INTERNAL_PACKAGE_REPO="kong-enterprise-edition-internal-preview"
fi
fi
if [[ -n $KONG_RC ]]; then
if [[ -n $KONG_ENTERPRISE ]]; then
BINTRAY_REGISTRY_URL="kong-docker-kong-enterprise-edition-rc-docker.bintray.io"
fi
BINTRAY_INTERNAL_PACKAGE_REPO="kong-community-edition-rc"
if [[ -n $KONG_ENTERPRISE ]]; then
BINTRAY_INTERNAL_PACKAGE_REPO="kong-enterprise-edition-rc"
fi
fi
supported_platforms=(alpine centos rhel)
platforms_to_build=()
for platform in "$PLATFORMS"; do
if [[ "all" == "$platform" ]]; then
platforms_to_build=("${supported_platforms[@]}")
elif ! [[ ${supported_platforms[*]} = *$platform* ]]; then
echo "Supported platforms:"
IFS=$'\n'; echo -e "${supported_platforms[*]}"
echo "all - to build all for platforms"
exit 1
else
platforms_to_build+=($platform)
fi
done
function build_no_phone_home {
local platform=$1
pushd phone-home-off > /dev/null
docker build --build-arg BASE_IMAGE=kong-$KONG_EDITION:$platform-$KONG_VERSION \
-t kong-$KONG_EDITION:$platform-$NO_PHONE_HOME_NAME-$KONG_VERSION .
popd > /dev/null
}
function build_alpine_image {
local alpine_url=$(curl -u $BINTRAY_USR:$BINTRAY_KEY -s -XPOST \
"https://bintray.com/api/v1/signed_url/kong/${BINTRAY_INTERNAL_PACKAGE_REPO:=kong-$KONG_EDITION-alpine-tar}/kong-$KONG_EDITION-$KONG_VERSION${INTERNAL_PREVIEW:+-internal-preview}${KONG_RC:+-$KONG_RC}.apk.tar.gz" \
-H "Content-Type: application/json" -d '{"valid_for_secs": 300}' \
| python -c "import sys, json; print(json.load(sys.stdin)['url'])")
echo $alpine_url
echo "Building Kong ($KONG_EDITION) Alpine image..."
pushd alpine > /dev/null
curl -o kong.tar.gz -L "${alpine_url}"
docker build --build-arg KONG_ENTERPRISE_PACKAGE=kong.tar.gz \
-t kong-$KONG_EDITION:alpine-$KONG_VERSION .
popd > /dev/null
echo "Kong EE Alpine image built successfully"
if [[ -n $NO_PHONE_HOME ]]; then
build_no_phone_home alpine
fi
}
function build_centos_image {
local centos_url=$(curl -u $BINTRAY_USR:$BINTRAY_KEY -s -XPOST \
"https://bintray.com/api/v1/signed_url/kong/${BINTRAY_INTERNAL_PACKAGE_REPO:=kong-$KONG_EDITION-rpm/centos/7}/kong-$KONG_EDITION-$KONG_VERSION${INTERNAL_PREVIEW:+-internal-preview}${KONG_RC:+-$KONG_RC}.el7.noarch.rpm" \
-H "Content-Type: application/json" -d '{"valid_for_secs": 300}' \
| python -c "import sys, json; print(json.load(sys.stdin)['url'])")
echo $centos_url
echo "Building Kong ($KONG_EDITION) CentOS image..."
pushd centos > /dev/null
curl -o kong.rpm -L "${centos_url}"
docker build --build-arg KONG_ENTERPRISE_PACKAGE=kong.rpm \
-t kong-$KONG_EDITION:centos-$KONG_VERSION .
popd > /dev/null
echo "Kong EE CentOS image built successfully"
if [[ -n $NO_PHONE_HOME ]]; then
build_no_phone_home centos
fi
}
function build_rhel_image {
local rhel_url=$(curl -u $BINTRAY_USR:$BINTRAY_KEY -s -XPOST \
"https://bintray.com/api/v1/signed_url/kong/${BINTRAY_INTERNAL_PACKAGE_REPO:=kong-$KONG_EDITION-rpm/rhel/7}/kong-$KONG_EDITION-$KONG_VERSION${INTERNAL_PREVIEW:+-internal-preview}${KONG_RC:+-$KONG_RC}.rhel7.noarch.rpm" \
-H "Content-Type: application/json" -d '{"valid_for_secs": 300}' \
| python -c "import sys, json; print(json.load(sys.stdin)['url'])")
echo $rhel_url
echo "Building Kong ($KONG_EDITION) RHEL image..."
pushd rhel > /dev/null
curl -o kong.rpm -L "${rhel_url}"
docker build --build-arg KONG_ENTERPRISE_PACKAGE=kong.rpm \
-t kong-$KONG_EDITION:rhel-$KONG_VERSION .
popd > /dev/null
echo "Kong EE RHEL image built successfully"
if [[ -n $NO_PHONE_HOME ]]; then
build_no_phone_home rhel
fi
}
function push_alpine_image {
local local_tag="kong-$KONG_EDITION:alpine-$KONG_VERSION"
if [[ -n $NO_PHONE_HOME ]]; then
BINTRAY_REGISTRY_URL="kong-docker-kong-enterprise-edition-$NO_PHONE_HOME_NAME-docker.bintray.io"
local_tag="kong-$KONG_EDITION:alpine-$NO_PHONE_HOME_NAME-$KONG_VERSION"
fi
docker login -u $BINTRAY_USR -p $BINTRAY_KEY \
$BINTRAY_REGISTRY_URL
echo "Pushing Kong ($KONG_EDITION) Alpine Docker image..."
# tag image accordingly
docker tag $local_tag \
$BINTRAY_REGISTRY_URL/kong-$KONG_EDITION:$KONG_VERSION-alpine
# push image to our registry
docker push $BINTRAY_REGISTRY_URL/kong-$KONG_EDITION:$KONG_VERSION-alpine
# update latest tag
if [[ -n $TAG_LATEST ]]; then
docker tag $BINTRAY_REGISTRY_URL/kong-$KONG_EDITION:$KONG_VERSION-alpine \
$BINTRAY_REGISTRY_URL/kong-$KONG_EDITION:latest
docker push $BINTRAY_REGISTRY_URL/kong-$KONG_EDITION:latest
fi
docker logout $BINTRAY_REGISTRY_URL
}
function push_centos_image {
local local_tag="kong-$KONG_EDITION:centos-$KONG_VERSION"
if [[ -n $NO_PHONE_HOME ]]; then
BINTRAY_REGISTRY_URL="kong-docker-kong-enterprise-edition-$NO_PHONE_HOME_NAME-docker.bintray.io"
local_tag="kong-$KONG_EDITION:centos-$NO_PHONE_HOME_NAME-$KONG_VERSION"
fi
docker login -u $BINTRAY_USR -p $BINTRAY_KEY \
$BINTRAY_REGISTRY_URL
echo "Pushing Kong ($KONG_EDITION) CentOS Docker image..."
# tag image accordingly
docker tag $local_tag \
$BINTRAY_REGISTRY_URL/kong-$KONG_EDITION:$KONG_VERSION-centos
# push image to our registry
docker push $BINTRAY_REGISTRY_URL/kong-$KONG_EDITION:$KONG_VERSION-centos
docker logout $BINTRAY_REGISTRY_URL
}
function push_rhel_image {
local local_tag="kong-$KONG_EDITION:rhel-$KONG_VERSION"
if [[ -n $NO_PHONE_HOME ]]; then
BINTRAY_REGISTRY_URL="kong-docker-kong-enterprise-edition-$NO_PHONE_HOME_NAME-docker.bintray.io"
local_tag="kong-$KONG_EDITION:rhel-$NO_PHONE_HOME_NAME-$KONG_VERSION"
fi
docker login -u $BINTRAY_USR -p $BINTRAY_KEY \
$BINTRAY_REGISTRY_URL
echo "Pushing Kong EE RHEL Docker image..."
# tag image accordingly
docker tag $local_tag \
$BINTRAY_REGISTRY_URL/kong-$KONG_EDITION:$KONG_VERSION-rhel
# push image to our registry
docker push $BINTRAY_REGISTRY_URL/kong-$KONG_EDITION:$KONG_VERSION-rhel
docker logout $BINTRAY_REGISTRY_URL
}
# Do the build/push process for each selected platform
for platform in "${platforms_to_build[@]}"; do
case $platform in
alpine)
if [[ -z $PUSH_ONLY ]]; then
build_alpine_image
fi
if [[ -z $BUILD_ONLY ]]; then
if [[ -z $(docker images --format "{{.Repository}}" \
kong-$KONG_EDITION:alpine-$KONG_VERSION) ]]; then
echo "Alpine image not found; build it first!"
continue
fi
push_alpine_image
fi
;;
centos)
if [[ -z $PUSH_ONLY ]]; then
build_centos_image
fi
if [[ -z $BUILD_ONLY ]]; then
if [[ -z $(docker images --format "{{.Repository}}" \
kong-$KONG_EDITION:centos-$KONG_VERSION) ]]; then
echo "CentOS image not found; build it first!"
continue
fi
push_centos_image
fi
;;
rhel)
if [[ -z $PUSH_ONLY ]]; then
build_rhel_image
fi
if [[ -z $BUILD_ONLY ]]; then
if [[ -z $(docker images --format "{{.Repository}}" \
kong-enterprise-edition:rhel-$KONG_VERSION) ]]; then
echo "RHEL image not found; build it first!"
continue
fi
push_rhel_image
fi
;;
esac
done