-
Notifications
You must be signed in to change notification settings - Fork 0
/
build
executable file
·110 lines (79 loc) · 2.08 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
#!/usr/bin/env bash
shopt -s globstar
root_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )"
image_pull() {
local pull_url file dir
pull_url="$1"
dir="$2"
file="${pull_url##*/}"
echo "Pulling $pull_url"
curl -fSsL "$pull_url" > "$dir/rootfs.tar.gz"
}
build() {
build_dir="${root_dir}/.build"
rm -rf ${build_dir}
mkdir ${build_dir}
declare manifest_files="${*:-versions/**/manifest}"
for manifest_file in $manifest_files; do
local version_dir
version_dir="${manifest_file%/*}"
declare image_files="${*:-$version_dir/image*}"
version="$(basename ${version_dir})"
for image_file in $image_files; do
extension="${image_file##*.}"
build_image_dir="${build_dir}/${version}/${extension}"
mkdir -p $build_image_dir
source "$manifest_file"
source "$image_file"
cp "$version_dir/Dockerfile" "$build_image_dir"
image_pull "$ALPINE_PULL_URL" "$build_image_dir"
docker build -t "$IMAGE_TAG" "$build_image_dir"
done
done
}
push(){
declare manifest_files="${*:-versions/**/manifest}"
for manifest_file in $manifest_files; do
local version_dir
version_dir="${manifest_file%/*}"
declare image_files="${*:-$version_dir/image*}"
declare -a tags
source "$manifest_file"
for image_file in $image_files; do
source "$image_file"
local tag
tag="${IMAGE_TAG}"
tags+=("$tag")
docker push $tag
done
for tag in "${MANIFEST_TAGS[@]}"; do
docker manifest create $tag ${tags[@]}
for image_file in $image_files; do
source "$image_file"
declare -a options
if [[ ! -z "${DOCKER_OS}" ]]; then
options+=("--os $DOCKER_OS")
fi
if [[ ! -z "${DOCKER_ARCH}" ]]; then
options+=("--arch $DOCKER_ARCH")
fi
if [[ ! -z "${DOCKER_VARIANT}" ]]; then
options+=("--variant $DOCKER_VARIANT")
fi
docker manifest annotate ${options[@]} $tag $IMAGE_TAG
unset options
done
docker manifest push $tag
done
unset tags
done
}
main() {
set -eo pipefail; [[ "$TRACE" ]] && set -x
declare cmd="$1"
case "$cmd" in
push) shift; push "$@";;
*) build "$@";;
esac
}
main "$@"