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.

Environment variables in config file

See original GitHub issue

I have separate config json files for dev and prod, using the format

{
    "user": USER,
    "password": PASSWORD,
    "database": DATABASE_NAME
}

Using the command db-migrate up --config config/production.json -e prod how would I reference USER and PASSWORD from production.json in my database.json config file?

<bountysource-plugin>

Want to back this issue? Post a bounty on it! We accept bounties via Bountysource. </bountysource-plugin>

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
wzrdtalescommented, May 26, 2015

@TGOlson Great to see, you have found a way that works for you and your team.

From what you’ve done I think, it would help to add a method to the programable API (there is no such API yet, but v0.10.x introduce one) that specifies a config object directly instead of parsing a file? In v0.10.x things like you have done now, are much easier, as there finally an API gets introduced that is made for the purpose of using db-migrate within another node.js module or in some automation.

Details about this are about to be documented soon, since yet there is only the instruction about the call convention over a singleton. http://db-migrate.readthedocs.org/en/latest/API/programable/

1reaction
TGOlsoncommented, May 26, 2015

Hey fellas,

Just swinging by to say we solved our problem by wrapping calls to db-migrate in our build tool, Gulp. We basically load our own internal config, and then provide the environment specific db url to db-migrate. Something like this:

var config = require('../server/config');

var DB_MIGRATE_COMMAND = 'DATABASE_URL=' + config.db + ' ./node_modules/.bin/db-migrate';

gulp.task('migrate', shell.task(DB_MIGRATE_COMMAND));

I omitted some setup code for brevity (if anyone wants the full solution I’d be happy to provide it). We do a little more work to wrap the tasks so you can provide options, like up --count 2, etc., but in general this has worked very well, without having to do much code/data duplication.

Edit: in case it’s not clear, the DATABASE_URL environment variable is a variable that can be provided to db-migrate. If you provide this variable, you can omit using a database.json config file. (It’s not documented very well in the docs).

Read more comments on GitHub >

github_iconTop Results From Across the Web

Use environment variables in the configuration - Elastic
You can use environment variable references in the config file to set values that need to be configurable during deployment. To do this,...
Read more >
Using variables in configuration files - IBM
Specify a variable in the bootstrap. · Use a defined variable in the configuration. · Use variable element in the configuration. · Use...
Read more >
Application configs: files or environment variables? Actually ...
Environment variables are set by who's responsible for the deployment environment: by developer on local machines, by SRE/Administrator/DevOps ...
Read more >
Want to use env variables in that config file? Well, you can ...
Meet the envsubst command​​ With envsubst we can embed the value of environment variables inside a string that comes from the standard input....
Read more >
Using Environment Variables in Nginx Config File - Baeldung
envsubst is a tool that we can use to generate an Nginx config file dynamically before the server starts. It replaces variables in...
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