Search code examples
yamlenvironment-variablesconda

Conda env yaml use environment variables for secrets


I have a project where I have to mix conda dependencies that are publicly available with dependencies from my own private pip package registry. These are all pip dependencies. It is possible to define a pip dependency like this in the env.yml file:

name: env-name
channels:
  - anaconda
  - conda-forge
  - defaults
dependencies:
  - conda-dependency=1.0.0=s0mel3tters

  - pip:
      - --extra-index-url https://__token_name__:__token__@gitlab.com/path/to/registry
      - pippackage==1.0.0

This works. Great. But. I don't want to check my __token_name__ and __token__ in source control for obvious reasons. Now it turns out that I can define environment variables into the env.yml that will be created in the actual environment. I want to do something slightly different. I want to read in an environmental variable that already exists and use it in my pip URL definition. Is this possible? If so, how?


Solution

  • Apparently, you can substitute for environmental variables:

    name: env-name
    channels:
      - anaconda
      - conda-forge
      - defaults
    dependencies:
      - conda-dependency=1.0.0=s0mel3tters
    
      - pip:
          - --extra-index-url https://${TOKEN_NAME}:${TOKEN}@gitlab.com/path/to/registry
          - pippackage==1.0.0