-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathcico_setup.sh
executable file
·134 lines (115 loc) · 3.37 KB
/
cico_setup.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
#!/bin/bash -ex
load_jenkins_vars() {
if [ -e "jenkins-env.json" ]; then
eval "$(./env-toolkit load -f jenkins-env.json \
DEVSHIFT_TAG_LEN \
QUAY_USERNAME \
QUAY_PASSWORD \
JENKINS_URL \
GIT_BRANCH \
GIT_COMMIT \
BUILD_NUMBER \
ghprbSourceBranch \
ghprbActualCommit \
BUILD_URL \
ghprbPullId \
RECOMMENDER_API_TOKEN)"
fi
}
prep() {
yum -y update
yum -y install docker make git gcc-c++ bzip2 fontconfig
curl -sL https://rpm.nodesource.com/setup_6.x | sudo -E bash -
yum -y install nodejs
yum -y install java-1.8.0-openjdk
systemctl start docker
}
install_dependencies() {
# Build fabric8-analytics-stack-reports-ui
npm install;
chmod +x /root/payload/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs
if [ $? -eq 0 ]; then
echo 'CICO: npm install : OK'
else
echo 'CICO: npm install : FAIL'
exit 1
fi
}
run_unit_tests() {
# Exec unit tests
npm run test:unit
if [ $? -eq 0 ]; then
echo 'CICO: unit tests OK'
else
echo 'CICO: unit tests FAIL'
exit 2
fi
}
build_project() {
npm run build:prod
}
run_ui_integration_tests() {
# Build ui test docker image
echo 'recommender-token'
echo ${RECOMMENDER_API_TOKEN}
docker build --no-cache --rm -f Dockerfile.tests -t $(make get-test-image-name) .
if [ $? -eq 0 ]; then
echo 'CICO: test image build OK'
else
echo 'CICO: test image build FAIL'
exit 3
fi
# Run ui test docker image
docker run -e RECOMMENDER_API_TOKEN=${RECOMMENDER_API_TOKEN} $(make get-test-image-name)
# ./tests/run_functional_tests_docker.sh
if [ $? -eq 0 ]; then
echo 'CICO: UI integration tests OK'
else
echo 'CICO: UI integration tests FAIL'
exit 4
fi
}
build_image() {
local push_registry
push_registry=$(make get-push-registry)
# login before build to be able to pull RHEL parent image
if [ -n "${QUAY_USERNAME}" -a -n "${QUAY_PASSWORD}" ]; then
docker login -u ${QUAY_USERNAME} -p ${QUAY_PASSWORD} ${push_registry}
else
echo "Could not login, missing credentials for the registry"
exit 1
fi
make docker-build
}
run_image() {
make docker-run
}
tag_push() {
local target=$1
local source=$2
docker tag ${source} ${target}
docker push ${target}
}
push_image() {
local image_name
local image_repository
local short_commit
local push_registry
image_name=$(make get-image-name)
image_repository=$(make get-image-repository)
short_commit=$(git rev-parse --short=$DEVSHIFT_TAG_LEN HEAD)
push_registry=$(make get-push-registry)
if [ -n "${ghprbPullId}" ]; then
# PR build
pr_id="SNAPSHOT-PR-${ghprbPullId}"
tag_push ${push_registry}/${image_repository}:${pr_id} ${image_name}
tag_push ${push_registry}/${image_repository}:${pr_id}-${short_commit} ${image_name}
else
# master branch build
tag_push ${push_registry}/${image_repository}:latest ${image_name}
tag_push ${push_registry}/${image_repository}:${short_commit} ${image_name}
fi
echo 'CICO: Image pushed, ready to update deployed app'
}
load_jenkins_vars
prep