forked from gliderlabs/docker-alpine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·114 lines (101 loc) · 2.9 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
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
#!/usr/bin/env bash
build() {
declare build_files="${*:-versions/**/options}"
[[ "$BUILDER_IMAGE" ]] || {
BUILDER_IMAGE="alpine-builder"
docker build -t "$BUILDER_IMAGE" builder
}
for file in $build_files; do
( # shellcheck source=versions/gliderlabs-3.2/options
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"
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
}
commit() {
[[ "$CIRCLE_BRANCH" == "release" ]] || return 0
declare rootfs_files="versions/**/rootfs.tar.gz"
local build_num="${CIRCLE_BUILD_NUM:-nobuild}"
local current_branch
current_branch=$(git rev-parse --abbrev-ref HEAD)
: "${current_branch:?}"
for file in $rootfs_files; do
local release version_dir
release="$(basename "$(dirname "$file")")"
version_dir="$(dirname "$file")"
: "${release:?}" "${version_dir:?}"
git checkout -B "rootfs/$release" "$current_branch"
git add -f -- "$file"
git commit -m "release image version $release for build $build_num"
done
[[ "$NO_PUSH" ]] || git push -f origin 'refs/heads/rootfs/*'
git checkout "$current_branch"
}
run_tests() {
declare build_files="${*:-versions/**/options}"
declare -a test_files
for file in $build_files; do
# shellcheck source=versions/gliderlabs-3.2/options
source "$file"
local tag
tag="${TAGS[0]}" tag="${tag//:/-}" tag="${tag//\//_}"
test_files+=("test/test_${tag}.bats")
done
bats "${test_files[@]}"
}
push() {
[[ "$CIRCLE_BRANCH" == "release" ]] || return 0
[[ "$NO_PUSH" ]] && return 0
declare build_files="${*:-versions/**/options}"
for file in $build_files; do
( #shellcheck source=versions/gliderlabs-3.2/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
}
library() {
for file in versions/library-*/options; do
# shellcheck source=versions/library-3.2/options
source "$file"
local refs
refs="$(git ls-remote --exit-code --heads origin rootfs/library-${RELEASE#v})"
: "${refs:?}"
for tag in "${TAGS[@]}"; do
echo "${tag#*:}:" \
"git://github.com/gliderlabs/docker-alpine@${refs:0:40}" \
"versions/library-${RELEASE#v}"
done
done
}
main() {
set -eo pipefail; [[ "$TRACE" ]] && set -x
declare cmd="$1"
case "$cmd" in
test) shift; run_tests "$@";;
commit) shift; commit "$@";;
push) shift; push "$@";;
library) shift; library;;
*) build "$@";;
esac
}
main "$@"