具有docker compose构建的Git子模块
我正在尝试创建一个git超级项目,其中包含子模块,并且超级项目中有一个具有docker compose构建的Git子模块,git,docker,docker-compose,dockerfile,git-submodules,Git,Docker,Docker Compose,Dockerfile,Git Submodules,我正在尝试创建一个git超级项目,其中包含子模块,并且超级项目中有一个docker compose.yml文件来构建所有子模块 就像这里讨论的: 文件结构示例: . ├── docker-compose.yml ├── .git ├── .gitmodules ├── module1 │ ├── Dockerfile │ └── .git └── module2 ├── Dockerfile └── .git docker-compose.yml: version:
docker compose.yml
文件来构建所有子模块
就像这里讨论的:
文件结构示例:
.
├── 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
这也是为了协调环境,但这与我的问题无关。
这在开始时效果很好
然而,我遇到的问题是,它的Dockerfile
中的模块是否使用git。例如,在我正在使用的模块中:
git describe --tags || git rev-parse HEAD
传递git版本以嵌入到模块的程序中。
这不起作用,因为我的子模块中的.git
文件夹不再是一个文件夹,而是一个引用了/.git/modules/module1/
的文件
在superproject
中尝试运行docker compose build
时得到的输出是:
fatal: not a git repository: <IMAGE_CWD>/../.git/modules/module1
fatal:不是git存储库:/...git/modules/module1
因此git试图引用一个不存在的文件,因为context:./module1
是在docker compose.yml
我不知道怎么解决这个问题。我不想在我的docker compose.yml
中扩展上下文,因为这样我就必须重写所有Dockerfile
我看到有人建议将git子模块
放在这里:
这似乎有点骇人听闻
我还试图找到是否有一个选项可以将.git
文件夹直接放在子模块中,但没有找到任何选项
这似乎是一个常见的用法,对吗?有解决办法吗?任何帮助都将不胜感激