Been using doppler for a while and I was wondering if there is a way to load the secrets into the shell. Right now, I find it really annoying having to type
doppler run -- npm test or any other command. One alternative would be to create a multiple npm scripts such as
npm test and
npm ci:test. However managing this gets harder when you have more and more scripts. I was wondering if the following was possible:
- Only have one set of scripts (test, dev, start, etc)
- When I CD into my local development environment, I run a single command which loads the latest env variables and sources them.
- On CI, doppler syncs the env variables so there is no need to use the doppler command there
- On prod, same as step 3
We actually have a small section in the docs that discusses this here:
Essentially, you can either create a new shell that was executed via
doppler run OR you could setup a script that does this:
source <(doppler secrets download --no-file --format env)
set -a causes each variable or function that’s defined to be given the export attribute. So, you could have a
pull-env-secrets.sh script that you run in a new shell session that sets all your variables for you.
Would that do what you’re after?
Perfect, thats exactly what I was looking for!
Is there a different way to do this with
sh? I added
"load": "set -a && source <(doppler secrets download --no-file --format env) && set +a" to my package.json but I get an error saying:
sh: syntax error near unexpected token `('
sh-3.2$ set -a && source <(doppler secrets download --no-file --format env) && set +a
There is but I would strongly advise against it because the bourne shell (
sh) doesn’t support process substitution (the
<() syntax), therefore the secrets would have to be saved to disk and executed in the context of the current shell using the
. .env form.
Can you instead install
If not, below is how you could achieve it:
doppler secrets download --no-file --format env > .env
I was actually just playing around with this and you might be able to get what you’re after by simply doing this:
export $(doppler secrets download --no-file --format env-no-quotes)
set -a or
set +a required.
@watsonian Yep, I was the one that emailed you the code for dotenv
One caveat to the
export $(...) form is that it will fail if there is a space in a secret’s value.