Devstack tips and tricks. General discussion

Most of our devstacks require setting a shell environment variable (or two) to get working properly. For example,

export OPENEDX_RELEASE=ironwood.master

It can be a hassle to make sure the right environment is set if you move between devstacks. One nice tool for managing this is direnv. If I have direnv installed, I can add a .envrc to each devstack directory to ensure the correct evironment is set when I enter the directory, and unset when
I leave it. For example,

# ~/OpenCraft/devstack-ironwood/devstack/.envrc
export OPENEDX_RELEASE=ironwood.master
export VIRTUAL_ENV=venv
layout python-venv

This ensures that when I enter ~/OpenCraft/devstack-ironwood/devstack/ OPENEDX_RELEASE and VIRTUAL_ENV are set appropriately. The last line also ensures the python virtual environment has been set up (which is a bonus). Checkout the direnv for appropriate shell integration and options for different types of virtual environments.

When I enter a directory controlled by direnv, I get an informative message:

~ $ cd ~/OpenCraft/devstack-ironwood/devstack
direnv: loading .envrc
direnv: export +OPENEDX_RELEASE +VIRTUAL_ENV ~PATH
(venv) ~/OpenCraft/devstack-ironwood/devstack $
(venv) ~ $ echo $OPENEDX_RELEASE
ironwood.master
(venv) ~ $

Similarly, when I leave:

(venv) ~/OpenCraft/devstack-ironwood/devstack $ cd ~
direnv: unloading
~ $ echo $OPENEDX_RELEASE

~$

In case you are worried about the security of this, note that adding or editing .envrc files requires approval:

$ vim .envrc
direnv: error .envrc is blocked. Run `direnv allow` to approve its content.
$
4 Likes