avro-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kojirom...@apache.org
Subject [avro] branch master updated: AVRO-2594: Use JAVA env when building local docker. (#709)
Date Wed, 11 Dec 2019 00:49:45 GMT
This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 0ff34ca  AVRO-2594: Use JAVA env when building local docker. (#709)
0ff34ca is described below

commit 0ff34ca6771ab7d9ff34844bc4e312df103450fb
Author: RyanSkraba <ryan@skraba.com>
AuthorDate: Wed Dec 11 01:49:35 2019 +0100

    AVRO-2594: Use JAVA env when building local docker. (#709)
    
    * AVRO-2594: Use JAVA env when building local docker.
    
    * AVRO-2594: Move test command to build.sh.
    
    * Add Dockerfile bash CMD for default.
    
    * AVRO-2594: Add both JDKs to container.
    
    * AVRO-2594: Set JAVA environment in Yetus docker.
    
    * AVRO-2594: Clarify comment.
    
    * Use portable form of bash functions.
    
    * AVRO-2594: Update script documentation.
    
    Make the script sourceable in bash to reuse the function.
    
    * AVRO-2594: Document choice in Dockerfile.
    
    * AVRO-2594: Fix sourcing from bash.
    
    * AVRO-2594: Avoid build errors when java not installed.
    
    * AVRO-2594: Don't change java version if target doesn't use java.
---
 .travis/script.sh            |  1 -
 build.sh                     | 38 +++++++++++++++++++++++++++++++++++++-
 share/docker/Dockerfile      | 22 ++++++++++++++++++++--
 share/docker/DockerfileLocal |  5 +++--
 share/precommit/buildtest.sh |  8 ++++++--
 5 files changed, 66 insertions(+), 8 deletions(-)

diff --git a/.travis/script.sh b/.travis/script.sh
index 00f1610..3082a73 100755
--- a/.travis/script.sh
+++ b/.travis/script.sh
@@ -19,7 +19,6 @@ set -e
 
 case "$TRAVIS_OS_NAME" in
 "linux")
-    sed -i.bak "s/openjdk:8/openjdk:${JAVA}/" share/docker/Dockerfile
     # Workaround for Yetus. For now, Yetus assumes the directory in which Dockerfile is placed
is the docker context.
     # So the Dockerfile should be here to refer to other subdirectories than share/docker
from inside the Dockerfile.
     cp share/docker/Dockerfile .
diff --git a/build.sh b/build.sh
index 8dadeb6..193c213 100755
--- a/build.sh
+++ b/build.sh
@@ -15,6 +15,30 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
+# ===========================================================================
+# Bash functions that can be used in this script or exported by using
+# source build.sh
+
+change_java_version() {
+  local jdk=$1
+  if ((jdk)) && [[ -d /usr/local/openjdk-${jdk} ]]; then
+    export JAVA_HOME=/usr/local/openjdk-${jdk}
+    export PATH=$JAVA_HOME/bin:$PATH
+    echo "----------------------"
+    echo "Java version switched:"
+  else
+    echo "Using the current Java version:"
+  fi
+  echo "  JAVA_HOME=$JAVA_HOME"
+  echo "  PATH=$PATH"
+  java -version
+}
+
+# Stop here if sourcing for functions
+[[ "$0" == *"bash" ]] && return 0
+
+# ===========================================================================
+
 set -xe
 cd "${0%/*}"
 
@@ -32,6 +56,17 @@ while (( "$#" ))
 do
   target="$1"
   shift
+
+  # Change the JDK from the default for all targets that will eventually require Java (or
maven).
+  # This only occurs when the JAVA environment variable is set and a Java environment exists
in
+  # the "standard" location (defined by the openjdk docker images).  This will typically
occur in CI
+  # builds.  In all other cases, the Java version is taken from the current installation
for the user.
+  case "$target" in
+    lint|test|dist|clean|veryclean|rat)
+    change_java_version "$JAVA"
+    ;;
+  esac
+
   case "$target" in
 
     lint)
@@ -277,6 +312,7 @@ do
       # down to under 10.  However, editing files from OSX may take a few
       # extra second before the changes are available within the docker container.
       docker run --rm -t -i \
