generator-jhipster icon indicating copy to clipboard operation
generator-jhipster copied to clipboard

[v7.9.3] App with Elasticsearch doesn't work out-of-the-box with Heroku

Open mraible opened this issue 1 year ago • 7 comments

Overview of the issue

I'm updating 21-Points Health as part of the JHipster Mini-Book. When I deploy to Heroku with Jenkins, it fails to work.

The generated deployment task is as follows:

stage('deployment') {
    sh "./gradlew deployHeroku --no-daemon"
}

I started commenting on the old issue, but realized it's probably better to create a new one.

With JHipster v7.9.3, the workaround of downgrading Elasticsearch for Heroku only works with git push and fails to work when you try to use Elasticsearch:

2022-11-08T05:17:22.489474+00:00 app[web.1]: 2022-11-08T05:17:22.488Z ERROR 4 --- [  XNIO-1 task-3] o.z.problem.spring.common.AdviceTraits   : Internal Server Error
2022-11-08T05:17:22.489493+00:00 app[web.1]:
2022-11-08T05:17:22.489494+00:00 app[web.1]: org.springframework.web.util.NestedServletException: Handler dispatch failed; nested exception is java.lang.NoSuchFieldError: INDEX_CONTENT_TYPE
2022-11-08T05:17:22.489496+00:00 app[web.1]: at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1085)
2022-11-08T05:17:22.489496+00:00 app[web.1]: at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963)
Motivation for or Use Case

I'd like to update the JHipster Mini-Book to v7 and this is a blocker.

Reproduce the error

Create an app using the following .yo-rc.json, deploy it to Heroku, and try to register a new user.

{
  "generator-jhipster": {
    "applicationType": "monolith",
    "authenticationType": "jwt",
    "baseName": "TwentyOnePoints",
    "blueprints": [],
    "buildTool": "gradle",
    "cacheProvider": "ehcache",
    "clientFramework": "angularX",
    "clientPackageManager": "npm",
    "clientTheme": "none",
    "clientThemeVariant": "",
    "creationTimestamp": 1662997089611,
    "cypressAudit": false,
    "cypressCoverage": false,
    "databaseType": "sql",
    "devDatabaseType": "h2Disk",
    "devServerPort": 4200,
    "dtoSuffix": "DTO",
    "enableGradleEnterprise": false,
    "enableHibernateCache": true,
    "enableSwaggerCodegen": false,
    "enableTranslation": true,
    "entities": ["Points", "Weight", "BloodPressure", "Preferences"],
    "entitySuffix": "",
    "jhiPrefix": "jhi",
    "jhipsterVersion": "7.9.3",
    "languages": ["en", "fr"],
    "lastLiquibaseTimestamp": 1667866821000,
    "messageBroker": false,
    "microfrontend": false,
    "microfrontends": [],
    "nativeLanguage": "en",
    "otherModules": [],
    "packageName": "org.jhipster.health",
    "pages": [],
    "prodDatabaseType": "postgresql",
    "reactive": false,
    "searchEngine": "elasticsearch",
    "serverPort": "8080",
    "serverSideOptions": ["searchEngine:elasticsearch"],
    "serviceDiscoveryType": "no",
    "skipCheckLengthOfIdentifier": false,
    "skipClient": false,
    "skipFakeData": false,
    "skipUserManagement": false,
    "testFrameworks": ["cypress"],
    "websocket": false,
    "withAdminUi": true
  }
}

Or, clone this repo and try to deploy it to Heroku.

Related issues
  • https://github.com/jhipster/generator-jhipster/issues/18650
Suggest a Fix

I think there's a few options:

  • Switch to using the Elasticsearch add-on, which costs $67/month.
  • Deploy a Docker container to Heroku and use that instead.
  • Remove Elasticsearch from the 21-Points Health example or use some other search technology.

Personally, using the ES add-on seems like the best practice, but 67/month seems pricey for a sample app. I already pay $25/month to keep it on all the time. I'd like to document the best way to do things in the mini-book, if possible. There's a good chance this predicament and solution will be part of the book.

