-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
travis-ci.sh
executable file
·90 lines (72 loc) · 2.23 KB
/
travis-ci.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
#!/bin/bash -ue
function red_echo() {
echo -e "\033[31m$@\033[0m"
}
function green_echo() {
echo -e "\033[32m$@\033[0m"
}
function yellow_echo() {
echo -e "\033[33m$@\033[0m"
}
function check_unpushed_changes() {
source ./generate.sh # Update Dockerfile
if git diff --name-only HEAD | grep "^dockerfiles/$TAG" >/dev/null; then
red_echo "[ERROR] Changes for tag $TAG are not uncommited or unpushed."
red_echo " ./generate_all.sh and push the changes"
git diff HEAD
exit 127
fi
}
## Print the difference of this pull request into STDOUT.
function git_diff_pullreq() {
yellow_echo "Pull request: $TRAVIS_PULL_REQUEST" >&2
if [[ "$TRAVIS_PULL_REQUEST" != false ]]; then
curl -sL https://github.com/$TRAVIS_REPO_SLUG/pull/$TRAVIS_PULL_REQUEST.diff
else
local merge
merge=$(git show | grep '^Merge: ' | awk '{print $2 ".." $3}')
if [[ "$merge" == '' ]]; then
yellow_echo "The latest commit is not a merge." >&2
git show
else
yellow_echo "The latest commit is a merge: $merge" >&2
git diff $merge
fi
fi
}
function build_image() {
yellow_echo "[Build] $TAG: Dockerfile is changed."
docker build -t akabe/iocaml-datascience:$TAG dockerfiles/$TAG
docker history akabe/iocaml-datascience:$TAG
}
function test_image() {
yellow_echo "[Test] $TAG"
./tests/run_test.sh akabe/iocaml-datascience:$TAG
}
function deploy_image() {
if [[ "$TRAVIS_PULL_REQUEST" == false ]] && [[ "$TRAVIS_BRANCH" == master ]]; then
yellow_echo "[Deploy] Deploy image tag $TAG"
docker login -u $DOCKER_USER -p $DOCKER_PWD
docker push akabe/iocaml-datascience:$TAG
for t in $ALIAS; do
yellow_echo "[Deploy] Deploy image tag $TAG as $t"
docker tag akabe/iocaml-datascience:$TAG akabe/iocaml-datascience:$t
docker push akabe/iocaml-datascience:$t
done
else
yellow_echo "[Deploy] Skip pushing image tag $TAG..."
for t in $ALIAS; do
yellow_echo "[Deploy] Skip pushing image tag $t"
done
fi
}
check_unpushed_changes
git_diff_pullreq > pullreq.diff
cat pullreq.diff
if grep "^+++ b/dockerfiles/$TAG/Dockerfile" pullreq.diff >/dev/null; then
build_image
test_image
deploy_image
else
green_echo "[ OK ] $TAG: Dockerfile is not changed."
fi