question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

hi @jezdez, this may be completely out of scope as the project is literally named envdir, but I was wondering if its possible to provide a single file with all of the variables for each environment. so like:

prod
  - .env
dev
  - .env

this is mainly because I run programs both locally and with docker and docker allows me to specify a --env argument with a single file of environment variables. this way I can use the same file of environment variables for locally running a program and docker

thanks!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
AlJohricommented, Sep 8, 2016

thanks @blueyed, that’s what I ended up doing

posting this here for the future:

The snippets below accomplished what I needed.

Load envs/local or .env into current shell:

if [ -d "envs/local" ]; then
    echo "sourcing envs/local directory..."
    for f in envs/local/*; do eval $(echo export $(basename $f)=$(cat $f)); done
elif [ -f ".env" ]; then
    echo "sourcing .env file..."
    export $(cat .env | grep -v "^#" | xargs)
fi

notes:

  • replacing eval with echo in the for loop can help create a real env file if one likes. Sourcing it into the current shell worked well enough for me.
  • this probably doesn’t work with multiline variables or maybe even variables with spaces or special characters. doesn’t apply for my usage right now
  • this will choke on .DS_Store files and other random artifacts in the folder

docker-compose using external environment variables instead of an env-file file

version: '2'
services:
  myservice:
    environment:
      DATABASE_URL: ${DATABASE_URL}
      DEBUG: ${DEBUG}

https://docs.docker.com/compose/environment-variables/#/substituting-environment-variables-in-compose-files

usage if env variables are loaded in current shell: docker-compose up myservice usage using envdir: envdir envs/local docker-compose up myservice

0reactions
AlJohricommented, Aug 8, 2017

haha thanks! that looks good, I’ll have to try that. not as great at the bashfu just yet 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Declare default environment variables in file
Compose supports declaring environment variables in an environment file. ... Environment variables defined in the .env file are not automatically visible ...
Read more >
.env file - IBM
env file lets you customize your individual working environment variables. Because the .env file is hidden, use the ls -a command to list...
Read more >
What is .env ? How to Set up and run a .env file in Node?
env file ? The dotenv package for handling environment variables is the most popular option in the Node.js community. You can create an.env...
Read more >
We need to talk about the .env | Platform.sh
env is a de facto standard for an ini-like file that contains fake environment variables. An application that supports .env files will, on...
Read more >
Using .env Files for Environment Variables in Python ...
A .env file is a text file containing key value pairs of all the environment variables required by your application. This file is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found