سؤال

To set config vars for a Heroku app, you do this:

$ heroku config:set GITHUB_USERNAME=joesmith

How would I set a config var with the contents of a file?

هل كانت مفيدة؟

المحلول

Take a look at the heroku-config plugin, which adds a heroku config:push command to push key-value pairs in a file named .env to the app.

It also has a heroku config:pull command to do the opposite and works very well with foreman for running the app locally with the config in .env.

https://github.com/xavdid/heroku-config

Example
heroku config:push --file=.env.production 

نصائح أخرى

I know this is too late but still it will be helpful for future users who land here.

I also wanted a quick solution to add variable to heroku app but copy-paste is so boring.. So wrote a script to read values from the .env file and set it at the requested app - all things passed as an option:

https://gist.github.com/md-farhan-memon/e90e30cc0d67d0a0cd7779d6adfe62d1

Usage

./bulk_add_heroku_config_variables.sh -f='/path/to/your/.environment/file' -s='bsc-server-name' -k='YOUR_CONFIG_KEY1 YOUR_CONFIG_KEY2'

A simple pure-python solution using honcho and invoke:

from honcho.environ import parse
from invoke import run

def push_env(file='.env'):
    """Push .env key/value pairs to heroku"""
    with open(file, 'r') as f:
        env = parse(f.read())
    cmd = 'heroku config:set ' + ' '.join(
        f'{key}={value}' for key, value in env.items())
    run(cmd)

The idea here is that you will get the same configuration as if you ran the project locally using honcho. Then I use invoke to run this task easily from the command line (using @task and c.run) but I've adapted it here to stand alone.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top