devspace-sh / devspace

DevSpace - The Fastest Developer Tool for Kubernetes ⚡ Automate your deployment workflow with DevSpace and develop software directly inside Kubernetes.
https://devspace.sh
Apache License 2.0
4.37k stars 361 forks source link

Create spring boot example #919

Closed ravening closed 5 months ago

ravening commented 4 years ago

Is your feature request related to a problem? I have a simple Java Spring boot application which displays greeting message on navigating to localhost:8080/hello but devspace is unable to serve the port forward nor able to reload the code changed dynamically

Which solution do you suggest? When I change the Java code, devspace dev should automatically reload the code and build the changes similar to other supported languages

Which alternative solutions exist?

Additional context

/kind feature

FabianKramm commented 4 years ago

@ravening thanks for opening this issue! Yes currently we are missing an example for spring boot, I think we should create one! However, generally speaking its just a matter of the right DevSpace configuration, I don't see any problem why DevSpace shouldn't work with spring boot applications. Is there any error during devspace dev or in the logs (.devspace/logs)?

ravening commented 4 years ago

@FabianKramm Even I was thinking the same.. its just a plain hello world java application which should be same as other projects but didnt find any errors in the logs as well.

I did devspace deploy to deploy on the cluster and then devspace dev to start working on it. If I make any changes to source code, I didnt see the package being compiled automatically. The end point returned the same message

LukasGentele commented 4 years ago

@ravening I will take a look at this and write a blog post about how to configure DevSpace for spring boot with hot reloading. We might add that as a java quick start guide as well.

LukasGentele commented 4 years ago

Alright. I did not find the time to create a blog post about DevSpace and spring boot but with the latest release, we now have a java quickstart project. It shows with a very simple example how to solve java container hot reloading with DevSpace.

@ravening Is that what you were looking for? Feel free to check it out here: https://devspace.sh/cli/docs/getting-started/initialize-project

heroyin commented 4 years ago

This java quickstart is very simple, sync java file and rebuild in remote container. For java spring , it's too slow. If I got time , will post a hot reload sample, like https://github.com/HotswapProjects/HotswapAgent

LukasGentele commented 4 years ago

That looks awesome! Can't wait for you to contribute the next Java project. Thanks, @heroyin

heroyin commented 4 years ago

https://github.com/heroyin/quickstart-spring-java Spring java quickstart is coming! @LukasGentele

Romeh commented 4 years ago

@heroyin @LukasGentele How it works with multii module spring boot application ? as other the main module which has *.classes pushed to the docker container , the other modules will be packaged as JAR in the libs folder of the main application .

is pushing new jar for one of the sub modules will trigger the hot code reload ?

LukasGentele commented 4 years ago

@Romeh Sorry for the late reply. I don't know how to make it work for multi-module spring boot applications but in case you figured it out, feel free to share your solution with us :)

joaomlneto commented 3 years ago

@LukasGentele I'm using devspace with Spring Boot apps. I think I can contribute with this.

What would be most helpful? An example "hello world" app repository with devspace.yml?

LukasGentele commented 3 years ago

@joaomlneto Thanks for suggesting that! That would be amazing. We could link to the project from the docs. Make sure it has an Apache 2.0 license and uses the newest devspace init recommended workflow that opens the terminal rather than log streaming.

If you're interested in showing a bit more advanced project with database plus showing some dev workflows etc., happy to feature you in our blog and social media as well. Ping me via slack.loft.sh if interested.

joaomlneto commented 3 years ago

@joaomlneto Thanks for suggesting that! That would be amazing. We could link to the project from the docs. Make sure it has an Apache 2.0 license and uses the newest devspace init recommended workflow that opens the terminal rather than log streaming.

I just bootstrapped a project using the latest Spring Boot and Devspace versions: https://github.com/joaomlneto/example-devspace-spring-boot

Let me know if it works for you :-) If you do git clone and devspace dev, it should work out of the box(?).

Some tweaks after devspace init:

If you're interested in showing a bit more advanced project with database plus showing some dev workflows etc., happy to feature you in our blog and social media as well. Ping me via slack.loft.sh if interested.

That'd be cool :-) I can do something more complex at a later date.

LukasGentele commented 3 years ago

@joaomlneto Thanks for putting this together and sorry I didn't find the time yet to take a closer look. The project looks very promising at first sight and I'll plan to take a closer look at this tomorrow.

LukasGentele commented 3 years ago

@joaomlneto This is great! I made some changes:

I also forked the project: https://github.com/loft-sh/devspace-example-spring-boot

Let me know if this looks good to you and I will make sure that include this in the docs and then we can get a blog post started later on if you like.

joaomlneto commented 3 years ago

@joaomlneto This is great! I made some changes:

  • replacePods+terminal instead of log streaming since I think that opening the terminal instead of log streaming provides more control for the developer and allows to skip image building which is a huge plus but it also means that you manually need to start the application using mvn spring-boot:run (added this as hint to devspace_start.sh and README)
  • added >>/dev/pts/0 to the mvn compile command to make sure that the output is shown inside the dev container's terminal

I also forked the project: https://github.com/loft-sh/devspace-example-spring-boot

LGTM! Easy to deploy via devspace dev and hot reload works.

I wasn't familiar with the proper workflows using DevSpace. 😅 I'm still using the legacy behavior on my services, which automatically start the application, and won't output the mvn compile command, which is neat! I'll steal that. 🙂

Let me know if this looks good to you and I will make sure that include this in the docs and then we can get a blog post started later on if you like.

We can adapt the Spring PetClinic to run in K8S with devspace. It's quite a complex example, but is a well-maintained sample project to showcase the Spring stack, and has already extensive documentation.

There are quite a few forks, and one is a modified version that is split into microservices and runs natively on K8S. I may be underestimating the task complexity, though.


On a related note: I have a devspace-newbie question: what is your approach to developing microservices? Currently I have my service applications in separate repositories, each with a devspace.yml that is deployed separately, but I sense this is not the recommended approach (for example, several DevSpace UIs are created and run on ports 809X, and the merged logs function doesn't work). Is your recommendation to also have a top-level devspace.yml when integrating services? Do you [plan to] support composition of sub-projects with their own devspace.yml? Loaded questions, sorry! 😄

LukasGentele commented 3 years ago

@joaomlneto Thanks! That's perfect. Would love to see a more advanced version with the PetClinic project. Let me know if you have an initial version of a devspace.yaml or a forked project and I'm happy to review and extend it if needed.

To your question about microservices: Yes, that is possible with devspace using the dependencies option (https://devspace.sh/cli/docs/configuration/dependencies/basics). For your structure, I would recommend having separate devspace.yaml files and if they are part of the same git repo, use path-based dependencies. Sometimes, if folks tend to work on the same services together a lot, they prefer just having 1 devspace.yaml that deploys everything instead of splitting it up but that depends on the type of applications and how closely they are connected. Other additional microservices located in separate git repos outside of the monorepo can also be added as git-based dependencies. Let me know if there are any further questions about this. The UI can run multiple times. That is not a problem. DevSpace will pick a different port but you can still just use one UI and see all the containers in one view (at least if they are in the same namespace, otherwise use the namespace switcher on the right).

Also a heads-up: I told @richburroughs that you may want to write or contribute to a blog post about Spring with DevSpace and he'll be in touch with you about that :)

deniseschannon commented 5 months ago

It looks like there are multiple examples in this issue to use so closing the issue.