Using conda with gitlab CI

Now with 100% more conda

As I described some weeks ago, I started using GitlabCI for one of my projects. Then I used pip to manage the environment for testing. Since I prefer conda to manage my environments, I tried to replace pip. Following a blog entry by Benjamin Bertrand I modified my dummy repository to work with conda.

What you need to change

The basic setup stays the same as described in the old entry. You will need to modify the .gitlab-ci.yaml file to work with conda and install some additional requirements and replace the pip-flavour requirements.txt with a conda environment.yaml.

New .gitlab-ci.yaml

This is the new file:

image: continuumio/miniconda3:latest

unittests:
  script:
    - apt-get update -q -y
    - apt-get install -y build-essential
    - conda env create -f environment.yaml
    - source activate myenv
    - nosetests -v --nocapture

Most prominently, I replaced the docker image with a miniconda3 image. Since I do not need specific images per test (yet), I use a global image.

To use conda, the build-essential package should be installed, since some packages need to be compiled. The -y parameter answers all upcoming questions regarding the installation with yes.

The conda env create step builds an environment as described by the environment file (see below). The name of the environment is contained in the environment file as well. The following step activates the environment myenv.

The environment.yaml

name: myenv

dependencies:
  - python>=3.6
  - nose
  - numpy

This file defines the conda environment used to test our package and replaces pips requirements.txt. In addition to the list of packages it also contains the name of the environment,additional channels, etc. For example if you would like to use a package from bioconda, you would need to add the channel here.

name: myenv

channels:
 - bioconda
 - conda-forge
 - defaults

dependencies:
 - ...

If you want to install something that is not on conda, you can also include a list of packages to install from pip:

name: myenv

dependencies:
  - python>=3.6
  - nose
  - numpy
  - pip:
    - mmh3

Whats next?

I have not yet tried using different environments for different test etc. If I will ever need this, or any other interesting feature, I will continue to document this.

Links

Related

comments powered by Disqus