THRIFT-3718 Reduce size of docker image for build environment

This closes #931
diff --git a/build/docker/debian/Dockerfile b/build/docker/debian/Dockerfile
index a85d9e1..d8c2411 100644
--- a/build/docker/debian/Dockerfile
+++ b/build/docker/debian/Dockerfile
@@ -21,12 +21,15 @@
 ENV DEBIAN_FRONTEND noninteractive
 
 # General dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       apt-transport-https \
+      autoconf \
       automake \
       bison \
+      build-essential \
       clang \
       cmake \
+      curl \
       debhelper \
       flex \
       g++ \
@@ -36,7 +39,7 @@
       pkg-config
 
 # C++ dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       libboost-dev \
       libboost-filesystem-dev \
       libboost-program-options-dev \
@@ -44,12 +47,15 @@
       libboost-test-dev \
       libboost-thread-dev \
       libevent-dev \
-      libqt4-dev \
-      libssl-dev
+      libssl-dev \
+      qt5-default \
+      qtbase5-dev \
+      qtbase5-dev-tools
 
 # Java dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       ant \
+      ant-optional \
       openjdk-7-jdk \
       maven \
     && update-java-alternatives -s java-1.7.0-openjdk-amd64
@@ -68,13 +74,13 @@
       python3-pip
 
 # Ruby dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       ruby \
       ruby-dev \
     && gem install bundler rake
 
 # Perl dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       libbit-vector-perl \
       libclass-accessor-class-perl \
       libcrypt-ssleay-perl \
@@ -82,7 +88,7 @@
       libnet-ssleay-perl
 
 # Php dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       php5 \
       php5-dev \
       php5-cli \
@@ -91,10 +97,10 @@
       phpunit
 
 # GlibC dependencies
-RUN apt-get update && apt-get install -y libglib2.0-dev
+RUN apt-get update && apt-get install -y --no-install-recommends libglib2.0-dev
 
 # Erlang dependencies
-RUN  apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       erlang-base \
       erlang-eunit \
       erlang-dev \
@@ -112,31 +118,29 @@
       cabal-install
 
 # Haxe
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       neko \
       neko-dev \
       libneko0 \
-    && mkdir -p /tmp/haxe /usr/lib/haxe && \
-    curl http://haxe.org/website-content/downloads/3.2.0/downloads/haxe-3.2.0-linux64.tar.gz -o /tmp/haxe/haxe-3.2.0-linux64.tar.gz && \
-    tar -xvzf /tmp/haxe/haxe-3.2.0-linux64.tar.gz -C /usr/lib/haxe --strip-components=1 && \
+    && mkdir -p /usr/lib/haxe && \
+    curl http://haxe.org/website-content/downloads/3.2.0/downloads/haxe-3.2.0-linux64.tar.gz | \
+    tar -C /usr/lib/haxe --strip-components=1 -xz && \
     ln -s /usr/lib/haxe/haxe /usr/bin/haxe && \
     ln -s /usr/lib/haxe/haxelib /usr/bin/haxelib && \
     mkdir -p /usr/lib/haxe/lib  && \
     chmod -R 777 /usr/lib/haxe/lib && \
     haxelib setup /usr/lib/haxe/lib && \
-    haxelib install hxcpp && \
-    rm -rf /tmp/haxe
-
+    haxelib install hxcpp
 
 # Node.js dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       nodejs \
       nodejs-dev \
       nodejs-legacy \
       npm
 
 # CSharp dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       libmono-system-web2.0-cil \
       mono-complete \
       mono-devel \
@@ -161,16 +165,16 @@
 # Dart dependencies
 RUN curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
     curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list && \
-    apt-get update && apt-get install -y dart
+    apt-get update && apt-get install -y --no-install-recommends dart
 ENV PATH /usr/lib/dart/bin:$PATH
 
 # Lua dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       lua5.2 \
       lua5.2-dev
 
 # MinGW dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       mingw32 \
       mingw32-binutils \
 #      mingw32-runtime \
