Prep the script for Kubernetes Integration.

Add the launch parameter, move the docker run command into an if
statement that checks for the launch type to be empty. Add git submodule
update to build.sh script. It seems it needs it to be able to
successfully build out of OpenBMC/QEMU repo.

Change-Id: I6f68f89812c7329c815822644e873245e1236355
Signed-off-by: Alanny Lopez <alanny.lopez@ibm.com>
diff --git a/qemu-build.sh b/qemu-build.sh
index 9c9dee6..92b7f97 100755
--- a/qemu-build.sh
+++ b/qemu-build.sh
@@ -8,49 +8,30 @@
 # Default variables
 WORKSPACE=${WORKSPACE:-${HOME}/${RANDOM}${RANDOM}}
 http_proxy=${http_proxy:-}
+launch=${launch:-}
 
 # Timestamp for job
 echo "Build started, $(date)"
 
-# Configure docker build
+# Setup Proxy
 if [[ -n "${http_proxy}" ]]; then
 PROXY="RUN echo \"Acquire::http::Proxy \\"\"${http_proxy}/\\"\";\" > /etc/apt/apt.conf.d/000apt-cacher-ng-proxy"
 fi
 
-Dockerfile=$(cat << EOF
-FROM ubuntu:16.04
+ARCH=$(uname -m)
 
-${PROXY}
-
-ENV DEBIAN_FRONTEND noninteractive
-RUN apt-get update && apt-get install -yy --no-install-recommends \
-    bison \
-    flex \
-    gcc \
-    git \
-    libc6-dev \
-    libfdt-dev \
-    libglib2.0-dev \
-    libpixman-1-dev \
-    make \
-    python-yaml \
-    python3-yaml
-
-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}
-
-USER ${USER}
-ENV HOME ${HOME}
-RUN /bin/bash
-EOF
-)
-
-# Build the docker container
-docker build -t qemu-build/ubuntu - <<< "${Dockerfile}"
-if [[ "$?" -ne 0 ]]; then
-  echo "Failed to build docker container."
-  exit 1
-fi
+# Determine the prefix of the Dockerfile's base image
+case ${ARCH} in
+  "ppc64le")
+    DOCKER_BASE="ppc64le/"
+    ;;
+  "x86_64")
+    DOCKER_BASE=""
+    ;;
+  *)
+    echo "Unsupported system architecture(${ARCH}) found for docker image"
+    exit 1
+esac
 
 # Create the docker run script
 export PROXY_HOST=${http_proxy/#http*:\/\/}
@@ -70,6 +51,7 @@
 
 # Go into the source directory (the script will put us in a build subdir)
 cd qemu
+git submodule update --init dtc
 # disable anything that requires us to pull in X
 ./configure \
     --target-list=arm-softmmu \
@@ -90,11 +72,55 @@
 
 chmod a+x ${WORKSPACE}/build.sh
 
-# Run the docker container, execute the build script we just built
-docker run \
-    --rm=true \
-    -e WORKSPACE=${WORKSPACE} \
-    -w "${HOME}" \
-    -v "${HOME}":"${HOME}" \
-    -t qemu-build/ubuntu \
-    ${WORKSPACE}/build.sh
+# Configure docker build
+Dockerfile=$(cat << EOF
+FROM ${DOCKER_BASE}ubuntu:16.04
+
+${PROXY}
+
+ENV DEBIAN_FRONTEND noninteractive
+RUN apt-get update && apt-get install -yy --no-install-recommends \
+    bison \
+    flex \
+    gcc \
+    git \
+    libc6-dev \
+    libfdt-dev \
+    libglib2.0-dev \
+    libpixman-1-dev \
+    make \
+    python-yaml \
+    python3-yaml
+
+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}
+USER ${USER}
+ENV HOME ${HOME}
+EOF
+)
+
+# Build the docker container
+imgname=${imgname:-qemu-build:${ARCH}}
+
+# If Launch is left empty will create a docker container
+if [[ "${launch}" == "" ]]; then
+
+  docker build -t ${imgname} - <<< "${Dockerfile}"
+  if [[ "$?" -ne 0 ]]; then
+    echo "Failed to build docker container."
+    exit 1
+  fi
+
+  docker run \
+      --rm=true \
+      -e WORKSPACE=${WORKSPACE} \
+      -w "${HOME}" \
+      -v "${HOME}":"${HOME}" \
+      -t ${imgname} \
+      ${WORKSPACE}/build.sh
+
+else
+  echo "Launch Parameter is invalid"
+fi
+
+