Deploying a Docker container to Heroku seems like an easy workaround. Here's some helpful links:

  • https://devcenter.heroku.com/articles/container-registry-and-runtime
  • https://devcenter.heroku.com/articles/build-docker-images-heroku-yml
  • https://github.com/heroku/alpinehelloworld/blob/master/Dockerfile
  • https://www.elastic.co/blog/how-to-make-a-dockerfile-for-elasticsearch
JHipster Version
[email protected] /Users/mraible/dev/21-points
└── [email protected]
JHipster configuration, a .yo-rc.json file generated in the root folder
.yo-rc.json file
{
  "applicationType": "monolith",
  "authenticationType": "jwt",
  "baseName": "TwentyOnePoints",
  "blueprints": [],
  "buildTool": "gradle",
  "cacheProvider": "ehcache",
  "clientFramework": "angularX",
  "clientPackageManager": "npm",
  "clientTheme": "none",
  "clientThemeVariant": "",
  "creationTimestamp": 1662997089611,
  "cypressAudit": false,
  "cypressCoverage": false,
  "databaseType": "sql",
  "devDatabaseType": "h2Disk",
  "devServerPort": 4200,
  "dtoSuffix": "DTO",
  "enableGradleEnterprise": false,
  "enableHibernateCache": true,
  "enableSwaggerCodegen": false,
  "enableTranslation": true,
  "entities": [
    "Points",
    "Weight",
    "BloodPressure",
    "Preferences"
  ],
  "entitySuffix": "",
  "herokuAppName": "health-by-pints",
  "herokuDeployType": "git",
  "herokuJavaVersion": "11",
  "jhiPrefix": "jhi",
  "jhipsterVersion": "7.9.3",
  "languages": [
    "en",
    "fr"
  ],
  "lastLiquibaseTimestamp": 1667866821000,
  "messageBroker": false,
  "microfrontend": false,
  "microfrontends": [],
  "nativeLanguage": "en",
  "otherModules": [],
  "packageName": "org.jhipster.health",
  "pages": [],
  "prodDatabaseType": "postgresql",
  "reactive": false,
  "searchEngine": "elasticsearch",
  "serverPort": "8080",
  "serverSideOptions": [
    "searchEngine:elasticsearch"
  ],
  "serviceDiscoveryType": "no",
  "skipCheckLengthOfIdentifier": false,
  "skipClient": false,
  "skipFakeData": false,
  "skipUserManagement": false,
  "testFrameworks": [
    "cypress"
  ],
  "websocket": false,
  "withAdminUi": true
}
JDL for the Entity configuration(s) entityName.json files generated in the .jhipster directory
JDL entity definitions
entity Points {
  date LocalDate required
  exercise Integer
  meals Integer
  alcohol Integer
  notes String maxlength(140)
}
entity Weight {
  timestamp ZonedDateTime required
  weight Double required
}
entity BloodPressure {
  timestamp ZonedDateTime required
  systolic Integer required
  diastolic Integer required
}
entity Preferences {
  weeklyGoal Integer required min(10) max(21)
  weightUnits Units required
}
enum Units {
  KG,
  LB
}

relationship OneToOne {
  Preferences{user(login)} to User
}
relationship ManyToOne {
  Points{user(login)} to User
  Weight{user(login)} to User
  BloodPressure{user(login)} to User
}

paginate Points with pagination
paginate Weight, BloodPressure with infinite-scroll

Environment and Tools

openjdk version "17.0.5" 2022-10-18 OpenJDK Runtime Environment Temurin-17.0.5+8 (build 17.0.5+8) OpenJDK 64-Bit Server VM Temurin-17.0.5+8 (build 17.0.5+8, mixed mode)

git version 2.33.0

node: v16.17.0 npm: 8.19.3

Docker version 20.10.20, build 9fdeb9c

mraible avatar Nov 14 '22 21:11 mraible