From 0ee1faded27b7cd65878d0dc331362fa4a004e55 Mon Sep 17 00:00:00 2001 From: Matteo Merli Date: Tue, 18 Jul 2017 16:32:09 -0700 Subject: [PATCH] Build and publish docker images (#575) --- .travis.yml | 16 +++++++++- docker/build.sh | 16 ++++------ docker/get-version.sh | 30 ++++++++++++++++++ docker/publish.sh | 72 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 123 insertions(+), 11 deletions(-) create mode 100755 docker/get-version.sh create mode 100755 docker/publish.sh diff --git a/.travis.yml b/.travis.yml index fe759d27cbf..1450a16a6ba 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,6 +21,11 @@ language: java C++ ruby jdk: - oraclejdk8 +sudo: required + +services: + - docker + cache: directories: - $HOME/.m2 @@ -44,7 +49,10 @@ install: script: # Build Java and C++ - - mvn license:check test && sudo bash -x $TRAVIS_BUILD_DIR/pulsar-client-cpp/travis-build.sh $HOME/pulsar-dep $TRAVIS_BUILD_DIR compile + - mvn license:check test package && sudo bash -x $TRAVIS_BUILD_DIR/pulsar-client-cpp/travis-build.sh $HOME/pulsar-dep $TRAVIS_BUILD_DIR compile + # Build docker images + - docker/build.sh + # Generate website - (cd site && make travis_build) deploy: @@ -81,3 +89,9 @@ deploy: on: repo: apache/incubator-pulsar branch: master + - + provider: script + skip_cleanup: true + script: docker/publish.sh + on: + tags: true diff --git a/docker/build.sh b/docker/build.sh index afc03debbad..1a43b8ca96c 100755 --- a/docker/build.sh +++ b/docker/build.sh @@ -18,14 +18,10 @@ # under the License. # -# Get the project version from Maven -pushd .. > /dev/null -MVN_VERSION=$(mvn -q \ - -Dexec.executable="echo" \ - -Dexec.args='${project.version}' \ - --non-recursive \ - org.codehaus.mojo:exec-maven-plugin:1.3.1:exec) -popd > /dev/null +ROOT_DIR=$(git rev-parse --show-toplevel) +cd $ROOT_DIR/docker + +MVN_VERSION=`./get-version.sh` echo "Pulsar version: ${MVN_VERSION}" @@ -54,14 +50,14 @@ rm pulsar-${MVN_VERSION}-bin.tar.gz # Build pulsar-grafana image -docker build -t pulsar-grafana grafana +docker build -t pulsar-grafana:latest grafana if [ $? != 0 ]; then echo "Error: Failed to create Docker image for pulsar-grafana" exit 1 fi # Build dashboard docker image -docker build -t pulsar-dashboard ../dashboard +docker build -t pulsar-dashboard:latest ../dashboard if [ $? != 0 ]; then echo "Error: Failed to create Docker image for pulsar-dashboard" exit 1 diff --git a/docker/get-version.sh b/docker/get-version.sh new file mode 100755 index 00000000000..b2318ba9683 --- /dev/null +++ b/docker/get-version.sh @@ -0,0 +1,30 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +ROOT_DIR=$(git rev-parse --show-toplevel) + +pushd $ROOT_DIR > /dev/null + +# Get the project version from the Maven pom.xml +cat pom.xml | xmllint --format - \ + | sed "s/xmlns=\".*\"//g" | xmllint --stream --pattern /project/version --debug - \ + | grep -A 2 "matches pattern" | grep text | sed "s/.* [0-9] //g" + +popd > /dev/null diff --git a/docker/publish.sh b/docker/publish.sh new file mode 100755 index 00000000000..6ca3c0c40b3 --- /dev/null +++ b/docker/publish.sh @@ -0,0 +1,72 @@ +#!/bin/bash +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +ROOT_DIR=$(git rev-parse --show-toplevel) +cd $ROOT_DIR/docker + +# We should only publish images that are made from official and approved releases +# and thus ignore all the release candidates that are just tagged during the release +# process +if [[ ${TRAVIS_TAG} == *"candidate"* || ${TRAVIS_TAG} == *"rc"* ]]; then + echo "Skipping non-final release tag ${TRAVIS_TAG}" + exit 0 +fi + +if [ -z "$DOCKER_USER" ]; then + echo "Docker user in variable \$DOCKER_USER was not set. Skipping image publishing" + exit 1 +fi + +if [ -z "$DOCKER_PASSWORD" ]; then + echo "Docker password in variable \$DOCKER_PASSWORD was not set. Skipping image publishing" + exit 1 +fi + +DOCKER_ORG="${DOCKER_ORG:-apachepulsar}" + +docker login -u="$DOCKER_USER" -p="$DOCKER_PASSWORD" +if [ $? -ne 0 ]; then + echo "Failed to loging to Docker Hub" + exit 1 +fi + +MVN_VERSION=`./get-version.sh` +echo "Pulsar version: ${MVN_VERSION}" + +set -x + +# Fail if any of the subsequent commands fail +set -e + +docker tag pulsar:latest $DOCKER_ORG/pulsar:latest +docker tag pulsar-grafana:latest $DOCKER_ORG/pulsar-grafana:latest +docker tag pulsar-dashboard:latest $DOCKER_ORG/pulsar-dashboard:latest + +docker tag pulsar:latest $DOCKER_ORG/pulsar:$MVN_VERSION +docker tag pulsar-grafana:latest $DOCKER_ORG/pulsar-grafana:$MVN_VERSION +docker tag pulsar-dashboard:latest $DOCKER_ORG/pulsar-dashboard:$MVN_VERSION + +# Push all images and tags +docker push $DOCKER_ORG/pulsar:latest +docker push $DOCKER_ORG/pulsar-grafana:latest +docker push $DOCKER_ORG/pulsar-dashboard:latest +docker push $DOCKER_ORG/pulsar:$MVN_VERSION +docker push $DOCKER_ORG/pulsar-grafana:$MVN_VERSION +docker push $DOCKER_ORG/pulsar-dashboard:$MVN_VERSION -- GitLab