forked from gliderlabs/docker-alpine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild
executable file
·115 lines (98 loc) · 2.83 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
115
#!/usr/bin/env bash
declare BUILD_IMAGE="${BUILD_IMAGE:-alpine-builder}"
declare BUILD_PREFIX="${BUILD_PREFIX:-alpine-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 --name "${build}" "$BUILD_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
docker rm "$build" 2>/dev/null || true )
done
}
commit() {
declare rootfs_files="${*:-versions/**/rootfs.tar.gz}"
local build_num="${CIRCLE_BUILD_NUM:-nobuild}"
for file in $rootfs_files; do
local release="$(basename "$(dirname "$file")")"
local version_dir="$(dirname "$file")"
local current_branch=$(git rev-parse --abbrev-ref HEAD)
: "${release:?}"
git checkout -B "rootfs-$release"
git add -f -- "$file"
git commit -m "pushing release $release for build $build_num"
git push -f origin "rootfs-$release"
git checkout "$current_branch"
done
}
run_tests() {
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
}
library() {
local refs="$(git ls-remote --heads origin)"
echo "# maintainer: Glider Labs <[email protected]> (@gliderlabs)"
for file in versions/library-*/options; do
source "$file"
local version="${RELEASE#v}"
echo
for tag in $TAGS; do
local tag="$(echo "$tag" | cut -d: -f2)"
read sha _ <<< $(echo "$refs" | grep rootfs-library-$version)
echo "$tag:" "git://github.com/gliderlabs/docker-alpine@$sha" "versions/library-$version"
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 "$@"