build-setup: Ensure we fail the build when a step fails

Currently the build step can fail inside docker but we don't propogate
that error up, so the Jenkins build will not be marked as failed.

We set the following options:

 set -xeuo pipefail

 - bash trace output (-x)
 - failing when a step fails (-e)
 - failing on undefined variables (-u)
 - failing when a command in a pipe fails (-o pipefail) - the default
 behaviour is to use the exit code of the final command in the pipe.

http://redsymbol.net/articles/unofficial-bash-strict-mode/

Thanks to Daniel Axtens <dja@axtens.net> for the extra suggestions.

Signed-off-by: Joel Stanley <joel@jms.id.au>
Reviewed-by: Daniel Axtens <dja@axtens.net>
diff --git a/build-setup.sh b/build-setup.sh
index c5159d3..d0a6fc2 100755
--- a/build-setup.sh
+++ b/build-setup.sh
@@ -7,8 +7,8 @@
 #   distro = fedora|ubuntu
 #   WORKSPACE = 
 
-# Trace bash processing
-set -x
+# Trace bash processing. Set -e so when a step fails, we fail the build
+set -xeuo pipefail
 
 # Default variables
 target=${target:-qemu}
@@ -86,10 +86,6 @@
 
 # Build the docker container
 docker build -t openbmc/${distro} - <<< "${Dockerfile}"
-if [[ "$?" -ne 0 ]]; then
-  echo "Failed to build docker container."
-  exit 1
-fi
 
 # Create the docker run script
 export PROXY_HOST=${http_proxy/#http*:\/\/}
@@ -101,7 +97,7 @@
 cat > "${WORKSPACE}"/build.sh << EOF_SCRIPT
 #!/bin/bash
 
-set -x
+set -xeuo pipefail
 
 cd ${WORKSPACE}