-
Notifications
You must be signed in to change notification settings - Fork 1
/
build-release.sh
executable file
·71 lines (58 loc) · 1.65 KB
/
build-release.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
#!/bin/bash
function usage {
echo -e "\nUSAGE: ./build-release.sh [release DOCKER_REPO DOCKER_USER DOCKER_PASSWORD]"
echo -e "\n release Specifying \"release\" instructs the script to build the Docker image and push it to a remote repository"
echo -e " DOCKER_REPO The name of the repository in Docker hub or address of private repository server"
echo -e " DOCKER_USER User name to login as to the remote repository"
echo -e " DOCKER_PASSWORD The users password\n"
exit 1
}
case $1 in
help)
usage
;;
release)
[[ $# -eq 4 ]] || usage
;;
*)
[[ $# -eq 0 ]] || usage
;;
esac
TAG="$(git tag -l --points-at HEAD)"
if [[ "$1" == "release" ]] && [[ -z "$TAG" ]] ; then
echo "To build and push the release image their must be a version tag at the head of the branch."
exit 1
fi
ROOT_DIR=$(cd $(dirname $0) && pwd)
pushd $ROOT_DIR
set -x
set -e
go get -u github.com/kardianos/govendor
govendor sync
govendor test +local
pushd $ROOT_DIR/cmd/check
GOOS=linux GOARCH=amd64 go build
popd
pushd $ROOT_DIR/cmd/in
GOOS=linux GOARCH=amd64 go build
popd
pushd $ROOT_DIR/cmd/out
GOOS=linux GOARCH=amd64 go build
popd
TAG="$(git tag -l --points-at HEAD)"
if [[ "$1" == "release" ]]; then
docker build . -t cf-event-release --squash
if [[ -n $3 ]] && [[ -n $4 ]]; then
docker login -u $3 -p $4
docker tag cf-event-release $2/cf-event:latest
docker tag cf-event-release $2/cf-event:$TAG
docker push $2/cf-event
# clean up
docker rmi $2/cf-event:latest
docker rmi $2/cf-event:$TAG
docker rmi cf-event-release
fi
fi
set +e
set +x
popd