Last active
March 1, 2022 09:41
-
-
Save adrien2p/0d149db88c1aa7f22506a1c546388aa7 to your computer and use it in GitHub Desktop.
🔧 Add your env variables to your Heroku app smoothly 🚀
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
RED='\033[0;31m' | |
GREEN='\033[0;32m' | |
YELLOW='\033[0;33m' | |
BLUE='\033[0;34m' | |
NC='\033[0m' | |
usage=" | |
A quick script to add env variables to your heroku application. Following options are required: | |
-h, [--help] | show this help text | |
-f=, [--file=] | env file path | |
Sample command: ./$(basename "$0") -f='.env' | |
" | |
# Reading input options | |
for i in "$@"; do | |
case $i in | |
-f=*|--file=*) | |
FILE="${i#*=}" | |
;; | |
-h*|--help*) | |
printf "$usage" | |
exit 0 | |
;; | |
*) | |
# ignoring unknown option | |
;; | |
esac | |
done | |
# Check if -f option is present | |
if [ -z $FILE ] | |
then | |
echo -e "${YELLOW}--file${NC} ${RED}option missing${NC}. Use --help option to know the command\n" | |
exit 1 | |
fi | |
echo -e "\n${BLUE}---> Looking for your envs${NC}\n" | |
ENVS="" | |
while IFS='=' read key value; do | |
# Check that the key is not empty and that it does not start with "#" to avoid comment | |
if [[ ! -z "$key" && ! $key =~ ^#.* ]]; then | |
echo -e "$key=$value" | |
ENVS="$ENVS $key=$value" | |
fi | |
done < "$FILE" | |
echo -e "\n${BLUE}---> Set all env to the following app ${NC}\n" | |
heroku apps:info | |
echo -e "\n${BLUE}---> Setting up the envs ${NC}\n" | |
heroku config:set $ENVS |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@VxJasonxV Ill look into that and improve the script, thank you for your feedback, it is appreciated. 🚀