how to containerize a part of application

10/13/2020

I am working on a POC where I had to containerize a part of application for eg - I need to containerize "add to cart" functionality in an e-commerce website, I see a various example https://dzone.com/articles/docker-for-devs-containerizing-your-application to containerize whole application,but how to do for a part of it where my functionalities has dependency on other code parts as well.

Any pointers will be very helpful as I am totally stuck and don't see similar query anywhere else.

Thanks

-- Anand
docker
docker-compose
kubernetes

3 Answers

10/13/2020

IMHO, the first thing you need to do is read more about the concept of microservices and how it works.

Basically, the idea is decouple your monolithic application into as many services as your want and deploy it separate of each other. Each of this parts will comminicate with other parts by API calls.

There are a lot of benefits of using microservices architecture, and there is no the "better way" to do this, it will depends of how your application works and how your team is engaged.

I can recommend you a couple of link about microservices:

https://medium.com/hashmapinc/the-what-why-and-how-of-a-microservices-architecture-4179579423a9

https://opensource.com/resources/what-are-microservices

https://en.wikipedia.org/wiki/Microservices

-- Mr.KoopaKiller
Source: StackOverflow

10/13/2020

This is how I'd do it:

  1. create a new java/gradle module called "addToCart"
  2. extract all functionality related to "add to cart" functionality to this single gradle, spring boot module (add relevant dependencies to build.gradle and update settings.gradle to include the new module. And use compile("module") to have dependencies on existing modules brought into your new spring-boot module (note: you can't depend on a module that is a spring boot application - this will fail because spring-boot modules are compiled differently to lib modules without the spring boot plugin).
  3. extract any dependencies this new module has on existing code out to another new library module that can be pulled in using a gradle dependency (you're aiming to end up with a Gradle multiproject build). This is required so that existing projects/modules as well as the new one can maintain the same dependencies.
  4. use a gradle docker plugin like https://github.com/palantir/gradle-docker OR https://github.com/bmuschko/gradle-docker-plugin to create a docker image/container for you (instructions on website). You can do this part manually also.

If you're feeling particularly adventurous you could look into building GraalVM "native images" that are container friendly. Native images start incredibly fast. Because they start so fast you don't actually need to have them running all the time, which can lower your costs. There are trade-offs though. There's a talk from Devoxx Belgium 2019 that goes into details about it here: https://youtu.be/3eoAxphAUIg?t=978

-- Rob Evans
Source: StackOverflow

10/13/2020

If the application is not build as microservices, it wont actually work. The POC you should be striving for is to decouple it in another seperate application.... Which I guess its much harder and larger scope of the original POC

-- A_kat
Source: StackOverflow