-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
build.bash
executable file
·76 lines (64 loc) · 1.9 KB
/
build.bash
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
#!/usr/bin/env bash
declare BUILD_IMAGE="${BUILD_IMAGE:-sphinxsearch-builder}"
declare BUILD_PREFIX="${BUILD_PREFIX:-sphinxsearch-build-}"
declare OPTIONS="${OPTIONS:-versions/**/options}"
build() {
declare build_files="${*:-$OPTIONS}"
: "${build_files:?}"
docker build -t "$BUILD_IMAGE" builder
for file in ${build_files}; do
( source "${file}"
local release="${RELEASE}"
local build="${BUILD_PREFIX}${release}"
local build_options="${BUILD_OPTIONS}"
local version_dir="$(dirname "${file}")"
local tags="${TAGS}"
: "${build:?}" "${tags:?}" "${build_options:?}" "${release:?}"
docker rm "$build" 2>/dev/null || true
docker run --rm "$BUILD_IMAGE" ${build_options} > "./${version_dir}/sphinxsearch.tar.gz" || true
for tag in ${tags}; do
docker build -t "${tag}" "${version_dir}"
if [[ "${CIRCLE_BUILD_NUM}" ]]; then
mkdir -p images \
&& docker tag -f "$tag" "${tag}-${CIRCLE_BUILD_NUM}" \
&& docker save "${tag}-${CIRCLE_BUILD_NUM}" | gzip -c > "images/${tag//\//_}-${CIRCLE_BUILD_NUM}.tar.gz" \
&& docker rmi "${tag}-${CIRCLE_BUILD_NUM}" || true
fi
done )
done
}
testall() {
declare build_files="${*:-$OPTIONS}"
declare -a test_files
for file in ${build_files}; do
source "${file}"
local tag
tag="$(echo "${TAGS}" | cut -d' ' -f1)"
tag="${tag//:/-}"
tag="${tag//\//_}"
test_files+=("test/test_${tag}.bats")
done
bats "${test_files[@]}"
}
push() {
declare build_files="${*:-$OPTIONS}"
for file in ${build_files}; do
( source "${file}"
for tag in ${TAGS}; do
if docker history ${tag} &> /dev/null; then
[[ ${PUSH_IMAGE} ]] && docker push ${tag}
fi
done
exit 0 )
done
}
main() {
set -eo pipefail; [[ "$TRACE" ]] && set -x
declare cmd="$1"
case "$cmd" in
test) shift; testall "$@";;
push) shift; push "$@";;
*) build "$@";;
esac
}
main "$@"