forked from epimorphics/ukhpi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ci-container-test
executable file
·59 lines (36 loc) · 1.34 KB
/
ci-container-test
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
#!/bin/bash
. ci-container-test.conf
echo JOB_NAME=$JOB_NAME
#trap "docker stop \"$JOB_NAME\" || true ; docker rm \"$JOB_NAME\" " EXIT
set -e
# clean up any old containers left
docker stop "$JOB_NAME" > /dev/null 2>&1 || true
docker rm "$JOB_NAME" > /dev/null 2>&1 || true
# start the container
docker run --name "$JOB_NAME" -d \
--volume `pwd`:/mnt \
"$IMAGE" \
>/dev/null 2>&1
echo container started
# copy the build directory
if [ ! ${BUILD_DIR:-no-build} == "no-build" ]
then
docker exec "$JOB_NAME" /bin/bash -c "cp -R /mnt/* ${BUILD_DIR} ; chown -R $USER:$USER \"$BUILD_DIR\""
fi
echo build directory copied
# copy the deploy key
if [ ! ${KEY_SOURCE:-no-key} == "no-key" ]
then
docker exec -i "$JOB_NAME" /bin/bash -c "cat > \"${KEY_DEST}\" ; chmod 0400 \"${KEY_DEST}\" ; chown $USER:$USER \"${KEY_DEST}\"" < "${KEY_SOURCE}"
fi
echo key installed
# trust the github.com key
docker exec -u $USER "$JOB_NAME" /bin/bash -c "cd "$BUILD_DIR" ; pwd ; ssh-keyscan github.com > .ssh/known_hosts ; cat .ssh/known_hosts"
echo github.com trusted
# run the build in the container
docker exec -u $USER "$JOB_NAME" /bin/bash -c "cd \"$BUILD_DIR\" ; ./ci-build"
echo build run
# clean up
docker stop "$JOB_NAME" || true > /dev/null 2>&1
docker rm "$JOB_NAME" || true > /dev/null 2>&1
echo "$JOB_NAME" done