-
Notifications
You must be signed in to change notification settings - Fork 10
/
travis.sh
85 lines (72 loc) · 2.51 KB
/
travis.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
#------------------------------------------------------------------------------
# FUNCTIONS -------------------------------------------------------------------
#------------------------------------------------------------------------------
# compose Docker image tag ----------------------------------------------------
getTag() {
temp=""
# find tag prefix: master -> "", devel -> "devel"
if [[ "$TRAVIS_BRANCH" == "devel" ]]; then
temp="devel-"
fi
os=""
# determine os debian -> "", alpine -> "alpine"
if [[ "$dockerfile" == "alpine" ]]; then
temp="${temp}alpine-"
fi
# append tag
temp="${temp}${1}"
echo "$temp"
}
# compose full image name (repo + image name + tag) ---------------------------
getImageName() {
echo "${repo_name}/${image_name}:$(getTag ${1})"
}
# build Docker image ----------------------------------------------------------
build() {
# build image
docker build --build-arg baseimage_tag=${baseimage_tag} \
--build-arg webmapclient_version=${webmapclient_version} \
-t "temp:temp" \
${dockerfile}
}
# run Docker container --------------------------------------------------------
runContainer() {
docker run --name webcl -d -p 8000:8000 "temp:temp"
}
# deploy ----------------------------------------------------------------------
deploy() {
# deploy if not a pull request and branch is master or devel
if [[ "$TRAVIS_PULL_REQUEST" == "false" && \
( "$TRAVIS_BRANCH" == "master" || "$TRAVIS_BRANCH" == "devel" ) ]]; then
# login to docker hub
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
# create tags and push to docker hub
for str in ${tag//,/ } ; do
docker tag "temp:temp" "$(getImageName ${str})"
docker push "$(getImageName ${str})"
done
fi
}
# cleanup ---------------------------------------------------------------------
cleanup() {
docker rm -fv webcl
docker rmi -f "temp:temp"
# create tags and remove images
for str in ${tag//,/ } ; do
docker rmi -f "$(getImageName ${str})"
done
}
#------------------------------------------------------------------------------
# MAIN SCRIPT -----------------------------------------------------------------
#------------------------------------------------------------------------------
# Check if the function exists (bash specific)
if declare -f "$1" > /dev/null
then
# call arguments verbatim
"$@"
else
# Show a helpful error
echo "'$1' is not a known function name" >&2
exit 1
fi