-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Reworked build and deploy using TravisCI
- Loading branch information
Showing
3 changed files
with
172 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 |