+        --env JAVA=${JAVA:-8} \
         -v ${PWD}:/home/${USER_NAME}/avro${DOCKER_MOUNT_FLAG} \
         -w /home/${USER_NAME}/avro \
         -v ${HOME}/.m2:/home/${USER_NAME}/.m2${DOCKER_MOUNT_FLAG} \
@@ -300,7 +336,7 @@ do
       tar -cf- share/docker/Dockerfile \
                lang/ruby/Gemfile |
         docker build -t avro-test -f share/docker/Dockerfile -
-      docker run --rm -v ${PWD}:/avro/ avro-test
+      docker run --rm -v ${PWD}:/avro/ --env JAVA=${JAVA:-8} avro-test /avro/share/docker/run-tests.sh
       ;;
 
     *)
diff --git a/share/docker/Dockerfile b/share/docker/Dockerfile
index 473835e..669989e 100644
--- a/share/docker/Dockerfile
+++ b/share/docker/Dockerfile
@@ -17,9 +17,10 @@
 # Dockerfile for installing the necessary dependencies for building Avro.
 # See BUILD.txt.
 
-FROM openjdk:8
+# Despite this base, JDK8 is used by default.  See below.
+FROM openjdk:11
 WORKDIR /root
-CMD ["/avro/share/docker/run-tests.sh"]
+
 ENV APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=isolemnlysweariamuptonogood \
     DEBIAN_FRONTEND=noninteractive
 
@@ -47,6 +48,7 @@ RUN apt-get -qqy update \
                                                  libsnappy1v5 \
                                                  make \
                                                  maven \
+                                                 openjdk-8-jdk \
                                                  perl \
                                                  python \
                                                  python-pip \
@@ -141,3 +143,19 @@ RUN curl -sSLO https://packages.microsoft.com/config/ubuntu/16.04/packages-micro
 # Install Ruby modules
 COPY lang/ruby/Gemfile /tmp
 RUN bundle install --gemfile=/tmp/Gemfile
+
+# Note: This "ubertool" container has two JDK versions:
+# - OpenJDK 8 (installed as a package and available at /usr/bin/java)
+# - OpenJDK 11 (installed from the base image, and prioritized in the PATH)
+# - The root build.sh script switches between the versions according to 
+#   the JAVA environment variable.
+
+# Since want the JDK8 as a default, we have to re-prepend it to the PATH.
+# The /usr/local/openjdk-8 link is created to be consistent with the
+# openjdk:8 image.
+
+RUN ln -s /usr/lib/jvm/java-8-openjdk-amd64 /usr/local/openjdk-8
+ENV JAVA_HOME /usr/local/openjdk-8
+ENV PATH $JAVA_HOME/bin:$PATH
+
+CMD ["/bin/bash", "-i"]
diff --git a/share/docker/DockerfileLocal b/share/docker/DockerfileLocal
index cc2c553..dae1d53 100644
--- a/share/docker/DockerfileLocal
+++ b/share/docker/DockerfileLocal
@@ -14,8 +14,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-# Dockerfile for installing the necessary dependencies for building Avro.
-# See BUILD.txt.
+# Dockerfile for installing the Apache Forrest tools for building the
+# Avro site.
+
 FROM avro-build-ci
 
 # Install Forrest in /usr/local/apache-forrest
diff --git a/share/precommit/buildtest.sh b/share/precommit/buildtest.sh
index decf8b0..15635e5 100644
--- a/share/precommit/buildtest.sh
+++ b/share/precommit/buildtest.sh
@@ -22,7 +22,7 @@ VERBOSE=false
 BUILD_FILES=( build.sh )
 
 
-function buildtest_usage {
+buildtest_usage() {
   yetus_add_option "--verbose=<true|false>" "print output to console (default: false)"
 }
 
@@ -37,7 +37,7 @@ function buildtest_usage {
 #   fi
 # }
 
-function buildtest_postcompile {
+buildtest_postcompile() {
   for file in "${BUILD_FILES[@]}"; do
 
     big_console_header "Running ${file}"
@@ -60,3 +60,7 @@ function buildtest_postcompile {
     add_vote_table +1 buildtest "The build has passed"
   done
 }
+
+buildtest_docker_support() {
+  DOCKER_EXTRAARGS+=("--env" "JAVA=$JAVA")
+}


Mime
View raw message