The easiest way to set Config Vars in Heroku
After deploying your app (Laravel or whatever) to heroku for the first time, you then start thinking of the time you have spend setting the config vars on heroku. No problem, of course, you can easily heroku config:set VAR_NAME=var_value
or even just got to your heroku dashboard and start entering your config vars and its values one by one.
But eh, you have 50 variables to set, but thank God you already have them in your local .env file, you then start your journey of 50-config-var-programming. You promised your boss you’d be done deploying the app in 7 minutes, YES, you’ve deployed the app to heroku in under just 5 minutes 💪, Cool eh 🆒, huh. Now, 15 minutes is gone, and you’re still setting variable number 26, and your boss be like: “Sdk, are you not getting it, or should we try another host ?” 🐵
That was my reality not long ago.
This post was inspired by 4 reasons:
0. it’s a sunday, and I felt like doing something different from my everyday php jobs
- I have not written python code in God knows how long
- I have not done any console app in forever (Console apps used to be very fun for me)
- I had to set config vars on heroku with a very strict deadline
So, there was no better way to spend my Sunday than do something that’d check all boxes above. I decided to write a python script that solves my problem.
Lol! Story story… e don do!!!
To cut the short story shorter, this is how to set config vars on heroku in a joy-giving manner:
Check out my repo at https://github.com/sdkcodes/heroku-config, then follow the README.md
Heroku Config
This python script helps you set all your heroku config vars directly from a .env file, instead of having to load them in one by one. This script works especially for laravel, but can be used for any other environment, all you just need do is to have a
.env
file, and have your variables set like APP_NAME=your_app_nameRequirements
python runtime (2.7+)
heroku toolbelt (CLI)
A project already connected to heroku
Installation and Usage
Clone or download this repo, then copy the
heroku-config.py
file into the root directory of your project (or wherever your .env file is located)Or download the
heroku-config.py
directly from git into the same location as your .env fileFrom the cmd,
cd
into the location of your .env file e.gcd C:/projects/your heroku project
Run
python heroku-config.py
. You should see your config vars getting set on after the otherThat’s all
Now you spend your time saving the world instead of setting Config Vars.
Don’t cringe at the code though, my python has gotten very rusty 😜, but hey, it works!
Use it, and let me know if there’s anything you’d want me to improve in it.