enofex / naikan

Naikan is an open source software inventory management tool for dev teams driven by our CI/CD pipeline.

Home Page:https://naikan.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spring-boot-docker-compose ignore 'dev' profile and uses docker-compose.yml in the project root

panilya opened this issue · comments

Hi, I saw your tweet with a link to this project. I was immediately interested in the technologies used here🙃. I'd like to help and contribute to the project as well, but I've encountered a problem when launching the project locally.

I don't understand why spring-boot-starter-docker ignores the dev profile and still uses docker-compose in the project root.

This is the console output:

2023-09-16T21:11:25.228+03:00 INFO 66991 --- [ restartedMain] com.enofex.naikan.NaikanApplication : Starting NaikanApplication using Java 20.0.2 with PID 66991 (/Users/panilya/Documents/naikan/naikan-web/target/classes started by panilya in /Users/panilya/Documents/naikan)
2023-09-16T21:11:25.232+03:00 INFO 66991 --- [ restartedMain] com.enofex.naikan.NaikanApplication : The following 1 profile is active: "dev"
2023-09-16T21:11:25.315+03:00 INFO 66991 --- [ restartedMain] .s.b.d.c.l.DockerComposeLifecycleManager : Using Docker Compose file '/Users/panilya/Documents/naikan/docker-compose.yml'
2023-09-16T21:11:26.305+03:00 INFO 66991 --- [utReader-stderr] o.s.boot.docker.compose.core.DockerCli :  Container naikan Created
2023-09-16T21:11:26.311+03:00 INFO 66991 --- [utReader-stderr] o.s.boot.docker.compose.core.DockerCli :  Container naikan Starting
2023-09-16T21:11:26.609+03:00 INFO 66991 --- [utReader-stderr] o.s.boot.docker.compose.core.DockerCli :  Container naikan Started
2023-09-16T21:11:26.610+03:00 INFO 66991 --- [utReader-stderr] o.s.boot.docker.compose.core.DockerCli :  Container naikan Waiting
2023-09-16T21:11:27.119+03:00 INFO 66991 --- [utReader-stderr] o.s.boot.docker.compose.core.DockerCli :  Container naikan Healthy

Thank you.

👋 @panilya

Welcome to the Naikan community! 💖

Thanks and congrats 🎉 for opening your first issue here!

Hope you have a great time there!

Great to see you here!

The configuration for the dev profile can be found here:

https://github.com/enofex/naikan/blob/main/naikan-web/src/main/resources/application-dev.yml

Here you can find the configuration:

file: "./development/docker/compose.yml"

The docker-compose in the root is the docker-compose which will be used for the installation

curl -LO https://naikan.io/docker-compose.yml
docker-compose up -d

I didn't really know about the spring-boot-docker-compose dependency before, and it looks cool.

I'm running NaikanApplication using dev profile and it should use the compose.yml file in the development/docker directory, right? But it somehow uses docker-compose.yml in the root of the project which doesn't specify mongodb connection string, I get the following problem when Spring Boot tries to start in docker container:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name overviewContactServiceHandler' defined in class path resource [com/enofex/naikan/overview/contact/support/OverviewContactServiceHandler.class]: 
Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'overviewContactMongoRepository' defined in class path resource [com/enofex/naikan/overview/contact/support/OverviewContactMongoRepository.class]: 
Unsatisfied dependency expressed through constructor parameter 0: 
Error creating bean with name 'mongoTemplate' defined in class path resource [com/enofex/naikan/MongoConfiguration.class]: 
Unsatisfied dependency expressed through method 'mongoTemplate' parameter 0: Error creating bean with name 'mongoDatabaseFactory' defined in class path resource [org/springframework/boot/autoconfigure/data/mongo/MongoDatabaseFactoryConfiguration.class]: 
Unsatisfied dependency expressed through method 'mongoDatabaseFactory' parameter 0: 
Error creating bean with name 'mongo' defined in class path resource [org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration.class]: Failed to instantiate [com.mongodb.client.MongoClient]: 
Factory method 'mongo' threw exception with message: Error creating bean with name 'standardMongoSettingsCustomizer' defined in class path resource [org/springframework/boot/autoconfigure/mongo/MongoAutoConfiguration$MongoClientSettingsConfiguration.class]: 
Failed to instantiate [org.springframework.boot.autoconfigure.mongo.StandardMongoClientSettingsBuilderCustomizer]: Factory method 'standardMongoSettingsCustomizer' 
threw exception with message: 
The connection string is invalid. Connection strings must start with either 'mongodb://' or 'mongodb+srv://

Yes, the compose.yml file will be taken be Spring as specified in the configuration. In the application-dev.yml you can find the configurations for mongodb as well:

spring:
  data:
    mongodb:
      uri: mongodb://localhost:27071/naikan?replicaSet=rs0

When you start the app with the dev profile everything should work out of the box.

