generated from kubernetes/kubernetes-template-project
-
Notifications
You must be signed in to change notification settings - Fork 960
/
build-image.sh
195 lines (172 loc) · 5.37 KB
/
build-image.sh
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#!/bin/bash
# This script is used to automatically generate tarball,
# build and upload docker images to AliYun
# on given branch,tag or commit.
set -e -u -o pipefail
# Following arguments are initialized with the default value.
#alluxio_git='https://github.com/Alluxio/alluxio.git'
alluxio_git='https://github.com/Alluxio/alluxio.git'
branch="release-2.8.0"
tag=""
commit=""
alluxio_image_name="fluidcloudnative/alluxio"
alluxio_fuse_image_name="fluidcloudnative/alluxio-fuse"
dev_container_name="alluxio-dev-test"
print_usage()
{
echo -e "Usage:"
echo -e "\t./build-image.sh [options]"
echo -e "OPTIONS:"
echo -e "\t-h"
echo -e "\t\tDisplay this help message."
echo -e "\t-b, --branch branch"
echo -e "\t\tSet the git branch."
echo -e "\t-t, --tag tag"
echo -e "\t\tSet the git tag."
echo -e "\t-c, --commit commmit_id"
echo -e "\t\tSet the commit id."
echo -e "\t-a, --alluxio_image_name alluxio_image_name"
echo -e "\t\tSet the alluxio image name."
echo -e "\t-f, --alluxio_fuse_image_name alluxio_fuse_image_name"
echo -e "\t\tSet the alluxio fuse image name."
}
clean()
{
docker rm -f ${dev_container_name} || true
# rm -rf /alluxio || true
}
clone()
{
if [ -d "/alluxio" ]; then
echo "alluxio repository already exists."
else
echo "cloning from ${alluxio_git}."
git clone "${alluxio_git}" /alluxio
fi
}
checkout()
{
local owd=$(pwd)
# Make sure that local repository is up tp date
cd "/alluxio" && git fetch
# 1. checkout commit
if [[ -n ${commit} ]]; then
echo "checkout to commit ${commit}."
git checkout ${commit}
elif [[ -n ${tag} ]]; then
# 2. checkout tag
echo "checkout to tag ${tag}."
git checkout ${tag}
# 3. checkout branch
else
echo "checkout to branch ${branch}."
git checkout "remotes/origin/${branch}"
fi
echo "GIT_COMMIT=$(git rev-parse --short HEAD)"
cd "${owd}"
}
start_container()
{
docker pull "maven:3.6.2-jdk-8"
local dev_container_id=$(docker ps | grep ${dev_container_name} | awk '{print $1}')
if [ -z ${dev_container_id} ]; then
echo "start maven container."
docker run -itd -v /alluxio:/alluxio --name "${dev_container_name}" "maven:3.6.2-jdk-8" bash
dev_container_id=$(docker ps | grep ${dev_container_name} | awk '{print $1}')
fi
if [ -z ${dev_container_id} ]; then
echo "ERROR: can not start container." >&2
exit 1
fi
}
tarball()
{
docker cp tarball.sh ${dev_container_name}:/tarball.sh
docker exec -it ${dev_container_name} /bin/bash -c "sh /tarball.sh"
}
build()
{
docker cp ${dev_container_name}:/tmp/alluxio-release-2.8.1-SNAPSHOT-bin.tar.gz /tmp/
cp /tmp/alluxio-release-2.8.1-SNAPSHOT-bin.tar.gz /alluxio/integration/docker
cd /alluxio/integration/docker
GIT_COMMIT=$(git rev-parse --short HEAD)
echo "GIT_COMMIT=${GIT_COMMIT}"
# Use aluxio/alluxio-dev image for both Alluxio and Fuse, starting from Alluxio v2.6.2
# Build Alluxio image
if test -f /alluxio/integration/docker/Dockerfile-dev; then
docker build -f Dockerfile-dev -t alluxio/alluxio-dev:release-2.8.1-SNAPSHOT-$GIT_COMMIT --build-arg ALLUXIO_TARBALL=alluxio-release-2.8.1-SNAPSHOT-bin.tar.gz --build-arg ENABLE_DYNAMIC_USER="true" .
else
docker build -t alluxio/alluxio-dev:release-2.8.1-SNAPSHOT-$GIT_COMMIT --build-arg ALLUXIO_TARBALL=alluxio-release-2.8.1-SNAPSHOT-bin.tar.gz --build-arg ENABLE_DYNAMIC_USER="true" .
fi
# Tag Alluxio image
docker tag alluxio/alluxio-dev:release-2.8.1-SNAPSHOT-$GIT_COMMIT ${alluxio_image_name}:release-2.8.1-SNAPSHOT-$GIT_COMMIT
# Build Fuse image if needed. Tag Fuse image
if test -f /alluxio/integration/docker/Dockerfile.fuse; then
docker build -f Dockerfile.fuse -t alluxio/alluxio-fuse:release-2.8.1-SNAPSHOT-$GIT_COMMIT --build-arg ALLUXIO_TARBALL=alluxio-release-2.8.1-SNAPSHOT-bin.tar.gz --build-arg ENABLE_DYNAMIC_USER="true" .
docker tag alluxio/alluxio-fuse:release-2.8.1-SNAPSHOT-$GIT_COMMIT ${alluxio_fuse_image_name}:release-2.8.1-SNAPSHOT-$GIT_COMMIT
else
docker tag alluxio/alluxio-dev:release-2.8.1-SNAPSHOT-$GIT_COMMIT ${alluxio_fuse_image_name}:release-2.8.1-SNAPSHOT-$GIT_COMMIT
fi
docker push ${alluxio_fuse_image_name}:release-2.8.1-SNAPSHOT-$GIT_COMMIT &
docker push ${alluxio_image_name}:release-2.8.1-SNAPSHOT-$GIT_COMMIT &
}
main()
{
# Parse arguments using getopt
ARGS=$(getopt -a -o b:c:t:a:f:h --long branch:,commit:,tag:,alluxio_image_name:,alluxio_fuse_image_name:,help -- "$@")
if [ $? != 0 ]; then
exit 1
fi
eval set -- "${ARGS}"
while true
do
case "$1" in
-h|--help)
print_usage
shift 1
exit 0
;;
-b|--branch)
branch=$2
echo "branch=$2"
shift 2
;;
-c|--commit)
commit=$2
echo "commit=$2"
shift 2
;;
-t|--tag)
tag=$2
echo "tag=$2"
shift 2
;;
-a|--alluxio_image_name)
alluxio_image_name=$2
echo "alluxio_image_name=$2"
shift 2
;;
-f|--alluxio_fuse_image_name)
alluxio_fuse_image_name=$2
echo "alluxio_fuse_image_name=$2"
shift 2
;;
--)
shift
break
;;
*)
echo "ERROR: invalide argument $1" >&2
exit 1
;;
esac
done
clean && clone && checkout && start_container && tarball && build
if [ $? == 0 ]; then
echo "Build SUCCESS!"
else
echo "Build FAILED!"
exit 1
fi
}
main "$@"