Deploying to Heroku
This sub-generator allows deployment of your JHipster application to the Heroku cloud.
Heroku is helping JHipster in two ways:
- Joe Kutner, from Heroku, is currently maintaining this sub-generator
- Heroku gives us free credits, allowing us to test generated applications with complex, high-end setups, to guarantee everything works well for our common users
Running the sub-generator
Before running the sub-generator, you must install the Heroku CLI, and have a Heroku account created.
You must also create a Heroku account and log in with the CLI by running the following command:
**$ heroku login** Enter your Heroku credentials. Email: YOUR_EMAIL Password (typing will be hidden): YOUR_PASSWORD Authentication successful.
To deploy your application to Heroku, run this command:
jhipster heroku
This should package your application in “production” mode, create an Heroku application with a database, upload your code, and start the application.
Note that if your application is a microservice, you will be prompted to provide a registry URL. Scroll down to learn how to do this.
Please be aware that your application must start under 90 seconds, or it will be killed. Depending on the platform load, starting under 60 seconds is of course not guaranteed!
Updating your deployed application
Preparing a new deployment
When your application is already deployed, you can prepare a new deployment by typing:
./mvnw package -Pprod -DskipTests
Or when using gradle:
./gradlew -Pprod bootWar -x test
Pushing to production
_Note: This assumes you have run the generator on the machine you are executing this command from. If you have not, you will need to follow the instructions for installing the Heroku Java CLI.
To push to production, type:
heroku deploy:jar target/*.war
Or when using gradle:
heroku deploy:jar build/libs/*war
Deploying Microservices
JHipster microservices require a JHipster Registry as described in the Doing microservices with JHipster documentation. You can deploy a registry to Heroku by clicking this button:
Once the registry is deployed, you can run the jhipster heroku
command against your microservice or gateway. The Heroku sub-generator will prompt you for the URL of your registry, which will be in the form https://[appname].herokuapp.com
.
A registry running on Heroku has a few limitations, including:
- The registry will only work with native configuration (and not Git config).
- The registry service cannot be scaled up to multiple dynos to provide redundancy. You must deploy multiple applications (i.e. click the button more than once). This is because Eureka requires distinct URLs to synchronize in-memory state between instances.
Using security with your JHipster Registry on Heroku
To get the automatically-generated admin password on the JHipster Registry, type:
heroku config:get JHIPSTER_PASSWORD
To use this password, update all of your microservices and your gateway to use the credentials for the registry by running this command:
heroku config:set JHIPSTER_REGISTRY_URL="https://admin:[password]@[appname].herokuapp.com"
Troubleshooting
If your application is killed by Heroku when your Liquibase changelog is being applied, your database will be marked as “locked” by Liquibase. You will need to manually clean the lock table. On Postgres, you make sure you have a local Postgres client installed and run the following command:
heroku pg:psql -c "update databasechangeloglock set locked=false;"
Heroku has a default boot-timeout limit of 90 seconds. If your app takes longer than this, Heroku will kill the process, which may leave the database in a locked state. If the problem is persistent, try contacting Heroku Support to request a longer boot limit for your app.