JHipster offers sub-generators for deploying applications to cloud providers (such as Heroku and Openshift), but not for applications using MongoDB due to the fact that Mongeez requires admin privileges which of course is not possible within a PaaS environment.
However, it should be possible to run JHipster + MongoDB on cloud providers as long as Mongeez is deactivated. I did the following (using Heroku):
- First, I manually exported the MongoDB database that was created by JHipster on my local development machine and imported it on a Mongolab instance.
- In case the used profile is
prod
, Mongeez doesn't get instantiated. - After some modifications to JHipster's Heroku subgenerator, it was possible to deploy the app to Heroku. The generator now ignores
_HerokuDatabaseConfiguration.java
(which is for JDBC) and in the used Procfile, I changed the profile toprod
(instead ofprod,heroku
) and removed the parameter--spring.datasource.heroku-url=$DATABASE_URL
.
It works quite well, but I have problems with injecting the MongoDB connection string. At the moment, the credentials are "hardcoded" into application-prod.yml
, so it would be necessary to redeploy the whole application in case of a change of the credentials. In another attempt, I added spring.data.mongodb.uri=$MONGOLAB_URI
to the Procfile, but there wasn't any effect (unless I missed something).
So how could I solve this issue? As I said, the application is running on Heroku without any problems, but it would be nice to derive the connection details from e.g. the MONGOLAB_URI environment variable. In other news, I have a feeling that I don't understand the cloud
profile (which I do not use at the moment).
Instead of Mongeez you can use mongobee to provide the migration logic for your app.
I've tried it and it works on heroku.
This is my default mongobee migration code for jhipster that has the same effect as the mongeez one.
In the
DatabaseConfiguration.java
file remove mongeez and addAnd finally update your gradle file removing the mongeez dependency and adding:
I've also opened a pull request to update the JHipster generator. Now we wait to see if the guys agree :)