-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathorchestrator
executable file
·126 lines (104 loc) · 2.91 KB
/
orchestrator
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/usr/bin/env bash
# vim: ft=sh
declare help="
Orchestrator Script for Alpine's docker images.
Usage:
orchestrator test
orchestrator push
orchestrator build
orchestrator [path/to/options] [path/to/other/options]
orchestrator --version
orchestrator -h | --help
Options:
-h --help Show this screen.
--version Show versions.
Example of build:
orchestrator build versions/myprefix-*/options
Examples of tests:
orchestrator test version/myprefix-*/options
How should the tests be named:
Use the tag of the resulting docker image, so if the tag is foo/bar:1.0 the
test file should be called test_foo_bar-1.0.bats inside the tests directory.
By default it will build all the available files on the versions/arch
directory.
"
declare version="
Version: 1.0.0.
Licensed under the BSD terms.
"
declare ARCH
ARCH="$(uname -m)"
declare BUILDER_DIR="${BUILDER_DIR:-builder/$ARCH}"
declare BUILD_IMAGE="${BUILD_IMAGE:-alpine-builder-$ARCH}"
declare BUILD_PREFIX="${BUILD_PREFIX:-alpine-build-$ARCH-}"
declare OPTIONS="${OPTIONS:-versions/$ARCH/**/options}"
build() {
echo "Building for architecture: $ARCH"
declare build_files="${*:-$OPTIONS}"
echo "Will build versions files: $build_files"
echo "Building the builder image:"
echo "$BUILDER_DIR"
docker build -t "$BUILD_IMAGE" "$BUILDER_DIR"
echo "Now, gonna build the resulting images:"
for file in $build_files; do
echo "Building from file: $file..."
( # shellcheck source=versions/x86_64/resnullius-edge/options
source "$file"
local version_dir
version_dir="$(dirname "$file")"
: "${TAGS:?}" "${BUILD_OPTIONS:?}" "${RELEASE:?}"
echo "The build options to use are" "${BUILD_OPTIONS[@]}"
docker run --rm -e "TRACE=$TRACE" "$BUILD_IMAGE" "${BUILD_OPTIONS[@]}" \
> "./$version_dir/rootfs.tar.gz"
for tag in "${TAGS[@]}"; do
docker build -t "$tag" "$version_dir"
done )
done
}
run_tests() {
declare build_files="${*:-$OPTIONS}"
declare -a test_files
for file in $build_files; do
# shellcheck source=versions/x86_64/resnullius-edge/options
source "$file"
local tag
tag="${TAGS[0]}"
tag="${tag//:/-}"
tag="${tag//\//_}"
test_files+=("tests/test_${tag}.bats")
done
bats "${test_files[@]}"
}
push() {
[[ "$NO_PUSH" ]] && return 0
declare build_files="${*:-$OPTIONS}"
for file in $build_files; do
( # shellcheck source=versions/x86_64/resnullius-edge/options
source "$file"
for tag in ${TAGS[@]}; do
if docker history "$tag" &> /dev/null; then
[[ "$PUSH_IMAGE" ]] && docker push "$tag"
fi
done
exit 0 )
done
}
version() {
echo "$version"
}
help() {
echo "$help"
}
main() {
set -eo pipefail; [[ "$TRACE" ]] && set -x
declare cmd="$1"
case "$cmd" in
test) shift; run_tests "$@";;
push) shift; push "$@";;
build) shift; build "$@";;
-h|--help) shift; help "$@";;
--version) shift; version;;
*) help "$@";;
esac
}
main "$@"