Change image build logic

  * Implement pre-build.sh
    Due our CI strategy, its kinda hard to fetch all resources
    during docker build stage.
    split logic to:
    pre-build.sh - script, will be ran by jenkins,
      with ssh-agent wrapper
    extra/build.sh - script, will be ran during docker build
  * Merge RUN into one step, to reduce layer amount
  * Fix 'tempest' dependency - always isntall from local
    copy

Revert "Add authorization for gerrit repositories"
This reverts commit 920ac7ce0c2b9a67bdc9186cd5e75b0b2b93ed22.

Change-Id: I2edf0c6e337eef21b8f8f1d6c2f1636ccde60932
diff --git a/extra/pre-build.sh b/extra/pre-build.sh
new file mode 100755
index 0000000..ed1748b
--- /dev/null
+++ b/extra/pre-build.sh
@@ -0,0 +1,135 @@
+#!/bin/bash
+
+set -ex
+
+export GERRIT_NAME=${GERRIT_NAME:-mcp-jenkins}
+# Would delete all .git folders.
+# Keep in mind, you would not able to get any other version or history!
+# Will ignore 'tempest' itself bz of:
+# ```
+#   Exception: Versioning for this project requires either an sdist tarball, or access to an upstream git repository.
+#   It's also possible that there is a mismatch between the package name in setup.cfg and the argument given to pbr.version.VersionInfo.
+#   Project name tempest was given, but was not able to be found.
+# ```
+# FIXME|TODO Disabled by default.
+# Currently, pip not able to install any package w\o .git directory.
+# Should it be re-writed to tgz install or whatever?
+#export RELEASE_BUILD=${RELEASE_BUILD:-true}
+RELEASE_BUILD=false
+#
+export TEMPEST_TAG="${TEMPEST_TAG:-mcp/pike}"
+export HORIZON_TAG="${HORIZON_TAG:-mcp/pike}"
+export BARBICAN_TAG="${BARBICAN_TAG:-mcp/pike}"
+export DESIGNATE_TAG="${DESIGNATE_TAG:-mcp/pike}"
+export HEAT_TAG="${HEAT_TAG:-mcp/pike}"
+export IRONIC_TAG="${IRONIC_TAG:-mcp/pike}"
+export MANILA_TAG="${MANILA_TAG:-mcp/pike}"
+export TELEMETRY_TAG="${TELEMETRY_TAG:-mcp/pike}"
+export OCTAVIA_TAG="${OCTAVIA_TAG:-mcp/pike}"
+export PATROLE_TAG="${PATROLE_TAG:-0.4.x}"
+export TUNGSTEN_TAG="${TUNGSTEN_TAG:-0.1.x}"
+# global openstack requirements repo
+# This is the commit where tempest version is 17.2.0 in u-c
+export UPPER_CONSTRAINTS_TAG="${UPPER_CONSTRAINTS_TAG:-83b1de74834fbcdbe749e270c29e76cdc28f85d5}"
+
+function prepare(){
+  # TODO migrate to downstrem mirror?
+  mkdir -p data; pushd data
+    if [ ! -d openstack_requirements ] ; then
+      git clone https://github.com/openstack/requirements.git openstack_requirements
+      pushd openstack_requirements; git checkout $UPPER_CONSTRAINTS_TAG; popd
+    fi
+    sed -i -e "s|tempest=.*|git+file:///var/lib/tempest@${TEMPEST_TAG}#egg=tempest|g" \
+    openstack_requirements/upper-constraints.txt;
+  #
+    if [ ! -d tempest-horizon-plugin ] ; then
+      git clone ssh://${GERRIT_NAME}@gerrit.mcp.mirantis.com:29418/packaging/sources/tempest-horizon tempest-horizon-plugin
+      pushd tempest-horizon-plugin ; git checkout $HORIZON_TAG; popd
+    fi
+  #
+    if [ ! -d barbican-tempest-plugin ] ; then
+      git clone ssh://${GERRIT_NAME}@gerrit.mcp.mirantis.com:29418/packaging/sources/barbican-tempest-plugin
+      pushd barbican-tempest-plugin; git checkout $BARBICAN_TAG; popd
+    fi
+  #
+    if [ ! -d designate-tempest-plugin ] ; then
+      git clone ssh://${GERRIT_NAME}@gerrit.mcp.mirantis.com:29418/packaging/sources/designate-tempest-plugin
+      pushd designate-tempest-plugin; git checkout $DESIGNATE_TAG; popd;
+    fi
+  #
+    if [ ! -d heat-tempest-plugin ] ; then
+      git clone ssh://${GERRIT_NAME}@gerrit.mcp.mirantis.com:29418/packaging/sources/heat-tempest-plugin
+      pushd heat-tempest-plugin; git checkout $HEAT_TAG; popd
+    fi
+  #
+    if [ ! -d ironic-tempest-plugin ] ; then
+      git clone ssh://${GERRIT_NAME}@gerrit.mcp.mirantis.com:29418/packaging/sources/ironic-tempest-plugin
+      pushd ironic-tempest-plugin; git checkout $IRONIC_TAG;  popd;
+    fi
+  #
+    if [ ! -d manila-tempest-plugin ] ; then
+      git clone ssh://${GERRIT_NAME}@gerrit.mcp.mirantis.com:29418/packaging/sources/manila-tempest-plugin
+      pushd manila-tempest-plugin; git checkout $MANILA_TAG; popd;
+    fi
+  #
+    if [ ! -d telemetry-tempest-plugin ] ; then
+      git clone ssh://${GERRIT_NAME}@gerrit.mcp.mirantis.com:29418/packaging/sources/telemetry-tempest-plugin
+      pushd telemetry-tempest-plugin; git checkout $TELEMETRY_TAG; popd;
+    fi
+  #
+    if [ ! -d octavia-tempest-plugin ] ; then
+      git clone ssh://${GERRIT_NAME}@gerrit.mcp.mirantis.com:29418/packaging/sources/octavia-tempest-plugin
+      pushd octavia-tempest-plugin; git checkout $OCTAVIA_TAG; popd;
+    fi
+  #
+    if [ ! -d patrole-tempest-plugin ] ; then
+      git clone ssh://${GERRIT_NAME}@gerrit.mcp.mirantis.com:29418/packaging/sources/patrole patrole-tempest-plugin
+      pushd patrole-tempest-plugin; git checkout $PATROLE_TAG; popd;
+    fi
+  #
+    if [ ! -d tungsten-tempest-plugin ] ; then
+      git clone ssh://${GERRIT_NAME}@gerrit.mcp.mirantis.com:29418/contrail/tungsten-tempest tungsten-tempest-plugin
+      pushd tungsten-tempest-plugin; git checkout $TUNGSTEN_TAG; popd;
+    fi
+  #
+    if [ ! -d tempest ] ; then
+      git clone ssh://${GERRIT_NAME}@gerrit.mcp.mirantis.com:29418/packaging/sources/tempest tempest
+      pushd tempest ; git checkout $TEMPEST_TAG; popd
+    fi
+  #
+    if [[ "$(echo ${RELEASE_BUILD} | tr [:upper:] [:lower:] )" == "true" ]]; then
+      find . -maxdepth 2 -type d -iname .git -not -path '*tempest/.git*' | xargs --no-run-if-empty rm -rf
+      find . -maxdepth 2 -type f -iname .gitignore -or -iname .gitreview | xargs --no-run-if-empty rm -v
+    fi
+  popd
+  }
+
+function buildme(){
+  echo "=== Installing plugins"
+  plugins="tempest-horizon-plugin barbican-tempest-plugin designate-tempest-plugin heat-tempest-plugin ironic-tempest-plugin"
+  plugins="${plugins} manila-tempest-plugin telemetry-tempest-plugin octavia-tempest-plugin patrole-tempest-plugin tungsten-tempest-plugin"
+  for plugin in ${plugins}; do
+    echo "=== Installing plugin: ${plugin}"
+    pushd /var/lib/${plugin}
+      pip install --constraint /var/lib/openstack_requirements/upper-constraints.txt -r requirements.txt .
+    popd
+  done
+  echo "=== Installing tempest itself"
+  pushd /var/lib/tempest/
+    pip install .
+  popd
+  pip install junitxml
+  echo "BUILD_TIMESTAMP=$(date '+%Y-%m-%d-%H-%M-%S' -u)" > /etc/build_timestamp
+}
+
+############# body ############################################################
+
+case "$1" in
+
+buildme)  echo "Attempt to buildme"
+   buildme
+   ;;
+*) echo "Attempt to prepare.."
+   prepare
+   ;;
+esac