forked from alpine-docker/helm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sh
executable file
·54 lines (42 loc) · 1.28 KB
/
build.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
#!/usr/bin/env bash
# Prerequisite
# Make sure you set secret enviroment variables in Travis CI
# DOCKER_USERNAME
# DOCKER_PASSWORD
# API_USER
# API_TOKEN
set -ex
Usage() {
echo "$0 [rebuild]"
}
image="alpine/helm"
repo="kubernetes/helm"
latest=`curl -sL -u ${API_USER}:${API_TOKEN} https://api.github.com/repos/${repo}/tags |jq -r ".[].name"|head -1|sed 's/^v//'`
sum=0
echo "Lastest release is: ${latest}"
tags=`curl -sL https://hub.docker.com/v2/repositories/${image}/tags/ |jq -r .results[].name`
for i in ${tags}
do
if [ ${i} == ${latest} ];then
sum=$((sum+1))
fi
done
if [[ ( $sum -ne 1 ) || ( $1 == "rebuild" ) ]];then
docker build --no-cache --build-arg VERSION=$latest -t ${image}:${latest} .
# test
version=$(docker run -ti --rm ${image}:${latest} version -c )
#Client: &version.Version{SemVer:"v2.9.0-rc2", GitCommit:"08db2d0181f4ce394513c32ba1aee7ffc6bc3326", GitTreeState:"clean"}
version=$(echo $version| awk -F \" '{print $2}')
if [ "${version}" == "v${latest}" ]; then
echo "matched"
else
echo "unmatched"
exit
fi
docker tag ${image}:${latest} ${image}:latest
if [[ "$TRAVIS_BRANCH" == "master" ]]; then
docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
docker push ${image}:${latest}
docker push ${image}:latest
fi
fi