Skip to content

Commit

Permalink
Ci/docker gcloud (#13)
Browse files Browse the repository at this point in the history
* push docker image to gcloud from travis

* gcloud secret base64 encoded

* use tianon/pgp-happy-eyeballs to solve gpg server problems

* try to login to gcloud registry using docker login

* add GCLOUD_REPO_NAME var

* switch to openjdk because install script fails with oracle
  • Loading branch information
DBarthe committed Oct 18, 2018
1 parent 37ed00c commit fd24142
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 29 deletions.
8 changes: 7 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ env:
global:
# this variable determine when docker images are tagged 'latest'
- LATEST_VERSION=6.2.3
# Make sure gcloud command is on our PATH and the App Engine SDK is in the Python path
- GAE_PYTHONPATH=${HOME}/.cache/google_appengine PATH=$PATH:${HOME}/google-cloud-sdk/bin PYTHONPATH=${PYTHONPATH}:${GAE_PYTHONPATH} CLOUDSDK_CORE_DISABLE_PROMPTS=1

language:
- java
Expand All @@ -20,15 +22,19 @@ cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
# Cache our Gcloud SDK between commands
- $HOME/google-cloud-sdk/

before_install:
- wget https://github.com/sormuras/bach/raw/master/install-jdk.sh
# solves gpg server problems
- wget -qO- 'https://github.com/tianon/pgp-happy-eyeballs/raw/master/hack-my-builds.sh' | bash

matrix:
include:
# Java 10 "Oracle JDK"
- env: JDK='Oracle JDK 10'
install: . ./install-jdk.sh -F 10 -L BCL
install: . ./install-jdk.sh -F 10

install: ./gradlew --version

Expand Down
107 changes: 79 additions & 28 deletions docker-ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,53 @@
# fails on error and trace execution
set -ex

# shallow clone of the elassandra docker repository
rm -rf docker
git clone --depth 1 https://github.com/strapdata/docker-elassandra.git docker
cd docker
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
}

# set parameters
if [ "$TRAVIS" = "true" ]; then
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}
Expand All @@ -27,26 +67,37 @@ if [ "$TRAVIS" = "true" ]; then
fi
fi

else
# 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-docker-registry/elassandra} build_with_retry
}

manual_run() {
export REPO_DIR=../
fi

# 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


# clean up
cd ../
rm -rf docker
build_with_retry
}

cleanup() {
# clean up
cd ../
rm -rf docker
}

main() {
init

if [ "$TRAVIS" = "true" ]; then
under_travis
else
manual_run
fi

cleanup
}

main

0 comments on commit fd24142

Please sign in to comment.