diff --git a/build/docker/scripts/cmake.sh b/build/docker/scripts/cmake.sh
index 21b7fc6..26ccb10 100755
--- a/build/docker/scripts/cmake.sh
+++ b/build/docker/scripts/cmake.sh
@@ -1,14 +1,22 @@
 #!/bin/sh
 set -ev
 
+CMAKE_FLAGS=$*
+MAKEPROG=make
+
+if ninja --version  >/dev/null 2>&1; then
+  MAKEPROG=ninja
+  CMAKE_FLAGS="-GNinja $CMAKE_FLAGS"
+fi
+
 mkdir -p cmake_build && cd cmake_build
-cmake $* ..
+cmake $CMAKE_FLAGS ..
 for LIB in $BUILD_LIBS; do
   if ! grep "^BUILD_${LIB}:BOOL=ON$" CMakeCache.txt ; then
     echo "failed to configure $LIB"
     exit 1
   fi
 done
-make -j3
+$MAKEPROG -j3
 cpack
 ctest -VV -E "(concurrency_test|processor_test)"
diff --git a/build/docker/ubuntu/Dockerfile b/build/docker/ubuntu/Dockerfile
index 5180fca..58a361c 100644
--- a/build/docker/ubuntu/Dockerfile
+++ b/build/docker/ubuntu/Dockerfile
@@ -21,22 +21,27 @@
 ENV DEBIAN_FRONTEND noninteractive
 
 # General dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       apt-transport-https \
+      autoconf \
       automake \
       bison \
+      build-essential \
       clang \
       cmake \
+      curl \
       debhelper \
       flex \
       g++ \
       git \
       libtool \
       make \
+      ninja-build \
       pkg-config
 
 # C++ dependencies
-RUN apt-get update && apt-get install -y \
+# libevent and OpenSSL are needed by D too
+RUN apt-get update && apt-get install -y --no-install-recommends \
       libboost-dev \
       libboost-filesystem-dev \
       libboost-program-options-dev \
@@ -44,17 +49,23 @@
       libboost-test-dev \
       libboost-thread-dev \
       libevent-dev \
-      libqt4-dev \
-      libssl-dev
+      libssl-dev \
+      qt5-default \
+      qtbase5-dev \
+      qtbase5-dev-tools
 
 # Java dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       ant \
+      ant-optional \
       openjdk-7-jdk \
       maven \
     && update-java-alternatives -s java-1.7.0-openjdk-amd64
 
 # Python dependencies
+# TODO:
+# Install twisted and zope.interface via pip. we need twisted at ./configure time, otherwise
+# py.twisted tests are skipped.
 RUN apt-get update && apt-get install -y --no-install-recommends \
       python-all \
       python-all-dbg \
@@ -68,13 +79,13 @@
       python3-pip
 
 # Ruby dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       ruby \
       ruby-dev \
     && gem install bundler rake
 
 # Perl dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       libbit-vector-perl \
       libclass-accessor-class-perl \
       libcrypt-ssleay-perl \
@@ -82,7 +93,7 @@
       libnet-ssleay-perl
 
 # Php dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       php5 \
       php5-dev \
       php5-cli \
@@ -91,12 +102,12 @@
       phpunit
 
 # GlibC dependencies
-RUN apt-get update && apt-get install -y libglib2.0-dev
+RUN apt-get update && apt-get install -y --no-install-recommends libglib2.0-dev
 
 # Erlang dependencies
 RUN echo 'deb http://packages.erlang-solutions.com/debian trusty contrib' > /etc/apt/sources.list.d/erlang_solutions.list && \
     curl -sSL http://packages.erlang-solutions.com/debian/erlang_solutions.asc | apt-key add - && \
-    apt-get update && apt-get install -y \
+    apt-get update && apt-get install -y --no-install-recommends \
       erlang-base \
       erlang-eunit \
       erlang-dev \
@@ -107,44 +118,42 @@
 RUN curl -sSL https://storage.googleapis.com/golang/go1.4.3.linux-amd64.tar.gz | tar -C /usr/local/ -xz
 ENV PATH /usr/local/go/bin:$PATH
 
