This is an automated email from the ASF dual-hosted git repository.

sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git


The following commit(s) were added to refs/heads/master by this push:
     new b0b69a3  Publish bookkeeper dev image to docker hub
b0b69a3 is described below

commit b0b69a337b4220752dfb512fdb99cfc5bdab564a
Author: Sijie Guo <si...@apache.org>
AuthorDate: Wed May 23 10:56:04 2018 -0700

    Publish bookkeeper dev image to docker hub
    
    Descriptions of the changes in this PR:
    
    *Motivation*
    
    We built a `bookkeeper-current` image that reflects latest master for 
integration tests. However currently we don't publish this docker image to any 
docker registry. So it is inconvenient to test latest master in dockerized 
environments.
    
    *Solution*
    
    - Add a dev script to publish `bookkeeper-current` image to configured 
docker registry specified at `DOCKER_REGISTRY`
    - Update the nightly snapshot job to publish generated `bookkeeper-current` 
image to docker hub `apachebookkeeper`
    - Add `bin/standalone` script to use `docker-compose` to launch a 3-nodes 
bookkeeper cluster locally. The script generates docker-compose.yml and handles 
mounting local volumes and port forwarding. so developers can use that for 
quick development.
    
    Author: Sijie Guo <si...@apache.org>
    
    Reviewers: Enrico Olivelli <eolive...@gmail.com>, Jia Zhai <None>
    
    This closes #1427 from sijie/push_current_docker_image
---
 .gitignore                                         |   3 +
 .test-infra/jenkins/common_job_properties.groovy   |   1 +
 ...seed.groovy => jenkins_testing_job_seed.groovy} |   2 +-
 .../job_bookkeeper_release_nightly_snapshot.groovy |  23 ++-
 bin/standalone                                     |  31 ++++
 bin/standalone.docker-compose                      | 177 +++++++++++++++++++++
 dev/common.sh                                      |  30 ++++
 dev/publish-docker-images.sh                       |  70 ++++++++
 pom.xml                                            |   3 +
 9 files changed, 334 insertions(+), 6 deletions(-)

diff --git a/.gitignore b/.gitignore
index 98b8004..4865c98 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,3 +26,6 @@ logs/
 
 # Vagrant
 **/.vagrant
+
+# Data directory
+data/
diff --git a/.test-infra/jenkins/common_job_properties.groovy 
b/.test-infra/jenkins/common_job_properties.groovy
index 7ff5fe1..2b51f42 100644
--- a/.test-infra/jenkins/common_job_properties.groovy
+++ b/.test-infra/jenkins/common_job_properties.groovy
@@ -110,6 +110,7 @@ class common_job_properties {
 
       credentialsBinding {
         string("COVERALLS_REPO_TOKEN", "bookkeeper-coveralls-token")
+        usernamePassword('DOCKER_USER', 'DOCKER_PASSWORD', 
'bookkeeper_dockerhub')
       }
     }
   }
diff --git a/.test-infra/jenkins/job_testing_seed.groovy 
b/.test-infra/jenkins/jenkins_testing_job_seed.groovy
similarity index 97%
rename from .test-infra/jenkins/job_testing_seed.groovy
rename to .test-infra/jenkins/jenkins_testing_job_seed.groovy
index 5688ba7..a4cb50a 100644
--- a/.test-infra/jenkins/job_testing_seed.groovy
+++ b/.test-infra/jenkins/jenkins_testing_job_seed.groovy
@@ -16,7 +16,7 @@
  * limitations under the License.
  */
 
