forked from eclipse-archived/codewind
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
401 lines (345 loc) · 17.8 KB
/
Jenkinsfile
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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
#!groovy
pipeline {
agent {
label "docker-build"
}
triggers {
issueCommentTrigger('trigger_build')
}
options {
timestamps()
skipStagesAfterUnstable()
}
stages {
stage('Build Docker images') {
steps {
withDockerRegistry([url: 'https://index.docker.io/v1/', credentialsId: 'docker.com-bot']) {
// NOTE: change of this sh call should be in sync with './script/build.sh'.
sh '''#!/usr/bin/env bash
# Docker system prune
echo "Docker system prune ..."
docker system df
docker system prune -a --volumes -f
docker builder prune -a -f
docker system df
df -lh
echo "Starting build for Eclipse Codewind ..."
DIR=`pwd`;
SRC_DIR=$DIR/src;
PFE=pfe
PERFORMANCE=performance;
KEYCLOAK=keycloak;
GATEKEEPER=gatekeeper;
ARCH=`uname -m`;
TAG=latest;
REGISTRY=eclipse
# On intel, uname -m returns "x86_64", but the convention for our docker images is "amd64"
if [ "$ARCH" == "x86_64" ]; then
IMAGE_ARCH="amd64"
else
IMAGE_ARCH=$ARCH
fi
ALL_IMAGES="$PFE $PERFORMANCE $KEYCLOAK $GATEKEEPER";
# Copy .env over to file-watcher
if [ -f $DIR/.env ]; then
echo -e "\nCopying $DIR/.env to ${SRC_DIR}/${PFE}/file-watcher/scripts/.env\n"
cp $DIR/.env ${SRC_DIR}/${PFE}/file-watcher/scripts/.env
fi
# Copy the license files to the portal, performance, keycloak and gatekeeper
cp -r $DIR/LICENSE ${SRC_DIR}/pfe/portal/
cp -r $DIR/NOTICE.md ${SRC_DIR}/pfe/portal/
cp -r $DIR/LICENSE ${SRC_DIR}/performance/
cp -r $DIR/NOTICE.md ${SRC_DIR}/performance/
cp -r $DIR/LICENSE ${SRC_DIR}/keycloak/
cp -r $DIR/NOTICE.md ${SRC_DIR}/keycloak/
cp -r $DIR/LICENSE ${SRC_DIR}/gatekeeper/
cp -r $DIR/NOTICE.md ${SRC_DIR}/gatekeeper/
# Copy the docs into portal
cp -r $DIR/docs ${SRC_DIR}/pfe/portal/
echo -e "\n+++ DOWNLOADING EXTENSIONS +++\n";
if [ $GIT_BRANCH == "master" ]; then
VERSION="9.9.9999"
else
VERSION="$GIT_BRANCH"
fi
mkdir -p ${SRC_DIR}/pfe/extensions
rm -f ${SRC_DIR}/pfe/extensions/codewind-appsody-extension-*.zip
rm -f ${SRC_DIR}/pfe/extensions/codewind-odo-extension-*.zip
curl -Lo ${SRC_DIR}/pfe/extensions/codewind-appsody-extension-$VERSION.zip http://download.eclipse.org/codewind/codewind-appsody-extension/$GIT_BRANCH/latest/codewind-appsody-extension-$VERSION.zip
curl -Lo ${SRC_DIR}/pfe/extensions/codewind-odo-extension-$VERSION.zip http://download.eclipse.org/codewind/codewind-odo-extension/$GIT_BRANCH/latest/codewind-odo-extension-$VERSION.zip
# BUILD IMAGES
# Uses a build file in each of the directories that we want to use
echo -e "\n+++ BUILDING DOCKER IMAGES +++\n";
for image in $ALL_IMAGES
do
export IMAGE_NAME=codewind-$image-$IMAGE_ARCH
echo Building image $IMAGE_NAME;
cd ${SRC_DIR}/${image};
time sh build Dockerfile_${ARCH};
if [ $? -eq 0 ]; then
echo "+++ SUCCESSFULLY BUILT $IMAGE_NAME +++";
else
echo "+++ FAILED TO BUILD $IMAGE_NAME - exiting. +++";
exit 12;
fi
done;
echo -e "\n+++ ALL DOCKER IMAGES SUCCESSFULLY BUILT +++\n";
docker images | grep codewind;
'''
}
}
}
stage('Run Turbine Unit Test Suite') {
options {
timeout(time: 30, unit: 'MINUTES')
}
steps {
withEnv(["PATH=$PATH:~/.local/bin;NOBUILD=true"]) {
withDockerRegistry([url: 'https://index.docker.io/v1/', credentialsId: 'docker.com-bot']) {
sh '''#!/usr/bin/env bash
echo "Starting unit tests for Turbine..."
export PATH=$PATH:/home/jenkins/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node_js/bin/
ARCH=`uname -m`;
printf "\n\n${MAGENTA}Platform: $ARCH ${RESET}\n"
# Install nvm to easily set version of node to use
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
export NVM_DIR="$HOME/.nvm"
. $NVM_DIR/nvm.sh
nvm i 10
# Run eslint on turbine code
cd src/pfe/file-watcher/server
npm install
if [ $? -ne 0 ]; then
exit 1
fi
# Run the unit test suite
echo "Started running Turbine Unit Test Suite"
npm run unit:test
if [ $? -eq 0 ]; then
echo "+++ TURBINE UNIT TESTS COMPLETED SUCCESSFULLY +++";
else
echo "+++ TURBINE UNIT TESTS FAILED +++";
exit 1;
fi
'''
}
}
}
}
stage('Run Codewind test suite') {
options {
timeout(time: 2, unit: 'HOURS')
}
steps {
withEnv(["PATH=$PATH:~/.local/bin;NOBUILD=true"]){
withDockerRegistry([url: 'https://index.docker.io/v1/', credentialsId: 'docker.com-bot']) {
sh '''#!/usr/bin/env bash
echo "Starting tests for Eclipse Codewind ..."
export PATH=$PATH:/home/jenkins/.jenkins/tools/jenkins.plugins.nodejs.tools.NodeJSInstallation/node_js/bin/
ARCH=`uname -m`;
printf "\n\n${MAGENTA}Platform: $ARCH ${RESET}\n"
# Install nvm to easily set version of node to use
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
export NVM_DIR="$HOME/.nvm"
. $NVM_DIR/nvm.sh
nvm i 10
# Install docker-compose
curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-`uname -s`-`uname -m` -o ~/docker-compose
chmod +x ~/docker-compose
# Run eslint on portal code
cd src/pfe/portal
npm install
npm run eslint
if [ $? -ne 0 ]; then
exit 1
fi
cd ../../..
# Create codewind-workspace if it does not exist
printf "\n\nCreating codewind-workspace\n"
mkdir -m 777 -p codewind-workspace
export REPOSITORY='';
export TAG
export WORKSPACE_DIRECTORY=$PWD/codewind-workspace;
export WORKSPACE_VOLUME=cw-workspace;
export HOST_OS=$(uname);
export HOST_HOME=$HOME
export ARCH=$(uname -m);
# Select the right images for this architecture.
if [ "$ARCH" = "x86_64" ]; then
export PLATFORM="-amd64"
else
export PLATFORM="-$ARCH"
fi
# Start codewind running
~/docker-compose -f docker-compose.yaml -f docker-compose-remote.yaml up -d;
if [ $? -eq 0 ]; then
# Reset so we don't get conflicts
unset REPOSITORY;
unset WORKSPACE_DIRECTORY;
printf "\n\n${GREEN}SUCCESSFULLY STARTED CONTAINERS $RESET\n";
printf "\nCurrent running codewind containers\n";
docker ps --filter name=codewind
else
printf "\n\n${RED}FAILED TO START CONTAINERS $RESET\n";
exit;
fi
printf "\n\nPausing for 30 seconds to allow containers to start\n";
sleep 30;
# Check to see if any containers exited straight away
printf "\n\n${BLUE}CHECKING FOR codewind CONTAINERS THAT EXITED STRAIGHT AFTER BEING RUN $RESET\n";
EXITED_PROCESSES=$(docker ps -q --filter "name=codewind" --filter "status=exited" | wc -l)
if [ $EXITED_PROCESSES -gt 0 ]; then
printf "\n${RED}Exited containers found $RESET\n";
# docker ps --filter "name=codewind" --filter "status=exited";
NUM_CODE_ZERO=$(docker ps -q --filter "name=codewind" --filter "status=exited" --filter "exited=0" | wc -l);
NUM_CODE_ONE=$(docker ps -q --filter "name=codewind" --filter "status=exited" --filter "exited=1" | wc -l);
if [ $NUM_CODE_ZERO -gt 0 ]; then
printf "\n${RED}$NUM_CODE_ZERO found with an exit code '0' $RESET\n";
docker ps --filter "name=codewind" --filter "status=exited" --filter "exited=0";
printf "\nUse 'docker logs [container name]' to find why the exit happened";
fi
if [ $NUM_CODE_ONE -gt 0 ]; then
printf "\n${RED}$NUM_CODE_ONE found with an exit code '1' $RESET\n";
docker ps --filter "name=codewind" --filter "status=exited" --filter "exited=1";
printf "\nUse 'docker logs [container name]' to debug exit";
fi
else
printf "\nNo containers exited \n";
fi
printf "\n\ncodewind now available\n";
# Build the tests and run them against the portal.
cd test/
npm install
npm run eslint
npm run test
'''
}
}
}
}
stage('Publish Docker images') {
// This when clause disables PR build uploads; you may comment this out if you want your build uploaded.
when {
beforeAgent true
not {
changeRequest()
}
}
steps {
withDockerRegistry([url: 'https://index.docker.io/v1/', credentialsId: 'docker.com-bot']) {
sh '''#!/usr/bin/env bash
echo "Publishing docker images for Eclipse Codewind ..."
export REGISTRY="eclipse"
echo "Branch name is $GIT_BRANCH"
if [[ $GIT_BRANCH == "master" ]]; then
TAG="latest"
else
TAG=$GIT_BRANCH
fi
# Publish docker images with a filter for branch name
# Acceptable branch names: master, start with '<number>.<number>'
if [[ $GIT_BRANCH == "master" ]] || [[ $GIT_BRANCH =~ ^([0-9]+\\.[0-9]+) ]]; then
declare -a DOCKER_IMAGE_ARRAY=("codewind-performance-amd64"
"codewind-pfe-amd64"
"codewind-keycloak-amd64"
"codewind-gatekeeper-amd64")
chmod u+x ./script/publish.sh
for i in "${DOCKER_IMAGE_ARRAY[@]}"
do
echo "Publishing $REGISTRY/$i:$TAG"
./script/publish.sh $i $REGISTRY $TAG
done
if [[ $GIT_BRANCH =~ ^([0-9]+\\.[0-9]+) ]]; then
IFS='.' # set '.' as delimiter
read -ra TOKENS <<< "$GIT_BRANCH"
IFS=' ' # reset delimiter
export TAG_CUMULATIVE=${TOKENS[0]}.${TOKENS[1]}
for i in "${DOCKER_IMAGE_ARRAY[@]}"
do
echo "Publishing $REGISTRY/$i:$TAG_CUMULATIVE"
./script/publish.sh $i $REGISTRY $TAG_CUMULATIVE
done
fi
else
echo "Skip publishing docker images for $GIT_BRANCH branch"
fi
'''
}
}
}
}
post {
always {
sh '''#!/usr/bin/env bash
# Output portal logs
printf "\n********** codewind-pfe logs **********\n\n"
docker logs codewind-pfe
# Shutdown and cleanup.
printf "\nStopping and removing Codewind Docker containers.\n"
DOCKER_PS="docker ps -a -q --filter name=codewind";
DOCKER_IMAGES="docker images -q --filter reference=codewind*";
DOCKER_PS_APPS="docker ps -a -q --filter name=cw";
DOCKER_IMAGES_APPS="docker images -q --filter reference=cw*";
# Check to make sure that there are actually proceses to remove
NUMBER_OF_PROCESSES=$($DOCKER_PS | wc -l)
if [ $NUMBER_OF_PROCESSES -gt 0 ]; then
# Removing containers
printf "\nStopping all running containers\n";
docker rm -f $($DOCKER_PS)
if [ $? -eq 0 ]; then
printf "\nSuccessfully removed containers\n";
else
printf "\nError removing containers\n";
exit;
fi
printf "\nSUCCESSFULLY REMOVED CONTAINERS\n";
else
printf "\nERROR: THERE ARE NO CONTAINERS TO REMOVE\n";
fi
# Check to make sure that there are actually proceses to remove
NUMBER_OF_PROCESSES=$($DOCKER_PS_APPS | wc -l)
if [ $NUMBER_OF_PROCESSES -gt 0 ]; then
# Removing containers
docker rm -f $($DOCKER_PS_APPS)
if [ $? -eq 0 ]; then
printf "\n${GREEN}Successfully removed containers $RESET\n";
else
printf "\n${RED}Error removing containers $RESET\n";
exit;
fi
printf "\n${GREEN}SUCCESSFULLY REMOVED CONTAINERS $RESET\n";
else
printf "\n${RED}ERROR: THERE ARE NO CONTAINERS TO REMOVE $RESET\n";
fi
# Remove the codewind network
printf "\nRemoving docker network\n";
docker network rm codewind_network
if [ $? -eq 0 ]; then
printf "\n${GREEN}Successfully removed docker network $RESET\n";
else
printf "\n${RED}Error removing docker network $RESET\n";
fi
# Remove the default network
printf "\nRemoving docker network\n";
docker network rm codewind_default
if [ $? -eq 0 ]; then
printf "\n${GREEN}Successfully removed docker network $RESET\n";
else
printf "\n${RED}Error removing docker network $RESET\n";
fi
# Docker system prune
echo "Docker system prune ..."
docker system df
docker system prune -a --volumes -f
docker builder prune -a -f
docker system df
df -lh
'''
}
failure {
sh '''#!/usr/bin/env bash
printf "The PR failed";
'''
}
}
}