forked from strapdata/elassandra
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker-ci.sh
executable file
·103 lines (84 loc) · 2.19 KB
/
docker-ci.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
#!/usr/bin/env bash
# fails on error and trace execution
set -ex
init() {
# shallow clone of the elassandra docker repository
rm -rf docker
git clone --depth 1 https://github.com/strapdata/docker-elassandra.git docker
cd docker
}
build_with_retry() {
# try 5 times, because gpg servers suck
n=0
until [ $n -ge 5 ]
do
echo "build try number $n"
# build and publish the docker image
./build.sh && break
n=$[$n+1]
sleep 1
done
if [ $n -eq 5 ]; then
echo "failed to build image"
exit 1
fi
}
gcloud_install() {
# If the SDK is not already cached, download it and unpack it
if [ ! -d ${HOME}/google-cloud-sdk ]; then
curl https://sdk.cloud.google.com | bash;
gcloud -v
fi
}
gcloud_auth() {
if [ -z "$GCLOUD_SECRET_KEY" ]; then
echo "GCLOUD_SECRET_KEY is not set. Can't authenticate with gcloud"
return 1
else
echo "$GCLOUD_SECRET_KEY" | base64 -d > gcloud-secret.json
gcloud auth activate-service-account --key-file gcloud-secret.json
# does not work for docker 17.x
# gcloud beta auth configure-docker
cat gcloud-secret.json | docker login -u _json_key --password-stdin https://gcr.io
fi
}
under_travis() {
# Special branching to be ran under travis
export REPO_NAME=${TRAVIS_REPO_SLUG}
export REPO_DIR=${TRAVIS_BUILD_DIR}
export ELASSANDRA_COMMIT=${TRAVIS_COMMIT}
if [ -n "$TRAVIS_TAG" ]; then
# publish to docker hub when a tag is set
export DOCKER_PUBLISH=true
# try to infer if the current build need to be tagged "latest"
ELASTICSEARCH_VERSION=$(echo "$TRAVIS_TAG" | sed 's/v\(.*\..*.\..*\)\..*/\1/')
if [ "$ELASTICSEARCH_VERSION" = "$LATEST_VERSION" ]; then
export DOCKER_LATEST=true
fi
fi
# publish to docker hub
build_with_retry
# publish to gcloud registry
gcloud_install
gcloud_auth || return 1
DOCKER_REGISTRY=gcr.io/ REPO_NAME=${GCLOUD_REPO_NAME:-strapdata-factory/elassandra} BASE_IMAGE=launcher.gcr.io/google/debian9:latest build_with_retry
}
manual_run() {
export REPO_DIR=../
build_with_retry
}
cleanup() {
# clean up
cd ../
rm -rf docker
}
main() {
init
if [ "$TRAVIS" = "true" ]; then
under_travis
else
manual_run
fi
cleanup
}
main