-job('bookkeeper-jenkins-testing/seed') {
+job('bookkeeper-jenkins-testing-seed') {
   description('Seed job, which allows DSL jobs to be tested before being 
pushed for review')
 
   // Source code management.
diff --git a/.test-infra/jenkins/job_bookkeeper_release_nightly_snapshot.groovy 
b/.test-infra/jenkins/job_bookkeeper_release_nightly_snapshot.groovy
index 02d2a60..5938e06 100644
--- a/.test-infra/jenkins/job_bookkeeper_release_nightly_snapshot.groovy
+++ b/.test-infra/jenkins/job_bookkeeper_release_nightly_snapshot.groovy
@@ -19,7 +19,7 @@
 import common_job_properties
 
 // This job deploys a snapshot of latest master to artifactory nightly
-mavenJob('bookkeeper_release_nightly_snapshot') {
+freeStyleJob('bookkeeper_release_nightly_snapshot') {
   description('runs a `mvn clean deploy` of the nightly snapshot for 
bookkeeper.')
 
   // Set common parameters.
@@ -37,9 +37,22 @@ mavenJob('bookkeeper_release_nightly_snapshot') {
       'Release Snapshot',
       '/release-snapshot')
 
-  // Set maven parameters.
-  common_job_properties.setMavenConfig(delegate)
+  steps {
+    maven {
+      // Set maven parameters.
+      common_job_properties.setMavenConfig(delegate)
 
-  // Maven build project.
-  goals('clean apache-rat:check package spotbugs:check 
-Dmaven.test.failure.ignore=true deploy -Ddistributedlog -Dstream 
-DstreamTests')
+      // Maven build project.
+      goals('clean apache-rat:check package spotbugs:check 
-Dmaven.test.failure.ignore=true deploy -Ddistributedlog -Dstream -DstreamTests 
-Pdocker')
+    }
+
+    // publish the docker images
+    shell '''
+export MAVEN_HOME=/home/jenkins/tools/maven/latest
+export PATH=$JAVA_HOME/bin:$MAVEN_HOME/bin:$PATH
+export MAVEN_OPTS=-Xmx2048m
+
+./dev/publish-docker-images.sh
+    '''.stripIndent().trim()
+  }
 }
diff --git a/bin/standalone b/bin/standalone
new file mode 100755
index 0000000..d4bc0f5
--- /dev/null
+++ b/bin/standalone
@@ -0,0 +1,31 @@
+#!/usr/bin/env bash
+#
+# vim:et:ft=sh:sts=2:sw=2
+#
+#/**
+# * 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.
+# */
+
+BINDIR=${BK_BINDIR:-"`dirname "$0"`"}
+
+DOCKER_COMPOSE=$(which docker-compose)
+if [ $? != 0 ]; then
+  echo "Error: docker-compose is not found in ${PATH}." 1>&2
+  exit 1
+else
+  ${BINDIR}/standalone.docker-compose $@
+fi
diff --git a/bin/standalone.docker-compose b/bin/standalone.docker-compose
new file mode 100755
index 0000000..25e9fcb
--- /dev/null
+++ b/bin/standalone.docker-compose
@@ -0,0 +1,177 @@
+#!/usr/bin/env bash
+#
+# vim:et:ft=sh:sts=2:sw=2
+#
+#/**
+# * 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.
+# */
+
+BINDIR=${BK_BINDIR:-"`dirname "$0"`"}
+
+source ${BINDIR}/common.sh
+
+DOCKER_COMPOSE=docker-compose
+
+DATA_ROOT_DIR=${BK_DATA_DIR:-"${BK_HOME}/data"}
+mkdir -p ${DATA_ROOT_DIR}
+
+function gen_metadata_service_section() {
+  local cluster=$1
+  local image=$2
+  cat <<EOF
+  metadata-service:
+    image: ${image}
+    hostname: metadata-service
+    command: ["zookeeper"]
+    environment:
+      - ZK_dataDir=/data/zookeeper/data
+      - ZK_dataLogDir=/data/zookeeper/txlog
+      - ZK_standaloneEnabled=true
+    ports:
+      - "9990:9990"
+      - "2181:2181"
+    volumes:
+      - "${DATA_ROOT_DIR}/${cluster}/zookeeper/data:/data/zookeeper/data"
+      - "${DATA_ROOT_DIR}/${cluster}/zookeeper/txlog:/data/zookeeper/txlog"
+EOF
+}
+
+function gen_bookie_section() {
+  local cluster=$1
+  local bookie_name=$2
+  local bookie_port=$3
+  local image=$4
+  cat <<EOF
+  ${bookie_name}:
+    image: ${image}
+    depends_on:
+      - metadata-service
+    environment:
+      - BK_zkServers=metadata-service
+      - BK_metadataServiceUri=zk://metadata-service/ledgers
+      - BK_zkLedgersRootPath=/ledgers
+      - BK_journalDirectory=/data/bookkeeper/journal
+      - BK_ledgerDirectories=/data/bookkeeper/ledgers
+      - BK_indexDirectories=/data/bookkeeper/ledgers
+      - BK_advertisedAddress=localhost
+      - BK_bookiePort=${bookie_port}
+    ports:
+      - "${bookie_port}:${bookie_port}"
+    volumes:
+      - 
"${DATA_ROOT_DIR}/${cluster}/${bookie_name}/journal:/data/bookkeeper/journal"
+      - 
"${DATA_ROOT_DIR}/${cluster}/${bookie_name}/ledgers:/data/bookkeeper/ledgers"
+EOF
+}
+
+function generate_docker_compose_file() {
+  local cluster=$1
+  local num_bookies=$2
+  local image=$3
+  local docker_compose_file="${DATA_ROOT_DIR}/${cluster}/docker-compose.yml"
+
+  local metadata_service_section=$(gen_metadata_service_section ${cluster} 
${image})
+    
+  echo "version: '3'"                 >  ${docker_compose_file}
+  echo ""                             >> ${docker_compose_file}
+  echo "services:"                    >> ${docker_compose_file}
+  echo ""                             >> ${docker_compose_file}
+  echo "${metadata_service_section}"  >> ${docker_compose_file}
+  echo ""                             >> ${docker_compose_file}
+  local BI=0
+  while [ ${BI} -lt $((num_bookies)) ]; do
+    local bookie_port=$((3181 + BI))
+    local bookie_section=$(gen_bookie_section ${cluster} "bookie-${BI}" 
${bookie_port} ${image})
+    echo "${bookie_section}"        >> ${docker_compose_file}
+    let BI=BI+1
+  done
+}
+
+function show_help() {
+  cat <<EOF
+Usage: standalone [-c <cluster_name>] [-h] <action:[up|down]>
+EOF
+}
+
+# main entrypoint
+
+CLUSTER_NAME="bk-standalone-dc"
+OPTIND=1
+IMAGE=${IMAGE:-"apachebookkeeper/bookkeeper-current"}
+NUM_BOOKIES=${NUM_BOOKIES:-"3"}
+
+while getopts "h:c:" opt; do
+  case "${opt}" in
+  c )
+    CLUSTER_NAME=${OPTARG}
+    echo "use cluster = '${CLUSTER_NAME}'."
+    ;;
+  h|\? )
+    show_help
+    exit 1
+    ;;
+  esac
+done
+
+shift $((OPTIND-1))
+
+[ "${1:-}" = "--" ] && shift
+
+if [ $# -le 0 ]; then
+  show_help
+  exit 1
+fi
+
+ACTION=$1
+DOCKER_COMPOSE_OPTS=""
+case "${ACTION}" in
+  up)
+    DOCKER_COMPOSE_OPTS="--detach"
+    ;;
+  down)
+    ;;
+  *)
+    echo "Unknown action : ${ACTION}"
+    show_help
+    exit 1
+    ;;
+esac
+
+CLUSTER_DATA_ROOT="${DATA_ROOT_DIR}/${CLUSTER_NAME}"
+mkdir -p ${CLUSTER_DATA_ROOT}
+
+# generate docker compose file 
+DOCKER_COMPOSE_FILE="${CLUSTER_DATA_ROOT}/docker-compose.yml"
+
+if [ ! -f ${DOCKER_COMPOSE_FILE} ]; then
+  generate_docker_compose_file ${CLUSTER_NAME} ${NUM_BOOKIES} ${IMAGE}
+fi
+
+cd ${CLUSTER_DATA_ROOT}
+
+
+
+${DOCKER_COMPOSE} $@ ${DOCKER_COMPOSE_OPTS}
+
+if [ $? == 0 -a "${ACTION}" == "up" ]; then
+    echo ""
+    echo "Standalone cluster '${CLUSTER_NAME}' is up running."
+    echo "Use following uris to connect to standalone cluster:"
+    echo ""
+    echo "  - metadata service uri = 'zk://localhost/ledgers'"
+    echo "  - dlog uri             = 
'distributedlog://localhost/distributedlog'"
+fi
+exit $?
diff --git a/dev/common.sh b/dev/common.sh
new file mode 100644
index 0000000..d172d07
--- /dev/null
+++ b/dev/common.sh
@@ -0,0 +1,30 @@
+#!/usr/bin/env bash
+#
+# vim:et:ft=sh:sts=2:sw=2
+#
+# 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.
+#
+
+function get_bk_version() {
+    bk_version=`mvn org.apache.maven.plugins:maven-help-plugin:2.1.1:evaluate 
-Dexpression=project.version | grep -Ev '(^\[|Download\w+:)' 2> /dev/null`
+    echo ${bk_version}
+}
+
+export BK_DEV_DIR=`dirname "$0"`
+export BK_HOME=`cd ${BK_DEV_DIR}/..;pwd`
+export BK_VERSION=`get_bk_version`
diff --git a/dev/publish-docker-images.sh b/dev/publish-docker-images.sh
new file mode 100755
index 0000000..66d3e80
--- /dev/null
+++ b/dev/publish-docker-images.sh
@@ -0,0 +1,70 @@
+#!/usr/bin/env bash
+#
+# vim:et:ft=sh:sts=2:sw=2
+#
+# 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.
+#
+
+###############################################################################
+# Script to publish docker images to docker hub. This script is run at Jenkins
+# after building the current images.
+#
+# The script is sourced from Apache Pulsar (incubating).
+# https://github.com/apache/incubator-pulsar/blob/master/docker/publish.sh
+#
+# usage: ./dev/publish-docker-images.sh
+
+source `dirname "$0"`/common.sh
+
+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:-apachebookkeeper}"
+
+docker login ${DOCKER_REGISTRY} -u="${DOCKER_USER}" -p="${DOCKER_PASSWORD}"
+if [ $? -ne 0 ]; then
+    echo "Failed to loging to Docker Hub"
+    exit 1
+fi
+
+echo "BookKeeper Version: ${BK_VERSION}"
+
+if [[ -z ${DOCKER_REGISTRY} ]]; then
+    docker_registry_org=${DOCKER_ORG}
+else
+    docker_registry_org=${DOCKER_REGISTRY}/${DOCKER_ORG}
+fi
+echo "Starting to push images to ${docker_registry_org} as user 
${DOCKER_USER}..."
+
+set -x
+
+# Fail if any of the subsequent commands fail
+set -e
+
+# Publish the current image
+docker push ${docker_registry_org}/bookkeeper-current:latest
+docker push ${docker_registry_org}/bookkeeper-current:$BK_VERSION
+
+echo "Finished pushing images to ${docker_registry_org}"
diff --git a/pom.xml b/pom.xml
index a33fb7f..0a98b1f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -864,6 +864,9 @@
 
             <!-- logs -->
             <exclude>**/*.log</exclude>
+
+            <!-- data -->
+            <exclude>data/**</exclude>
           </excludes>
           <consoleOutput>true</consoleOutput>
         </configuration>

-- 
To stop receiving notification emails like this one, please contact
si...@apache.org.

Reply via email to