#env-var #configuration #environment #settings #sane #variables #manage

app activate

A sane way to manage environment-specific configurations

3 releases (breaking)

0.3.0 Feb 10, 2024
0.2.0 Feb 9, 2024
0.1.0 Feb 6, 2024

#58 in Configuration

MIT license

19KB
332 lines

activate

crates.io License: MIT Build Status

A sane way to manage environment-specific configurations. Simplify the way you work and build across various settings like Development, Testing, Production, and more.

Problem Statement

Code in different environments such as Dev, QA, Prod, etc. may need various configurations to run. The solution often used is loading environment variables or property files at build or run time. This by itself has a few drawbacks:

  • Setting up environments may take some additional imperative configuration or worse user setup.
  • Switching between environments is tedious.
  • Developers may have to maintain custom implementations and build scripts.
  • No good solution exists for switching entire mono-repos between environments.

Solution

activate solves all these problems.

  • Create an active.toml file and declaratively define your environments.
  • Loading and unloading an environment is as easy as activate <name> and deactivate with just activate.
  • No custom build scripts necessary, have per environment managed files/directories and environment variables.
  • Switch an entire mono-repo with activate -r <name>, all directories containing activate.toml are switched to <name>.

Example Use Cases

  1. You have assets, data files, executables, or program files that should be used in different environments like Dev, QA, etc. e.g.

    [dev.links]
    "app/data" = "path/to/dev/data"
    
    [qa.links]
    "app/data" = "path/to/qa/data"
    

    app/data is created and symlinked to the file or directory of the active environment.

  2. You want different environment variables in each environment e.g.

    [dev.env]
    HOST = "localhost"
    PORT = 3000
    
    [qa.env]
    HOST = "178.32.44.2"
    PORT = 443
    

    To load into your current shell run (this will also unload any activate environment).

    eval "$(activate -e <name>)"`
    

    Alternatively you can load the active .env file yourself or from an application, located at .activate/.env. This can also be useful for dev containers. Just add "runArgs": ["--env-file",".activate/.env"] to your .devcontainer/devcontainer.json file.

  3. You are using a mono-repo and want to switch everything to a certain environment. Run:

    activate -r <name>
    

    any directory/subdirecory (respecting .gitignore) with an activate.toml file is switched to <name>

activate.toml Schema

[<ENV_NAME>.env]
<ENV_VAR_NAME> = <ENV_VAR_VALUE>

[<ENV_NAME>.links]
"<LINK_PATH_FROM_ROOT>" = "<SOURCE_PATH_FROM_ROOT>"

Install

cargo install activate

ROADMAP

  • Allow activating multiple environments at the same time
  • Allow specifying environment entering and leaving scripts
  • Add defualt environment and shell hook

Dependencies

~6–8MB
~145K SLoC