You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@impala.apache.org by ta...@apache.org on 2019/07/30 23:39:43 UTC

[impala] branch master updated: IMPALA-8785: give debug docker images a different name

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

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


The following commit(s) were added to refs/heads/master by this push:
     new def70c2  IMPALA-8785: give debug docker images a different name
def70c2 is described below

commit def70c241dffcdab8301cbc7456ea6680ca01692
Author: Tim Armstrong <ta...@cloudera.com>
AuthorDate: Tue Jul 23 13:08:35 2019 -0700

    IMPALA-8785: give debug docker images a different name
    
    * Build scripts are generalised to have different targets for release
      and debug images.
    * Added new targets for the debug images: docker_debug_images,
      statestored_debug images. The release images still have the
      same names.
    * Separate build contexts are set up for the different base
      images.
    * The debug or release base image can be specified as the FROM
      for the daemon images.
    * start-impala-cluster.py picks the correct images for the build type
    
    Future work:
    We would like to generalise this to allow building from
    non-ubuntu-16.04 base images. This probably requires another
    layer of dockerfiles to specify a base image for impala_base
    with the required packages installed.
    
    Change-Id: I32d2e19cb671beacceebb2642aba01191bd7a244
    Reviewed-on: http://gerrit.cloudera.org:8080/13905
    Reviewed-by: Joe McDonnell <jo...@cloudera.com>
    Tested-by: Impala Public Jenkins <im...@cloudera.com>
---
 bin/jenkins/dockerized-impala-run-tests.sh |  2 +-
 bin/start-impala-cluster.py                |  7 ++-
 docker/CMakeLists.txt                      | 93 +++++++++++++++++++-----------
 docker/catalogd/Dockerfile                 |  3 +-
 docker/impalad_coord_exec/Dockerfile       |  3 +-
 docker/impalad_coordinator/Dockerfile      |  3 +-
 docker/impalad_executor/Dockerfile         |  3 +-
 docker/setup_build_context.py              | 24 ++++++--
 docker/statestored/Dockerfile              |  3 +-
 9 files changed, 96 insertions(+), 45 deletions(-)

diff --git a/bin/jenkins/dockerized-impala-run-tests.sh b/bin/jenkins/dockerized-impala-run-tests.sh
index 67a86b8..f2bc8ec 100755
--- a/bin/jenkins/dockerized-impala-run-tests.sh
+++ b/bin/jenkins/dockerized-impala-run-tests.sh
@@ -72,7 +72,7 @@ start-impala-cluster.py --kill
 
 # Build the docker images required to start the cluster.
 # parquet-reader is needed for e2e tests but not built for non-test build.
-make -j ${IMPALA_BUILD_THREADS} docker_images parquet-reader
+make -j ${IMPALA_BUILD_THREADS} docker_debug_images parquet-reader
 
 source_impala_config
 
diff --git a/bin/start-impala-cluster.py b/bin/start-impala-cluster.py
index f6ddb76..43294d6 100755
--- a/bin/start-impala-cluster.py
+++ b/bin/start-impala-cluster.py
@@ -575,7 +575,12 @@ class DockerMiniClusterOperations(object):
                 "-e", "JAVA_TOOL_OPTIONS={0}".format(
                     build_java_tool_options(DEFAULT_IMPALAD_JVM_DEBUG_PORT))]
     # The container build processes tags the generated image with the daemon name.
-    image_tag = daemon
+    debug_build = options.build_type == "debug" or (options.build_type == "latest" and
+        os.path.basename(os.path.dirname(os.readlink("be/build/latest"))) == "debug")
+    if debug_build:
+      image_tag = daemon + "_debug"
+    else:
+      image_tag = daemon
     host_name = self.__gen_host_name__(daemon, instance)
     container_name = self.__gen_container_name__(daemon, instance)
     # Mount configuration into container so that we don't need to rebuild container
diff --git a/docker/CMakeLists.txt b/docker/CMakeLists.txt
index 6700706..b798331 100644
--- a/docker/CMakeLists.txt
+++ b/docker/CMakeLists.txt
@@ -19,52 +19,77 @@ set(IMPALA_BASE_BUILD_CONTEXT_DIR
   ${CMAKE_SOURCE_DIR}/docker/build_context
 )
 
