Skip to content

Instantly share code, notes, and snippets.

@lrhache
Created December 11, 2013 15:21
Show Gist options
  • Save lrhache/7912248 to your computer and use it in GitHub Desktop.
Save lrhache/7912248 to your computer and use it in GitHub Desktop.
Easy way to batch set Heroku config from a file. No one wants to do this manually(!?).

#Heroku set configs from files

  • Export your configs from Heroku in "shell" format to file:

    $ heroku config -a <app_name> -s > .env-<environment_name(production, staging, ...)>
    
  • Copy this script to a file

    #!/bin/bash
    ESC_SEQ="\x1b["
    COL_RESET=$ESC_SEQ"39;49;00m"
    COL_GREEN=$ESC_SEQ"32;01m"
    COL_MAGENTA=$ESC_SEQ"35;01m"
    COL_RED=$ESC_SEQ"31;01m"
    
    script=`basename $0`
    
    if [ $# -ne 2 ]
    then
        echo -e $COL_RED"Usage: $script config_env_name heroku_app"$COL_RESET
    else
        echo -e $COL_GREEN"Setting up env:$1 on heroku:$2"$COL_RESET
        vars=$(cat .env-$1)
        command="heroku config:set $vars -a $2"
    
        echo $command
        eval $command
    fi
  • Run it!

    $ ./heroku-vars <environment_name(production, staging, ...)> <app_name>
    

###Note Make sure you double quote any spaced values in the config files. Heroku don't double quote those param values and will create an error when you try to run this script.

If you have a fix for this, post it below!

@tastycode
Copy link

If you have your envvars already in a .env file, you can just use cat .env | xargs heroku config:set

@bright-nwokoro
Copy link

If you have your envvars already in a .env file, you can just use cat .env | xargs heroku config:set

Haha, this happens to be useful 4 years later

@MrAzuka
Copy link

MrAzuka commented Jul 15, 2022

If you have your envvars already in a .env file, you can just use cat .env | xargs heroku config:set

Thank you. Still works

@andychongyz
Copy link

If you have your envvars already in a .env file, you can just use cat .env | xargs heroku config:set

Works! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment