Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker project structure with git submodules

When I see git projects which use Docker, then docker is just added to the git project which contains the source code one application. But what if I want to use docker-compose to orchestrate multiple of my git-projects, because they work together (backend, frontend, ...)?

For now, I use the source code from two other git projects and some more self-created Dockerfiles - so my compose-file now has 7 services (also some public ones from docker hub). I also need to create slightly different .yml files for different use cases (just with different environment variables). Is there any best practise how to structure such a project?

My project looks like this:

my-project/
|__ env/
|   |__ service-1/
|   |   |__ default.env
|   |   |__ usecase-1.env
|   |__ service-2/
|       |__ default.env
|       |__ usecase-1.env
|__ override/
|   |__ usecase-1.yml
|__ src/
|   |__ service-1/
|   |   |__ service-1/ (git submodule)
|   |   |__ Dockerfile
|   |__ service-2/
|       |__ Dockerfile
|__docker-compose.yml # default .yml, containing service-1 and service-2

So if there is a new use case, I create a new usecase-2.yml inside override/ and also some new usecase-2.env files inside my env/ folder.

For myself it's logical but I wonder what is best practise - becasue I don't find any similar project.

like image 477
Munchkin Avatar asked Sep 04 '25 17:09

Munchkin


1 Answers

If you want to use git submodules, then you need to group by service, not by env and src:

my-project/
|__ service-1/
|   |__ env/
|   |__ src/
|   |__ Dockerfile
|__ override/
|   |__ usecase-1.yml
|__ service-2/
|   |__ env/
|   |__ src/
|   |__ Dockerfile
|__docker-compose.yml # default .yml, containing service-1 and service-2

That way, service-1 and service-2 can be git repos of their own that you can add as submodules in the main parent repo 'my-project'.

like image 56
VonC Avatar answered Sep 07 '25 08:09

VonC