-# Build context depends on daemons and frontend jars
-# Sending the whole impala workspace including test binaries, testdata, etc
-# to the docker daemon can be very expensive, so we create a build context
-# with symlinks
-add_custom_target(impala_base_build_context
-  COMMAND ${CMAKE_SOURCE_DIR}/docker/setup_build_context.py
-  DEPENDS daemons fe ${CMAKE_SOURCE_DIR}/docker/setup_build_context.py
-  COMMENT "Creating impala base build context."
-  VERBATIM
-)
-
-# Target for the base Impala image.
-add_custom_target(impala_base_image
-  # Use tar with -h flag to assemble a tarball including all the symlinked files and
-  # directories in the build context.
-  COMMAND cd ${IMPALA_BASE_BUILD_CONTEXT_DIR} && tar cvh . | docker build -t impala_base -
-  DEPENDS impala_base_build_context ${CMAKE_SOURCE_DIR}/docker/impala_base/Dockerfile
-  DEPENDS ${CMAKE_SOURCE_DIR}/docker/daemon_entrypoint.sh
-  DEPENDS ${CMAKE_SOURCE_DIR}/bin/graceful_shutdown_backends.sh
-  COMMENT "Building Impala base docker image."
-  VERBATIM
-)
+# Add a target to build a base docker image for 'build_type'. 'build_context_args' are
+# passed to the setup_build_context.py script.
+function(add_base_image build_type build_context_args)
+  # Build context depends on daemons and frontend jars
+  # Sending the whole impala workspace including test binaries, testdata, etc
+  # to the docker daemon can be very expensive, so we create a build context
+  # with symlinks
+  add_custom_target(impala_base_build_context_${build_type}
+    COMMAND ${CMAKE_SOURCE_DIR}/docker/setup_build_context.py ${build_context_args}
+    DEPENDS daemons fe ${CMAKE_SOURCE_DIR}/docker/setup_build_context.py
+    COMMENT "Creating impala base build context build_type=${build_type}."
+    VERBATIM
+  )
+  # Target for the base Impala image.
+  add_custom_target(impala_base_image_${build_type}
+    # Use tar with -h flag to assemble a tarball including all the symlinked files and
+    # directories in the build context.
+    COMMAND cd ${IMPALA_BASE_BUILD_CONTEXT_DIR}/${build_type} && tar cvh . | docker build -t impala_base_${build_type} -
+    DEPENDS impala_base_build_context_${build_type} ${CMAKE_SOURCE_DIR}/docker/impala_base/Dockerfile
+    DEPENDS ${CMAKE_SOURCE_DIR}/docker/daemon_entrypoint.sh
+    DEPENDS ${CMAKE_SOURCE_DIR}/bin/graceful_shutdown_backends.sh
+    COMMENT "Building Impala base docker image build_type=${build_type}."
+    VERBATIM
+  )
+endfunction()
+add_base_image(release "")
+add_base_image(debug "--debug-build")
 
 # Target to build all docker images. Dependencies are added for each docker image
 # instantiated below.
 add_custom_target(docker_images)
+add_custom_target(docker_debug_images)
 
 set(daemon_image_names "")
 
