Essential Heroku Commands for Java (Spring Boot) developers
This blog post captures the command used to create and configure java apps or spring boot apps deployed to Heroku Cloud. I use these commands in CI/CD deployment steps for continuous delivery and also to access the application's information from my local development machine.
These commands are tested with Heroku Client version: heroku/7.0.33 darwin-x64 node-v10.0.0
heroku auth:whoami
heroku auth:logout
export HEROKU_API_KEY=<<API Key from https://dashboard.heroku.com/account>>
heroku auth:whoami
# unset HEROKU_API_KEY environment variable to logout
unset HEROKU_API_KEY
# clear the history to clear the API Key
history -cw && cat /dev/null > ~/.bash_history
# for deployment script
export APP_NAME=app-name
isAppAlreadyCreated=$(heroku apps | grep -c $APP_NAME)
if [ $isAppAlreadyCreated -eq 0 ]
then
heroku apps:create --app $APP_NAME --region eu --no-remote
else
echo "An existing application found"
fi
heroku config --app app-name
# set a new variable
heroku config:set ENVIRONMENT_VARIABLE1="Some Value1" --app app-name
# unset an existing variable
heroku config:unset ENVIRONMENT_VARIABLE1 --app app-name
echo 'web: java -Dspring.profiles.active=live -Dserver.port=$PORT $JAVA_OPTS -jar target/my-app.jar' > Procfile
heroku deploy:jar --jar target/my-app.jar --app app-name --jdk 8
# for deployment script
export APP_NAME=app-name
isDomainAlreadyApplied=$(heroku domains --app $APP_NAME | grep -c "test.harishkannarao.com")
if [ $isDomainAlreadyApplied -eq 0 ]
then
heroku domains:add test.harishkannarao.com --app $APP_NAME
else
echo "Domain already applied"
fi
heroku certs:auto:enable --app app-name
heroku maintenance:off --app app-name
These commands are tested with Heroku Client version: heroku/7.0.33 darwin-x64 node-v10.0.0
View help
heroku helpLogin/Logout to heroku With email and password
heroku auth:loginheroku auth:whoami
heroku auth:logout
Login/Logout to heroku With token
# set HEROKU_API_KEY environment variable to loginexport HEROKU_API_KEY=<<API Key from https://dashboard.heroku.com/account>>
heroku auth:whoami
# unset HEROKU_API_KEY environment variable to logout
unset HEROKU_API_KEY
# clear the history to clear the API Key
history -cw && cat /dev/null > ~/.bash_history
Show available regions for deployment
heroku regions
Create an application
heroku apps:create --app app-name --region eu --no-remote# for deployment script
export APP_NAME=app-name
isAppAlreadyCreated=$(heroku apps | grep -c $APP_NAME)
if [ $isAppAlreadyCreated -eq 0 ]
then
heroku apps:create --app $APP_NAME --region eu --no-remote
else
echo "An existing application found"
fi
List applications
heroku apps
Display application's information
heroku apps:info --app app-name
Config variables (environment variable)
# list existing variablesheroku config --app app-name
# set a new variable
heroku config:set ENVIRONMENT_VARIABLE1="Some Value1" --app app-name
# unset an existing variable
heroku config:unset ENVIRONMENT_VARIABLE1 --app app-name
Deploy a spring boot jar file with system properties
heroku plugins:install heroku-cli-deployecho 'web: java -Dspring.profiles.active=live -Dserver.port=$PORT $JAVA_OPTS -jar target/my-app.jar' > Procfile
heroku deploy:jar --jar target/my-app.jar --app app-name --jdk 8
Open the application in browser
heroku apps:open --app app-nameAdd custom domain
heroku domains:add test.example.com --app app-name# for deployment script
export APP_NAME=app-name
isDomainAlreadyApplied=$(heroku domains --app $APP_NAME | grep -c "test.harishkannarao.com")
if [ $isDomainAlreadyApplied -eq 0 ]
then
heroku domains:add test.harishkannarao.com --app $APP_NAME
else
echo "Domain already applied"
fi
Upgrade to paid hobby plan and enable heroku SSL
heroku ps:resize web=hobby --app app-nameheroku certs:auto:enable --app app-name
Downgrade to free plan and disable SSL
heroku ps:resize web=free --app app-nameCheck the application logs
heroku logs --app app-name --tailList current scalability of an application
heroku ps:scale --app app-name
Stop or scale down an application
heroku ps:scale web=0 --app app-nameStart or scale up an application
heroku ps:scale web=1 --app app-nameRestart an application
heroku ps:restart --app app-namePut and resume an application to/from maintenance mode
heroku maintenance:on --app app-nameheroku maintenance:off --app app-name
Comments
Post a Comment