Please check this before as well https://github.com/enofex/naikan/blob/main/DEVELOPING.md

Right, but Spring Boot app in Docker container falling back to default profile, however I ran it with dev profile.

2023-09-16 20:50:56 2023-09-16T17:50:56.572Z  INFO 1 --- [           main] com.enofex.naikan.NaikanApplication      : Starting NaikanApplication v0.6.0 using Java 20.0.2 with PID 1 (/BOOT-INF/classes started by root in /)
2023-09-16 20:50:56 2023-09-16T17:50:56.592Z  INFO 1 --- [           main] com.enofex.naikan.NaikanApplication      : No active profile set, falling back to 1 default profile: "default"
2023-09-16 20:50:58 2023-09-16T17:50:58.818Z  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2023-09-16 20:50:58 2023-09-16T17:50:58.852Z  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 25 ms. Found 0 MongoDB repository interfaces.
2023-09-16 20:51:00 2023-09-16T17:51:00.340Z  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2023-09-16 20:51:00 2023-09-16T17:51:00.362Z  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-09-16 20:51:00 2023-09-16T17:51:00.363Z  INFO 1 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.12]
2023-09-16 20:51:00 2023-09-16T17:51:00.571Z  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext

The profile is not set, as you can the in the log. The configuration depends on the IDE you are using.
Set -Dspring.profiles.active=dev as JVM parameter.

Yes, this is the problem. The profile IS set like you said and it sees dev profile when I run NaikanApplication, this is the console output:

2023-09-16T21:11:25.228+03:00  INFO 66991 --- [  restartedMain] com.enofex.naikan.NaikanApplication      : Starting NaikanApplication using Java 20.0.2 with PID 66991 (/Users/panilya/Documents/naikan/naikan-web/target/classes started by panilya in /Users/panilya/Documents/naikan)
2023-09-16T21:11:25.232+03:00  INFO 66991 --- [  restartedMain] com.enofex.naikan.NaikanApplication      : The following 1 profile is active: "dev"
2023-09-16T21:11:25.315+03:00  INFO 66991 --- [  restartedMain] .s.b.d.c.l.DockerComposeLifecycleManager : Using Docker Compose file '/Users/panilya/Documents/naikan/docker-compose.yml'
2023-09-16T21:11:26.305+03:00  INFO 66991 --- [utReader-stderr] o.s.boot.docker.compose.core.DockerCli   :  Container naikan  Created
2023-09-16T21:11:26.311+03:00  INFO 66991 --- [utReader-stderr] o.s.boot.docker.compose.core.DockerCli   :  Container naikan  Starting
2023-09-16T21:11:26.609+03:00  INFO 66991 --- [utReader-stderr] o.s.boot.docker.compose.core.DockerCli   :  Container naikan  Started
2023-09-16T21:11:26.610+03:00  INFO 66991 --- [utReader-stderr] o.s.boot.docker.compose.core.DockerCli   :  Container naikan  Waiting
2023-09-16T21:11:27.119+03:00  INFO 66991 --- [utReader-stderr] o.s.boot.docker.compose.core.DockerCli   :  Container naikan  Healthy

But when I open naikan docker container logs, it falls back to the default profile:

2023-09-16 20:50:56 2023-09-16T17:50:56.572Z  INFO 1 --- [           main] com.enofex.naikan.NaikanApplication      : Starting NaikanApplication v0.6.0 using Java 20.0.2 with PID 1 (/BOOT-INF/classes started by root in /)
2023-09-16 20:50:56 2023-09-16T17:50:56.592Z  INFO 1 --- [           main] com.enofex.naikan.NaikanApplication      : No active profile set, falling back to 1 default profile: "default"
2023-09-16 20:50:58 2023-09-16T17:50:58.818Z  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data MongoDB repositories in DEFAULT mode.
2023-09-16 20:50:58 2023-09-16T17:50:58.852Z  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 25 ms. Found 0 MongoDB repository interfaces.
2023-09-16 20:51:00 2023-09-16T17:51:00.340Z  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2023-09-16 20:51:00 2023-09-16T17:51:00.362Z  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-09-16 20:51:00 2023-09-16T17:51:00.363Z  INFO 1 --- [           main] o.apache.catalina.core.StandardEngine    : Starting Servlet engine: [Apache Tomcat/10.1.12]
2023-09-16 20:51:00 2023-09-16T17:51:00.571Z  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext

The dev profile is used only for developing.

When you start the docker-compose.yml the published version will be used and there is no profile set. So, the logs are correct.

When you want to start the app for developing with all infrastructure then start the app with dev, start the client and point to http://localhost:4200/

You do not have to start the docker-compose.yml in the root, this is for production use.

Deleting mongodb and openldap docker containers and running NaikanApplication again solved my problem.

Thank you.

Feel free to adjust the documentation, if you think something is unclear, thanks.