-function(add_daemon_docker_image image_name)
-  add_custom_target(${image_name}_image
-    COMMAND cd ${CMAKE_SOURCE_DIR}/docker/${image_name} && docker build -t ${image_name} .
-    DEPENDS impala_base_image ${CMAKE_SOURCE_DIR}/docker/${image_name}/Dockerfile
+# Add a target with name 'target' to build a daemon image for the daemon with
+# name 'daemon_name', e.g. "impalad_executor". The image is tagged as 'image_name'.
+# 'build_type' should be debug or release and determines which base image is used.
+function(add_daemon_docker_image target daemon_name image_name build_type)
+  set(build_dir ${CMAKE_SOURCE_DIR}/docker/${daemon_name})
+  add_custom_target(${target}
+    # Supply the appropriate base image as an argument for the Dockerfile.
+    COMMAND cd ${build_dir} && docker build --build-arg BASE_IMAGE=impala_base_${build_type} -t ${image_name} .
+    DEPENDS impala_base_image_${build_type} ${build_dir}/Dockerfile
     COMMENT "Building ${image_name} docker image."
     VERBATIM
   )
-  ADD_DEPENDENCIES(docker_images ${image_name}_image)
   set(daemon_image_names "${daemon_image_names} ${image_name}" PARENT_SCOPE)
 endfunction()
 
-# Command and target for the various Impalad images.
-add_daemon_docker_image(impalad_coord_exec)
-add_daemon_docker_image(impalad_coordinator)
-add_daemon_docker_image(impalad_executor)
-add_daemon_docker_image(catalogd)
-add_daemon_docker_image(statestored)
+# Add debug and release docker image targets for the given daemon e.g. if called
+# with "statestored", targets "statestored_image" and "statestored_debug_image"
+# are added.
+function(add_daemon_docker_images daemon_name)
+  set(release_image ${daemon_name})
+  set(release_target ${daemon_name}_image)
+  set(debug_image ${daemon_name}_debug)
+  set(debug_target ${daemon_name}_debug_image)
+  add_daemon_docker_image(${release_target} ${daemon_name} ${release_image} release)
+  add_daemon_docker_image(${debug_target} ${daemon_name} ${debug_image} debug)
+  ADD_DEPENDENCIES(docker_images ${release_target})
+  ADD_DEPENDENCIES(docker_debug_images ${debug_target})
+  set(daemon_image_names "${daemon_image_names} ${release_image}" PARENT_SCOPE)
+endfunction()
+
+# Stamp out image targets for all of the Impala daemons.
+add_daemon_docker_images(impalad_coord_exec)
+add_daemon_docker_images(impalad_coordinator)
+add_daemon_docker_images(impalad_executor)
+add_daemon_docker_images(catalogd)
+add_daemon_docker_images(statestored)
 
-# Generate a test file with all the daemon images.
+# Generate a text file with all of the release daemon images.
 file(WRITE ${CMAKE_SOURCE_DIR}/docker/docker-images.txt "${daemon_image_names}")
diff --git a/docker/catalogd/Dockerfile b/docker/catalogd/Dockerfile
index 6989dec..5473c12 100644
--- a/docker/catalogd/Dockerfile
+++ b/docker/catalogd/Dockerfile
@@ -15,7 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
-FROM impala_base
+ARG BASE_IMAGE=impala_base
+FROM ${BASE_IMAGE}
 
 # Externally-facing ports
 # Debug webserver
diff --git a/docker/impalad_coord_exec/Dockerfile b/docker/impalad_coord_exec/Dockerfile
index 271fee5..542734b 100644
--- a/docker/impalad_coord_exec/Dockerfile
+++ b/docker/impalad_coord_exec/Dockerfile
@@ -15,7 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
-FROM impala_base
+ARG BASE_IMAGE=impala_base
+FROM ${BASE_IMAGE}
 
 # Externally-facing ports
 # Beeswax
diff --git a/docker/impalad_coordinator/Dockerfile b/docker/impalad_coordinator/Dockerfile
index 8251659..b12814d 100644
--- a/docker/impalad_coordinator/Dockerfile
+++ b/docker/impalad_coordinator/Dockerfile
@@ -15,7 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
-FROM impala_base
+ARG BASE_IMAGE=impala_base
+FROM ${BASE_IMAGE}
 
 # Externally-facing ports
 # Beeswax
diff --git a/docker/impalad_executor/Dockerfile b/docker/impalad_executor/Dockerfile
index a3fab6a..3b1c309 100644
--- a/docker/impalad_executor/Dockerfile
+++ b/docker/impalad_executor/Dockerfile
@@ -15,7 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
-FROM impala_base
+ARG BASE_IMAGE=impala_base
+FROM ${BASE_IMAGE}
 
 # Externally-facing ports
 # Debug webserver
diff --git a/docker/setup_build_context.py b/docker/setup_build_context.py
index 47d630a..8e5ea1a 100755
--- a/docker/setup_build_context.py
+++ b/docker/setup_build_context.py
@@ -20,13 +20,23 @@
 # Most artifacts are symlinked so need to be dereferenced (e.g. with tar -h) before
 # being used as a build context.
 
+import argparse
 import glob
 import os
 import shutil
 from subprocess import check_call
 
+parser = argparse.ArgumentParser()
+parser.add_argument("--debug-build", help="Setup build context for debug build",
+                    action="store_true")
+args = parser.parse_args()
+
 IMPALA_HOME = os.environ["IMPALA_HOME"]
-OUTPUT_DIR = os.path.join(IMPALA_HOME, "docker/build_context")
+if args.debug_build:
+  BUILD_TYPE = "debug"
+else:
+  BUILD_TYPE = "release"
+OUTPUT_DIR = os.path.join(IMPALA_HOME, "docker/build_context", BUILD_TYPE)
 DOCKERFILE = os.path.join(IMPALA_HOME, "docker/impala_base/Dockerfile")
 
 IMPALA_TOOLCHAIN = os.environ["IMPALA_TOOLCHAIN"]
@@ -59,9 +69,15 @@ def symlink_file_into_dir(src_file, dst_dir):
 
 
 # Impala binaries and native dependencies.
-check_call([STRIP, "--strip-debug",
-            os.path.join(IMPALA_HOME, "be/build/latest/service/impalad"),
-            "-o", os.path.join(BIN_DIR, "impalad")])
+
+# Strip debug symbols from release build to reduce image size. Keep them for
+# debug build.
+IMPALAD_BINARY = os.path.join(IMPALA_HOME, "be/build", BUILD_TYPE, "service/impalad")
+if args.debug_build:
+  symlink_file_into_dir(IMPALAD_BINARY, BIN_DIR)
+else:
+  check_call([STRIP, "--strip-debug", IMPALAD_BINARY,
+              "-o", os.path.join(BIN_DIR, "impalad")])
 for lib in ["libstdc++", "libgcc"]:
   for so in glob.glob(os.path.join(GCC_HOME, "lib64/{0}*.so*".format(lib))):
     symlink_file_into_dir(so, LIB_DIR)
diff --git a/docker/statestored/Dockerfile b/docker/statestored/Dockerfile
index 8149457..5eb2746 100644
--- a/docker/statestored/Dockerfile
+++ b/docker/statestored/Dockerfile
@@ -15,7 +15,8 @@
 # specific language governing permissions and limitations
 # under the License.
 
-FROM impala_base
+ARG BASE_IMAGE=impala_base
+FROM ${BASE_IMAGE}
 
 # Externally-facing ports
 # Debug webserver