forked from martonsereg/docker-cb-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·54 lines (41 loc) · 1.34 KB
/
deploy.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
#!/bin/bash
set -eo pipefail
if [[ "$TRACE" ]]; then
: ${START_TIME:=$(date +%s)}
export START_TIME
export PS4='+ [TRACE $BASH_SOURCE:$LINENO][ellapsed: $(( $(date +%s) - $START_TIME ))] '
set -x
fi
debug() {
[[ "$DEBUG" ]] && echo "-----> $*" 1>&2 || :
}
install_deps() {
if ! dockerhub-tag --version &>/dev/null ;then
debug "installing dockerhub-tag binary to /usr/local/bin"
curl -L https://github.com/progrium/dockerhub-tag/releases/download/v0.2.0/dockerhub-tag_0.2.0_$(uname)_x86_64.tgz | tar -xz -C /usr/local/bin/
else
debug "dockerhub-tag already installed"
fi
}
get_latest_maven_version() {
curl -sL ${MAVEN_METADATA_URL} | sed -n '/<version>/ h; $ {x;s/ *<.\?version>//gp;}'
}
new_version() {
install_deps
declare NEW_VERSION=${1:-$(get_latest_maven_version)}
debug "building docker image for version: $NEW_VERSION"
sed -i "/^ENV VERSION/ s/VERSION .*/VERSION ${NEW_VERSION}/" Dockerfile
git commit -m "Release ${NEW_VERSION}" Dockerfile
git tag ${NEW_VERSION}
git push origin master --tags
dockerhub-tag set ${DOCKER_IMAGE} $NEW_VERSION $NEW_VERSION /
}
main() {
: ${MAVEN_METADATA_URL:?"required!"}
: ${DOCKER_IMAGE:?"required!"}
: ${DOCKERHUB_USERNAME:?"required!"}
: ${DOCKERHUB_PASSWORD:?"required!"}
: ${DEBUG:=1}
new_version "$@"
}
[[ "$0" == "$BASH_SOURCE" ]] && main "$@"