Q:

Caching virtual environment for gitlab-ci

I cached Pip packages using a Gitlab CI script, so that's not an issue.
Now I also want to catch a Conda virtual environment, because it reduces time to setup the environment.
I cached a virtual environment. Unfortunately it takes a long time at the end to cache all the venv files.
I tried to cache only the $CI_PROJECT_DIR/myenv/lib/python3.6/site-packages folder and it seems to reduce run time of the pipe.
My question is: am I doing it correctly?
The script is given below:
gitlab-ci.yml
image: continuumio/miniconda3:latest

cache:
  paths:
    - .pip
    - ls -l $CI_PROJECT_DIR/myvenv/lib/python3.6/site-packages
    - $CI_PROJECT_DIR/myvenv/lib/python3.6/site-packages

before_script:
  - chmod +x gitlab-ci.sh
  - ./gitlab-ci.sh

stages:
  - test

test:
  stage: test
  script:
    - python eval.py

gitlab-ci.sh
#!/usr/bin/env bash
ENV_NAME=myenv
ENV_REQUIREMENTS=requirements.txt

if [ ! -d $ENV_NAME ]; then
    echo "Environment $ENV_NAME does not exist. Creating it now!"
    conda create --path --prefix "$CI_PROJECT_DIR/$ENV_NAME"
fi

echo "Activating environment: $CI_PROJECT_DIR/$ENV_NAME"
source activate "$CI_PROJECT_DIR/$ENV_NAME"

echo "Installing PIP"
conda install -y pip

echo "PIP: installing required packages"
echo `which pip`
pip --cache-dir=.pip install -r "$ENV_REQUIREMENTS"

A:

Reusing pip cache between builds is a very good idea but doing the same for the virtualenvs is a really bad idea.
This is because virtualenv can easily become messed in a way that you cannot really detect at runtime. This not only happens, it happens more often than you could imagine and for that reason please avoid it.
PS. Advise from someone that learnt that the hard way.

