forked from cloudflare/docker-phan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·64 lines (56 loc) · 1.34 KB
/
build
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
#!/usr/bin/env bash
build() {
declare build_files="${*:-versions/**/options}"
[[ "$BUILDER_IMAGE" ]] || {
BUILDER_IMAGE="phan-builder"
docker build -t "$BUILDER_IMAGE" builder
}
for file in $build_files; do
(
source "$file"
local version_dir
version_dir="$(dirname "$file")"
: "${TAGS:?}" "${BUILD_OPTIONS:?}" "${RELEASE:?}"
docker run -e "TRACE=$TRACE" --rm "$BUILDER_IMAGE" "${BUILD_OPTIONS[@]}" \
> "$version_dir/rootfs.tar.gz"
for tag in "${TAGS[@]}"; do
docker build -t "$tag" "$version_dir"
done
)
done
}
push() {
declare build_files="${*:-versions/**/options}"
for file in $build_files; do
(
source "$file"
for tag in "${TAGS[@]}"; do
if docker history "$tag" &> /dev/null; then
docker push "$tag"
fi
done
exit 0
)
done
}
run_tests() {
declare build_files="${*:-versions/**/options}"
declare -a test_files
for file in $build_files; do
source "$file"
local tag
tag="${TAGS[0]}" tag="${tag//:/-}" tag="${tag//\//_}"
test_files+=("test/test_${tag}.bats")
done
bats "${test_files[@]}"
}
main() {
set -eo pipefail; [[ "$TRACE" ]] && set -x
declare cmd="$1"
case "$cmd" in
test) shift; run_tests "$@";;
push) shift; push "$@";;
*) build "$@";;
esac
}
main "$@"