Create base build unit test docker script

Base script to configure and build a docker image for unit tests.
Created as a stand alone script to allow users to build a docker image
to interactively use to verify unit tests.

Change-Id: Iea15d8c57760376c2f905d7f889d9ea483f6b0ad
Signed-off-by: Matthew Barth <msbarth@us.ibm.com>
diff --git a/build-unit-test-docker.sh b/build-unit-test-docker.sh
new file mode 100755
index 0000000..0d0d2a8
--- /dev/null
+++ b/build-unit-test-docker.sh
@@ -0,0 +1,74 @@
+#!/bin/bash -xe
+#
+# Build the required docker image to run package unit tests
+#
+# Parameters:
+#   param1:  <optional, the name of the docker image to generate>
+#            default is openbmc/ubuntu-unit-test
+#   param2:  <optional, the distro to build a docker image against>
+#            default is ubuntu:latest
+
+set -uo pipefail
+
+DOCKER_IMG_NAME=${1:-"openbmc/ubuntu-unit-test"}
+DISTRO=${2:-"ubuntu:latest"}
+
+# Determine the architecture
+ARCH=$(uname -m)
+case ${ARCH} in
+    "ppc64le")
+        DOCKER_BASE="ppc64le/"
+        ;;
+    "x86_64")
+        DOCKER_BASE=""
+        ;;
+    *)
+        echo "Unsupported system architecture(${ARCH}) found for docker image"
+        exit 1
+esac
+
+################################# docker img # #################################
+# Create docker image that can run package unit tests
+if [[ "${DISTRO}" == "ubuntu"* ]]; then
+Dockerfile=$(cat << EOF
+FROM ${DOCKER_BASE}${DISTRO}
+
+ENV DEBIAN_FRONTEND noninteractive
+
+RUN apt-get update && apt-get install -yy \
+    gcc \
+    g++ \
+    libc6-dev \
+    libtool \
+    cmake \
+    python \
+    python-dev \
+    python-setuptools \
+    pkg-config \
+    autoconf \
+    libsystemd-dev \
+    sudo \
+    wget \
+    git
+
+RUN wget http://ftpmirror.gnu.org/autoconf-archive/autoconf-archive-2016.09.16.tar.xz
+RUN tar -xJf autoconf-archive-2016.09.16.tar.xz
+RUN cd autoconf-archive-2016.09.16 && ./configure --prefix=/usr && make && make install
+
+RUN wget https://github.com/google/googletest/archive/release-1.7.0.tar.gz
+RUN tar -xzf release-1.7.0.tar.gz
+RUN cd googletest-release-1.7.0 && cmake -DBUILD_SHARED_LIBS=ON . && make && \
+cp -a include/gtest /usr/include && \
+cp -a libgtest_main.so libgtest.so /usr/lib/
+
+RUN grep -q ${GROUPS} /etc/group || groupadd -g ${GROUPS} ${USER}
+RUN grep -q ${UID} /etc/passwd || useradd -d ${HOME} -m -u ${UID} -g ${GROUPS} ${USER}
+
+RUN /bin/bash
+EOF
+)
+fi
+################################# docker img # #################################
+
+# Build above image
+docker build -t ${DOCKER_IMG_NAME} - <<< "${Dockerfile}"