Giter Site home page Giter Site logo

suirotras / containerize-conda Goto Github PK

View Code? Open in Web Editor NEW

This project forked from grst/containerize-conda

0.0 0.0 0.0 20 KB

Turn an existing conda environment into a Singularity container

Shell 11.48% Python 80.50% Dockerfile 2.11% Singularity 5.91%

containerize-conda's Introduction

Containerize an existing conda environment

I use conda environments for working on data analysis projects. Sometimes I need to revert to install using pip or R's install.packages if a package is not on bioconda or conda-forge.

This makes it very hard to reproduce the environment, and therefore, the analysis, on another system. Even pure conda environments stored as an environment.yml file tend to break after a while.

Using the instructions below allows to package an existing environment into a Singularity container which should be more portable and can also easily be integrated into a fully reproducible data analysis workflow based on e.g. Nextflow.

Usage

usage: conda_to_singularity.py [-h] [--template TEMPLATE] CONDA_ENV OUTPUT_CONTAINER

Convert a conda env to a singularity container.

positional arguments:
  CONDA_ENV            Absolute path to the conda enviornment. Must be exactely the path as it shows up in `conda env list`, not a symbolic link to it, nor a realpath.
  OUTPUT_CONTAINER     Output path where the singularity container will be safed.

optional arguments:
  -h, --help           show this help message and exit
  --template TEMPLATE  Path to a Singularity template file. Must contain a `{conda_env}` placeholder. If not specified, uses the default template shipped with this script.

For example

conda_to_singularity.py /home/sturm/.conda/envs/whatever whatever.sif

By default, the image will be based on CentOS 7. If you want a different base image, you can modify Singularity.template, and specify it with the --template argument.

How it works

Conda envs cannot simply be "moved" as some paths are hardcoded into the environment. I previously applied conda-pack to solve this issue, which works fine in most cases but breaks in some (especially for old environments that have a long history of manually installing stuff through R or pip).

This is an other appraoch where the issue is solved by copying the conda environment with its full absolute path to the container and append a line to the Singularity environment file that activates the conda environment from that path once the container is started:

echo "source /opt/conda/bin/activate {conda_env}" >>$SINGULARITY_ENVIRONMENT

Naively, this could be solved with %files /path/to/env, however, this dereferences all symbolic links, which breaks some environments. Instead, I build a tar archive that keeps all symbolic links intact within the conda environment, but at the same time include all files that are outside the conda env, but referenced by a symbolic link.

I don't have a lot of experience yet if it is really more stable than conda-pack or just happens to fail in different cases.

Where's the conda-pack/Docker version?

This is an updated version of my scripts that works without conda-pack and turned out to work even in cases where the conda-pack variant failed. It works only with Singularity at the moment. I don't see any major issues porting the new approach to Docker, but don't have need for that myself.

If you are looking for the previous scripts based on conda-pack, because you need a Docker variant, or they just work for you, they are in the conda-pack folder with a dedicated README.

containerize-conda's People

Contributors

grst avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.