You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@bookkeeper.apache.org by GitBox <gi...@apache.org> on 2018/05/23 17:56:16 UTC

[GitHub] sijie closed pull request #1427: Publish bookkeeper dev image to docker hub

sijie closed pull request #1427: Publish bookkeeper dev image to docker hub
URL: https://github.com/apache/bookkeeper/pull/1427
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/.gitignore b/.gitignore
index 98b800409..4865c98eb 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 7ff5fe1ff..2b51f4266 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 5688ba71e..a4cb50ae4 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 02d2a60c5..5938e06f0 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 000000000..d4bc0f5b8
--- /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 000000000..25e9fcbcb
--- /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 000000000..d172d07b3
--- /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 000000000..66d3e805e
--- /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 a33fb7ffb..0a98b1f78 100644
--- a/pom.xml
+++ b/pom.xml
@@ -864,6 +864,9 @@
 
             <!-- logs -->
             <exclude>**/*.log</exclude>
+
+            <!-- data -->
+            <exclude>data/**</exclude>
           </excludes>
           <consoleOutput>true</consoleOutput>
         </configuration>


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services