-
 # Haskell dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       ghc \
-      cabal-install \
-      libghc-binary-dev \
-      libghc-network-dev \
-      libghc-http-dev \
-      libghc-hashable-dev \
-      libghc-unordered-containers-dev \
-      libghc-vector-dev
+      cabal-install
+# Packages tend to be overwritten by build process since we're currently calling cabal update
+#       libghc-binary-dev \
+#       libghc-network-dev \
+#       libghc-http-dev \
+#       libghc-hashable-dev \
+#       libghc-unordered-containers-dev \
+#       libghc-vector-dev
 
 # Haxe
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       neko \
       neko-dev \
       libneko0 \
-    && mkdir -p /tmp/haxe /usr/lib/haxe && \
-    curl http://haxe.org/website-content/downloads/3.2.0/downloads/haxe-3.2.0-linux64.tar.gz -o /tmp/haxe/haxe-3.2.0-linux64.tar.gz && \
-    tar -xvzf /tmp/haxe/haxe-3.2.0-linux64.tar.gz -C /usr/lib/haxe --strip-components=1 && \
+    && mkdir -p /usr/lib/haxe && \
+    curl http://haxe.org/website-content/downloads/3.2.0/downloads/haxe-3.2.0-linux64.tar.gz | \
+    tar -C /usr/lib/haxe --strip-components=1 -xz && \
     ln -s /usr/lib/haxe/haxe /usr/bin/haxe && \
     ln -s /usr/lib/haxe/haxelib /usr/bin/haxelib && \
     mkdir -p /usr/lib/haxe/lib  && \
     chmod -R 777 /usr/lib/haxe/lib && \
     haxelib setup /usr/lib/haxe/lib && \
-    haxelib install hxcpp && \
-    rm -rf /tmp/haxe
-
+    haxelib install hxcpp
 
 # Node.js dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       nodejs \
       nodejs-dev \
       nodejs-legacy \
       npm
 
 # CSharp dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       libmono-system-web2.0-cil \
       mono-complete \
       mono-devel \
@@ -169,16 +178,16 @@
 # Dart dependencies
 RUN curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && \
     curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list && \
-    apt-get update && apt-get install -y dart
+    apt-get update && apt-get install -y --no-install-recommends dart
 ENV PATH /usr/lib/dart/bin:$PATH
 
 # Lua dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       lua5.2 \
       lua5.2-dev
 
 # MinGW dependencies
-RUN apt-get update && apt-get install -y \
+RUN apt-get update && apt-get install -y --no-install-recommends \
       mingw32 \
       mingw32-binutils \
       mingw32-runtime \
diff --git a/debian/control b/debian/control
index 74cbb58..be5209c 100644
--- a/debian/control
+++ b/debian/control
@@ -5,14 +5,14 @@
     mono-devel,  libmono-system-web2.0-cil, erlang-base, ruby-dev | ruby1.9.1-dev, autoconf, automake,
     pkg-config, libtool, bison, flex, libboost-dev | libboost1.53-dev, python-all,
     python-all-dev, python-all-dbg, openjdk-6-jdk | java-sdk,
-    libboost-test-dev | libboost-test1.53-dev, libevent-dev, perl (>= 5.8.0-7),
-    php5, php5-dev, libglib2.0-dev, libqt4-dev
+    libboost-test-dev | libboost-test1.53-dev, libevent-dev, libssl-dev, perl (>= 5.8.0-7),
+    php5, php5-dev, libglib2.0-dev, qtbase5-dev, qtbase5-dev-tools
 Maintainer: Thrift Developer's <dev@thrift.apache.org>
 Homepage: http://thrift.apache.org/
 Vcs-Git: https://git-wip-us.apache.org/repos/asf/thrift.git
 Vcs-Browser: https://git-wip-us.apache.org/repos/asf?p=thrift.git
 Standards-Version: 3.9.5
-X-Python-Version: >= 2.7
+X-Python-Version: >= 2.6
 
 Package: thrift-compiler
 Architecture: any