-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path.travis-ci.sh
executable file
·85 lines (68 loc) · 2.31 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
#!/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/ocaml-jupyter-datascience:$TAG dockerfiles/$TAG
docker history akabe/ocaml-jupyter-datascience:$TAG
}
function test_image() {
yellow_echo "[Test] $TAG"
./tests/run_test_on_docker.sh akabe/ocaml-jupyter-datascience:$TAG
}
function deploy_image() {
yellow_echo "[Deploy] Deploy image tag $TAG"
docker login -u $DOCKER_USER -p $DOCKER_PWD
docker push akabe/ocaml-jupyter-datascience:$TAG
for t in $ALIAS; do
yellow_echo "[Deploy] Deploy image tag $TAG as $t"
docker tag akabe/ocaml-jupyter-datascience:$TAG akabe/ocaml-jupyter-datascience:$t
docker push akabe/ocaml-jupyter-datascience:$t
done
}
check_unpushed_changes
git_diff_pullreq > pullreq.diff
cat pullreq.diff
if [[ "$TRAVIS_PULL_REQUEST" == false ]] && [[ "$TRAVIS_BRANCH" == master ]]; then
build_image
test_image
deploy_image # Build and deploy images on the master branch.
elif grep "^+++ b/dockerfiles/$TAG/Dockerfile" pullreq.diff >/dev/null; then
build_image
test_image
else
green_echo "[ OK ] $TAG: Dockerfile is not changed."
fi