-
Notifications
You must be signed in to change notification settings - Fork 13
/
build.sh
executable file
·101 lines (82 loc) · 1.84 KB
/
build.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash -e
REQUIRED_VARS=(
ARGS
TRAVIS_BRANCH
DOCKERFILE
DOCKER_PROJECT
DOCKER_IMAGE_TAG
)
help(){
cat <<EOH
Usage: $0 [options]
Options:
-h|--help
Show this help
-v|--verbose
Enable verbose mode
Required environment variables:
$(for var in "${REQUIRED_VARS[@]}"; do echo -ne "$var\n "; done)
EOH
exit "${1:-0}"
}
retry() {
if ! "$@"; then
echo "******** Retrying $*"
"$@" || exit $?
fi
}
parse_options(){
local opts
opts=$(\
getopt \
--options 'hv' \
--longoptions 'help,verbose' \
--name "$0" \
-- "$@" \
) || help 1
local failed=false
local env_var
eval set -- "$opts"
while true; do
opt="$1"
shift;
case $opt in
-h|--help) help 0;;
-v|--verbose) set -x;;
--) break;;
esac
done
for env_var in "${REQUIRED_VARS[@]}"; do
[[ -v $env_var ]] || {
echo "Undefined var $env_var, please define befor running this" \
"script"
failed=true
}
done
if $failed; then
echo -e "Some required env vars were not defined, aborting\n"
help 1
fi
}
build_venv_rights_fixer() {
cd python_base
gcc -o fix_rights fix_rights.c
local res=$?
cd -
return "$res"
}
main(){
parse_options "$@"
# fail on unset variables expansion
set -o nounset
if [[ "$TRAVIS_BRANCH" == "master" ]]; then
TAG="$DOCKER_PROJECT:$DOCKER_IMAGE_TAG"
else
TAG="$DOCKER_PROJECT:dev.$TRAVIS_BRANCH-$DOCKER_IMAGE_TAG"
fi
echo "Building venv rights fixer binary"
build_venv_rights_fixer
echo "Building image $TAG"
retry docker build -f "$DOCKERFILE" $ARGS -t "$TAG" .
}
main "$@"