HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Environment variable names, when my development environment has multiple projects

Submitted by: @import:stackexchange-devops··
0
Viewed 0 times
projectsnamesenvironmenthasdevelopmentmultiplewhenvariable

Problem

The context is that I'm looking at doing staging/testing and production on a kubernetes cluster.

Where I might have some code that looks like this:

doSomething({
  username: process.env.DB_USERNAME,
  password: process.env.DB_PASSWORD
})


For my various kubernetes environments, this isn't going to be a problem, as those environment variables can be set specifically for the environment.

However, for my development environment, there's a good chance that I'm going to have multiple projects, (or even different images for the same project) that all have a environment variable named DB_URL.

One solution would be to just prefix all environment variables with MY_APPLICATION_NAME_.

Another would be not permanently set environment variables, but instead to just call a script that sets them when needed. But that sounds a little messy.

I'm wondering if there's a well established way that deals with this problem.

Solution

check out https://direnv.net/ it sets environment variables based on the directory you are in.

other options are:
1.docker-compose
2.plain bash to set the variables.
  1. bash source .env
  2. use prefixes but you would still need to set the environment you are in via an environment variable, so back to options 1-3.



if you are going to store passwords or keys in the env variables locally that are sensitive i.e not a localhost db pass, use a secrets manager like https://pkhub.io/usecases/environments, or you could script up something with aws' secrets manager

Context

StackExchange DevOps Q#5183, answer score: 1

Revisions (0)

No revisions yet.