From 3c3f15cd2c1948ee59ef76947d97c0bd37941a0f Mon Sep 17 00:00:00 2001
From: Andre Anjos <andre.anjos@idiap.ch>
Date: Tue, 13 Jun 2017 17:38:07 +0200
Subject: [PATCH] Mitigate effects of #51 by erasing cloned environments after
 every stage

---
 gitlab/after_build.sh   |  6 +++++-
 gitlab/after_deploy.sh  |  6 +++++-
 gitlab/after_test.sh    |  6 +++++-
 gitlab/before_build.sh  | 10 +---------
 gitlab/before_deploy.sh |  2 +-
 gitlab/before_test.sh   |  2 +-
 gitlab/functions.sh     | 12 +++++++++++-
 7 files changed, 29 insertions(+), 15 deletions(-)

diff --git a/gitlab/after_build.sh b/gitlab/after_build.sh
index 45a69db..ad30ed8 100755
--- a/gitlab/after_build.sh
+++ b/gitlab/after_build.sh
@@ -1,2 +1,6 @@
 #!/usr/bin/env bash
-# Sat 24 Sep 08:12:24 2016 CEST
+# Tue 13 Jun 2017 17:32:07 CEST
+
+source $(dirname ${0})/functions.sh
+
+run_cmd rm -rf ${PREFIX}
diff --git a/gitlab/after_deploy.sh b/gitlab/after_deploy.sh
index 8a57965..445b812 100755
--- a/gitlab/after_deploy.sh
+++ b/gitlab/after_deploy.sh
@@ -1,2 +1,6 @@
 #!/usr/bin/env bash
-# Thu 22 Sep 2016 15:11:53 CEST
+# Tue 13 Jun 2017 17:32:29 CEST
+
+source $(dirname ${0})/functions.sh
+
+run_cmd rm -rf ${PREFIX}
diff --git a/gitlab/after_test.sh b/gitlab/after_test.sh
index 9f03f60..6199987 100755
--- a/gitlab/after_test.sh
+++ b/gitlab/after_test.sh
@@ -1,2 +1,6 @@
 #!/usr/bin/env bash
-# Thu 22 Sep 2016 13:59:03 CEST
+# Tue 13 Jun 2017 17:32:16 CEST
+
+source $(dirname ${0})/functions.sh
+
+run_cmd rm -rf ${PREFIX}
diff --git a/gitlab/before_build.sh b/gitlab/before_build.sh
index bdfac70..22e8b1e 100755
--- a/gitlab/before_build.sh
+++ b/gitlab/before_build.sh
@@ -10,15 +10,7 @@ if [ -z "${WHEELS_REPOSITORY}" ]; then
 fi
 check_env WHEELS_REPOSITORY
 
-# Readies a conda environment to use for installation
-if [ ! -d ${PREFIX} ]; then
-  log_info "Creating conda installation at ${PREFIX}..."
-  run_cmd ${CONDA_FOLDER}/bin/conda create --clone ${CONDA_ENV} --prefix ${PREFIX} --yes
-else
-  log_info "Prefix directory ${PREFIX} exists, not re-installing..."
-fi
-
-prepare_build_env ${CONDA_FOLDER} ${PREFIX}
+prepare_build_env ${CONDA_FOLDER} ${PREFIX} ${CONDA_ENV}
 
 # Verify where pip is installed
 use_pip=`which pip`
diff --git a/gitlab/before_deploy.sh b/gitlab/before_deploy.sh
index 895ac54..9c68a4f 100755
--- a/gitlab/before_deploy.sh
+++ b/gitlab/before_deploy.sh
@@ -5,7 +5,7 @@ source $(dirname ${0})/functions.sh
 
 run_cmd $(dirname ${0})/before_test.sh
 
-prepare_build_env ${CONDA_FOLDER} ${PREFIX}
+prepare_build_env ${CONDA_FOLDER} ${PREFIX} ${CONDA_ENV}
 
 # setup database locally and run `bob_dbmanage.py all download`
 # if this is a database package - need auxiliary file for package
diff --git a/gitlab/before_test.sh b/gitlab/before_test.sh
index 165784e..b588c13 100755
--- a/gitlab/before_test.sh
+++ b/gitlab/before_test.sh
@@ -5,7 +5,7 @@ source $(dirname ${0})/functions.sh
 
 run_cmd $(dirname ${0})/before_build.sh
 
-prepare_build_env ${CONDA_FOLDER} ${PREFIX}
+prepare_build_env ${CONDA_FOLDER} ${PREFIX} ${CONDA_ENV}
 
 # Verify where pip is installed
 use_pip=`which pip`
diff --git a/gitlab/functions.sh b/gitlab/functions.sh
index 8b68c94..357c791 100644
--- a/gitlab/functions.sh
+++ b/gitlab/functions.sh
@@ -184,10 +184,20 @@ dav_upload() {
 }
 
 
-# Activates environment and sets up compilation
+# Creates (clones), Activates environment and sets up compilation
 # $1: root of the conda installation
 # $2: your current build prefix
+# $3: the name of the conda environment to clone
 prepare_build_env() {
+
+  # Readies a conda environment to use for installation
+  if [ ! -d $2 ]; then
+    log_info "Creating conda installation at $2..."
+    run_cmd $1/bin/conda create --clone $3 --prefix $2 --yes
+  else
+    log_info "Prefix directory $2 exists, not re-installing..."
+  fi
+
   # Activates conda environment for the build
   log_info "$ source $1/bin/activate $2"
   source $1/bin/activate $2
-- 
GitLab