-
Notifications
You must be signed in to change notification settings - Fork 689
/
test-stirunimage.sh
executable file
·163 lines (131 loc) · 4.75 KB
/
test-stirunimage.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
#!/bin/bash
set -o errexit
set -o nounset
set -o pipefail
S2I_ROOT=$(dirname "${BASH_SOURCE}")/..
export KILLDONE=""
function time_now()
{
echo $(date +%s000)
}
mkdir -p /tmp/sti
WORK_DIR=$(mktemp -d /tmp/sti/test-work.XXXX)
NEEDKILL="yes"
S2I_PID=""
function cleanup()
{
set +e
#some failures will exit the shell script before check_result() can dump the logs (ssh seems to be such a case)
if [ -a "${WORK_DIR}/ran-clean" ]; then
echo "Cleaning up working dir ${WORK_DIR}"
else
echo "Dumping logs since did not run successfully before cleanup of ${WORK_DIR} ..."
cat /tmp/test-work*/*
fi
rm -rf ${WORK_DIR}
# use sigint so that s2i post processing will remove docker container
if [ -n "${NEEDKILL}" ]; then
if [ -n "${S2I_PID}" ]; then
kill -2 "${S2I_PID}"
fi
fi
echo
echo "Complete"
}
function check_result() {
local result=$1
if [ $result -eq 0 ]; then
echo
echo "TEST PASSED"
echo
if [ -n "${2}" ]; then
rm $2
fi
else
echo
echo "TEST FAILED ${result}"
echo
cat $2
cleanup
exit $result
fi
}
function test_debug() {
echo
echo $1
echo
}
trap cleanup EXIT SIGINT
echo "working dir: ${WORK_DIR}"
pushd ${WORK_DIR}
test_debug "cloning source into working dir"
git clone git://github.com/openshift/cakephp-ex &> "${WORK_DIR}/s2i-git-clone.log"
check_result $? "${WORK_DIR}/s2i-git-clone.log"
test_debug "s2i build with relative path without file://"
s2i build cakephp-ex openshift/php-55-centos7 test &> "${WORK_DIR}/s2i-rel-noproto.log"
check_result $? "${WORK_DIR}/s2i-rel-noproto.log"
test_debug "s2i build with relative path with file://"
s2i build file://./cakephp-ex openshift/php-55-centos7 test &> "${WORK_DIR}/s2i-rel-proto.log"
check_result $? "${WORK_DIR}/s2i-rel-proto.log"
popd
test_debug "s2i build with absolute path with file://"
s2i build "file://${WORK_DIR}/cakephp-ex" openshift/php-55-centos7 test &> "${WORK_DIR}/s2i-abs-proto.log"
check_result $? "${WORK_DIR}/s2i-abs-proto.log"
test_debug "s2i build with absolute path without file://"
s2i build "${WORK_DIR}/cakephp-ex" openshift/php-55-centos7 test &> "${WORK_DIR}/s2i-abs-noproto.log"
check_result $? "${WORK_DIR}/s2i-abs-noproto.log"
## don't do ssh tests here because credentials are needed (even for the git user), which
## don't exist in the vagrant/jenkins setup
test_debug "s2i build with non-git repo file location"
rm -rf "${WORK_DIR}/cakephp-ex/.git"
s2i build "${WORK_DIR}/cakephp-ex" openshift/php-55-centos7 test --loglevel=5 &> "${WORK_DIR}/s2i-non-repo.log"
check_result $? ""
grep "Copying sources" "${WORK_DIR}/s2i-non-repo.log"
check_result $? "${WORK_DIR}/s2i-non-repo.log"
test_debug "s2i rebuild"
s2i build https://github.com/openshift/sti-php.git --context-dir=5.5/test/test-app registry.access.redhat.com/openshift3/php-55-rhel7 rack-test-app --incremental=true --loglevel=5 &> "${WORK_DIR}/s2i-pre-rebuild.log"
check_result $? "${WORK_DIR}/s2i-pre-rebuild.log"
s2i rebuild rack-test-app:latest rack-test-app:v1 --force-pull=false -p never --loglevel=5 &> "${WORK_DIR}/s2i-rebuild.log"
check_result $? "${WORK_DIR}/s2i-rebuild.log"
test_debug "s2i usage"
s2i usage openshift/ruby-20-centos7 &> "${WORK_DIR}/s2i-usage.log"
check_result $? ""
grep "Sample invocation" "${WORK_DIR}/s2i-usage.log"
check_result $? "${WORK_DIR}/s2i-usage.log"
test_debug "s2i build with git proto"
s2i build git://github.com/openshift/cakephp-ex openshift/php-55-centos7 test --run=true &> "${WORK_DIR}/s2i-git-proto.log" &
check_result $? "${WORK_DIR}/s2i-git-proto.log"
test_debug "s2i build with --run==true option"
s2i build git://github.com/bparees/openshift-jee-sample openshift/wildfly-90-centos7 test-jee-app --run=true &> "${WORK_DIR}/s2i-run.log" &
S2I_PID=$!
TIME_SEC=1000
TIME_MIN=$((60 * $TIME_SEC))
max_wait=15*TIME_MIN
echo "Waiting up to ${max_wait} for the build to finish ..."
expire=$(($(time_now) + $max_wait))
set +e
while [[ $(time_now) -lt $expire ]]; do
grep "as a result of the --run=true option" "${WORK_DIR}/s2i-run.log"
if [ $? -eq 0 ]; then
echo "[INFO] Success running command s2i --run=true"
# use sigint so that s2i post processing will remove docker container
kill -2 "${S2I_PID}"
NEEDKILL=""
sleep 30
docker ps -a | grep test-jee-app
if [ $? -eq 1 ]; then
echo "[INFO] Success terminating associated docker container"
touch "${WORK_DIR}/ran-clean"
exit 0
else
echo "[INFO] Associated docker container still found, review docker ps -a output above, and here is the dump of ${WORK_DIR}/s2i-run.log"
cat "${WORK_DIR}/s2i-run.log"
exit 1
fi
fi
sleep 1
done
echo "[INFO] Problem with s2i --run=true, dumping ${WORK_DIR}/s2i-run.log"
cat "${WORK_DIR}/s2i-run.log"
set -e
exit 1