Mehdi
Mehdi

Reputation: 5597

How to dockerize monolith app with multiple separated projects?

i want to use docker image of my monolith application to test my app after commiting changes. I have one web-app project and many library projects (not application project!) in separated solutions that output of these projects will copy to a path that application's bin placed and make my app executable.

my source code structure is like this:

|--Master_Web_App.sln
|     |
|     app.csproj
|
|--projectA.sln
|      | 
|      projectA-1.csproj 
|      | 
|      projectA-2.csproj 
| 
|--projectB.sln 
      | 
      projectB-1.csproj 
      | 
      projectB-2.csproj 

after building each project i copy its output to the physical path that website defined:

wwwroot
|--app
    |
    bin
      |
      app.dll
      projectA-1.dll
      projectA-2.dll
      projectB-1.dll
      projectB-2.dll

i created a base docker image to run my application. when a change occured in a specific project (ex projectA-1) i want to create a single docker image FROM baseIamge that only copies projectA-1's output to destination folder.

Assumptions:

  1. i should have one single docker image for projects changes. (because i have a single-monolith app)
  2. projects placed separated but part of a single web app.
  3. i want create image only include changes from base image.

what is the best practice to handle it??

i thougt about creating a Dockerfile in root of each project and create a tool to merge all these Dockerfiles (every time changes commited and developer selected changed projects) and make a single-but-multi-staged Dockerfile! so result of Docker Build will be an image included selected projects output and will COPY dlls to base image. but i'm not sure that generating Dockerfile text programtically is a good approach.

Upvotes: 0

Views: 399

Answers (1)

Akash Sharma
Akash Sharma

Reputation: 757

You will have complex matrix of project version during development.

But one approach could be to pass project version/branch as parameters to docker build process. Create custom docker build process where you can build multiple projects as separate docker images one per project. For application docker image, Dockerfile use multistage builder and use all the project images to copy dlls in respective directories.

Separate images like:

|--Master_Web_App.sln
|     |
|     app.csproj -> app-dockerimage
|
|--projectA.sln
|      | 
|      projectA-1.csproj  -> projectA-1-dockerimage
|      | 
|      projectA-2.csproj  -> projectA-2-dockerimage
| 
|--projectB.sln 
      | 
      projectB-1.csproj  -> projectB-1-dockerimage 
      | 
      projectB-2.csproj  -> projectB-2-dockerimage 

Main docker image:

# app docker image
FROM projectA-1-dockerimage as projectA-1
FROM projectA-2-dockerimage as projectA-2
FROM projectB-1-dockerimage as projectB-1
FROM projectB-2-dockerimage as projectB-2

FROM BASE_IMAGE

# other steps
#Build process app.dll

COPY FROM --projectA-1 wwwroot/app/bin/projectA-1.dll
COPY FROM --projectA-2 wwwroot/app/bin/projectA-2.dll
COPY FROM --projectB-1 wwwroot/app/bin/projectB-1.dll
COPY FROM --projectB-2 wwwroot/app/bin/projectB-2.dll

Upvotes: 1

Related Questions