JHipster generated project with Redis support fails on GitLab CI, despite Redis container running.
When using Redis, it should be possible to run the CI pipeline on GitLab which supports Redis.
Generate application with Redis support.
Generate GitLab CI config:
jhipster ci-cd
Select GitLab, and enable "dockerized"
Deploy the application to GitLab, and run the pipeline.
Job maven-test fails, because several integration tests fail with:
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.cache.configuration.Configuration]: Factory method 'jcacheConfiguration' threw exception; nested exception is java.lang.IllegalArgumentException: Redis url should start with redis:// or rediss:// (for SSL connection)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:185)
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651)
... 122 common frames omitted
Caused by: java.lang.IllegalArgumentException: Redis url should start with redis:// or rediss:// (for SSL connection)
at org.redisson.misc.RedisURI.
Tried to manally set things, but
None
Try to see what configuration is missing when running GitLab pipeline, and add that to the gitlab ci-cd code generation for GitLab.
6.8.0
{
"generator-jhipster": {
"promptValues": {
"packageName": "com.treemarks",
"nativeLanguage": "nl"
},
"jhipsterVersion": "6.8.0",
"applicationType": "monolith",
"baseName": "treemarks",
"packageName": "com.treemarks",
"packageFolder": "com/treemarks",
"serverPort": "8080",
"authenticationType": "jwt",
"cacheProvider": "redis",
"enableHibernateCache": true,
"websocket": false,
"databaseType": "sql",
"devDatabaseType": "h2Disk",
"prodDatabaseType": "postgresql",
"searchEngine": false,
"messageBroker": false,
"serviceDiscoveryType": false,
"buildTool": "maven",
"enableSwaggerCodegen": false,
"embeddableLaunchScript": false,
"useSass": true,
"clientPackageManager": "npm",
"clientFramework": "angularX",
"clientTheme": "superhero",
"clientThemeVariant": "primary",
"creationTimestamp": 1587216333162,
"testFrameworks": ["cucumber"],
"jhiPrefix": "jhi",
"entitySuffix": "",
"dtoSuffix": "DTO",
"otherModules": [],
"enableTranslation": true,
"nativeLanguage": "nl",
"languages": ["nl", "en"],
"blueprints": []
}
}
If you have a JDL please wrap it in below structure
entity Person {
givenName String,
familyName String,
mboxSha1 String
}
entity Statement {
subject String,
predicate String,
object String
}
relationship OneToMany {
Person{knows} to Person
}
relationship ManyToOne {
Statement{owner} to Person
}
.gitlab-ci.yml:
image: jhipster/jhipster:v6.8.0
#services:
# - redis
#connect:
# image: redis
# script:
# - redis-cli -h redis PING
cache:
key: '$CI_COMMIT_REF_NAME'
paths:
- .maven/
stages:
- check
- build
- test
- analyze
- package
- release
- deploy
before_script:
- export NG_CLI_ANALYTICS="false"
- export MAVEN_USER_HOME=`pwd`/.maven
- ./mvnw -ntp com.github.eirslett:frontend-maven-plugin:install-node-and-npm -DnodeVersion=v12.16.1 -DnpmVersion=6.14.2 -Dmaven.repo.local=$MAVEN_USER_HOME
- ./mvnw -ntp com.github.eirslett:frontend-maven-plugin:npm -Dmaven.repo.local=$MAVEN_USER_HOME
nohttp:
stage: check
script:
- ./mvnw -ntp checkstyle:check -Dmaven.repo.local=$MAVEN_USER_HOME
maven-compile:
stage: build
script:
- ./mvnw -ntp compile -Dmaven.repo.local=$MAVEN_USER_HOME
artifacts:
paths:
- target/classes/
- target/generated-sources/
expire_in: 1 day
maven-test:
stage: test
script:
- ./mvnw -ntp verify -Dmaven.repo.local=$MAVEN_USER_HOME
artifacts:
reports:
junit: target/test-results/**/TEST-*.xml
paths:
- target/test-results
- target/jacoco
expire_in: 1 day
frontend-test:
stage: test
script:
- ./mvnw -ntp com.github.eirslett:frontend-maven-plugin:npm -Dfrontend.npm.arguments='run test' -Dmaven.repo.local=$MAVEN_USER_HOME
artifacts:
reports:
junit: target/test-results/TESTS-results-jest.xml
paths:
- target/test-results
- target/jacoco
expire_in: 1 day
maven-package:
stage: package
script:
- ./mvnw -ntp verify -Pprod -DskipTests -Dmaven.repo.local=$MAVEN_USER_HOME
artifacts:
paths:
- target/*.jar
- target/classes
expire_in: 1 day
# Uncomment the following line to use gitlabs container registry. You need to adapt the REGISTRY_URL in case you are not using gitlab.com
docker-push:
stage: release
variables:
REGISTRY_URL: registry.gitlab.com
IMAGE_TAG: $CI_REGISTRY_IMAGE:$CI_COMMIT_REF_SLUG-$CI_COMMIT_SHA
dependencies:
- maven-package
script:
- ./mvnw -ntp compile jib:build -Pprod -Djib.to.image=$IMAGE_TAG -Djib.to.auth.username=gitlab-ci-token -Djib.to.auth.password=$CI_BUILD_TOKEN -Dmaven.repo.local=$MAVEN_USER_HOME
Mac OS, but not relevant
@jkransen : Currently we don't support Redis on our CI pipelines by default. You need to adjust some things manually I guess. Looking at the error, my guess is the default urls that we have for Redis in application-prod.yml is the root cause of your problem.
Change the url to redis:// or rediss:// to see if that solves your problem? :smile:
Hi Sudharaka, thanks for looking into the issue. I was prepared to do some manual steps, but I didn't get it working. Just now I noticed there is a separate test config in src/test/resources/config/application.yml and in it there was a placeholder that didn't get expanded:
jhipster:
cache:
redis:
server: ${redis.test.server}
I wasn't sure how to set a value here from outside/CI config, so I just filled it in with redis://redis:6379 Now I get an UnkownHostException for "redis", so it looks like this container is not available during integration test. Now I'm considering to disable the cache alltogether in test, but I don't like the test setup to be different from the running one.
But if you say it is not supported, then maybe you can convert this issue into a request, because I think it can be achieved with a minor extension in the code generation.
the property should be set here https://github.com/jhipster/generator-jhipster/blob/master/generators/server/templates/src/test/java/package/RedisTestContainerExtension.java.ejs#L38
Are you running in gitlab.com? Did you enable dind to support testcontainers starting containers in docker? Here is another example configuring it for gitlab.com
@atomfrede : Yes I think that should be what's missing. I was just doing a test with dind with @jkransen 's exact configuration; :smile:
https://gitlab.com/SudharakaP/jhipster-gitlab/pipelines/137638599
@atomfrede : And it passes; I think we should add this to github-ci.yml.ejs for all the databases that uses Testcontainers. :thinking:
I'll do a PR for this. :smile:
I've done the changes; let me know if you guys see any issues with it. :smile:
@jkransen : Sorry for the confusion in the beginning; I though this was some kinda problem with the configuration. :smile:
Thanks a lot, @SudharakaP !
@jkransen: Welcome :smile: