This sub-generator allows deployment of your JHipster application to the Heroku cloud.
Heroku is helping JHipster in two ways:
Before running the sub-generator, you must install the Heroku toolbelt, and have a Heroku account created.
You must also create a Heroku account and log in with the toolbelt 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:
yo 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!
When your application is already deployed, you can prepare a new deployment by typing:
./mvnw package -Pprod -DskipTests
Or when using gradle:
./gradlew -Pprod bootRepackage -x test
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 first run heroku plugins:install https://github.com/heroku/heroku-deploy.
heroku plugins:install https://github.com/heroku/heroku-deploy
To push to production, type:
heroku deploy:jar --jar target/*.war
heroku deploy:jar --jar build/libs/*war
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 yo 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.
https://[appname].herokuapp.com
A registry running on Heroku has a few limitations, including:
To secure the registry, you must add the spring-boot-starter-security dependency to the app. To do so, first clone a local copy of the registry by running these commands (but replace “[appname]” with the name of your Heroku registry app):
spring-boot-starter-security
git clone https://github.com/jhipster/jhipster-registry cd jhipster-registry heroku git:remote [appname]
git clone https://github.com/jhipster/jhipster-registry
cd jhipster-registry
heroku git:remote [appname]
Then add the following dependency to the pom.xml:
pom.xml
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency>
Then commit the change and redeploy the registry by running these commands:
git add pom.xml git commit -m "security" git push heroku master
git add pom.xml
git commit -m "security"
git push heroku master
A random password for the registry was automatically configured when you deployed it. You can capture this value by running the following command:
heroku config:get JHIPSTER_PASSWORD
Finally, 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="http://user:[password]@[appname].herokuapp.com"
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.