I'm trying to create a git superproject which contains submodules and have a docker-compose.yml
file in the superproject to build all submodules.
Like discussed here:
https://stackoverflow.com/a/52389869
Example file structure:
.
├── docker-compose.yml
├── .git
├── .gitmodules
├── module1
│ ├── Dockerfile
│ └── .git
└── module2
├── Dockerfile
└── .git
docker-compose.yml:
version: '3.4'
services:
module1:
image: module1
build:
context: ./module1
dockerfile: Dockerfile
module2:
image: module2
build:
context: ./module2
dockerfile: Dockerfile
This is also to orchestrate the environment but this is not relevant to my problems. This works fine initially.
However, the issue I'm running into, is if a module in its Dockerfile
uses git. For example in a module I'm using:
git describe --tags || git rev-parse HEAD
to pass a git version to embed in my module's program.
This doesn't work because the .git
folder in my submodule is no longer a folder but a file with a reference to <superproject>/.git/modules/module1/
.
The output I'm getting when trying to run docker-compose build
in superproject
is:
fatal: not a git repository: <IMAGE_CWD>/../.git/modules/module1
So git is trying to reference a file which does not exist because context: ./module1
is set in docker-compose.yml
I have no idea how to solve this. I don't want to expand the context in my docker-compose.yml
because then I'd have to rewrite all Dockerfile
's.
I saw someone suggest dropping git submodules
all together here:
https://stackoverflow.com/a/44559410
This seems hacky.
I also tried to find if there's an option to have the .git
folders in the submodules directly, oppposite of git submodule absorbgitdirs
but found nothing.
It seems like a common usage, right? Is there a solution to this? Any help would be appreciated.