Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker compose build fails in git submodule #38

Open
czeni opened this issue Mar 6, 2025 · 1 comment
Open

Docker compose build fails in git submodule #38

czeni opened this issue Mar 6, 2025 · 1 comment

Comments

@czeni
Copy link

czeni commented Mar 6, 2025

Hello,

when connector is added to another repo as a submodule, docker compose build fails.

$ git submodule add [email protected]:Prometheus-X-association/dataspace-connector.git connector
$ git submodule update --init
$ cd connector
$ cp .env.sample .env && cp .env.sample .env.development
$ docker compose build
WARN[0000] /home/czentye/projects/PTX-edge-computing/dataspace/connector/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion 
Compose now can delegate build to bake for better performances
Just set COMPOSE_BAKE=true
[+] Building 0.7s (17/23)                                                                                                                                                                           docker:default
 => [mongodb internal] load build definition from Dockerfile                                                                                                                                                  0.0s
 => => transferring dockerfile: 230B                                                                                                                                                                          0.0s
 => [dataspace-connector internal] load build definition from Dockerfile                                                                                                                                      0.0s
 => => transferring dockerfile: 584B                                                                                                                                                                          0.0s
 => [dataspace-connector internal] load metadata for docker.io/library/node:lts                                                                                                                               0.4s
 => [mongodb internal] load metadata for docker.io/library/mongo:latest                                                                                                                                       0.4s
 => [mongodb internal] load .dockerignore                                                                                                                                                                     0.0s
 => => transferring context: 57B                                                                                                                                                                              0.0s
 => [dataspace-connector internal] load .dockerignore                                                                                                                                                         0.0s
 => => transferring context: 57B                                                                                                                                                                              0.0s
 => CACHED [mongodb 1/1] FROM docker.io/library/mongo:latest@sha256:f6164e498dbaee3966031c1ced1bfa0fd1c4961151b38a770fa6994f4b0dcae7                                                                          0.0s
 => [mongodb] exporting to image                                                                                                                                                                              0.0s
 => => exporting layers                                                                                                                                                                                       0.0s
 => => writing image sha256:2338ebd94aae89efb924773f45e2d116b9d504049ae69f1a9a1c3497e253ac2c                                                                                                                  0.0s
 => => naming to docker.io/library/connector-mongodb                                                                                                                                                          0.0s
 => [dataspace-connector  1/13] FROM docker.io/library/node:lts@sha256:f6b9c31ace05502dd98ef777aaa20464362435dcc5e312b0e213121dcf7d8b95                                                                       0.0s
 => [dataspace-connector internal] load build context                                                                                                                                                         0.1s
 => => transferring context: 2.20MB                                                                                                                                                                           0.1s
 => [mongodb] resolving provenance for metadata file                                                                                                                                                          0.0s
 => CACHED [dataspace-connector  2/13] RUN npm install -g pnpm                                                                                                                                                0.0s
 => CACHED [dataspace-connector  3/13] RUN mkdir -p /usr/src/app                                                                                                                                              0.0s
 => CACHED [dataspace-connector  4/13] WORKDIR /usr/src/app                                                                                                                                                   0.0s
 => CACHED [dataspace-connector  5/13] COPY package.json .                                                                                                                                                    0.0s
 => CACHED [dataspace-connector  6/13] RUN git init                                                                                                                                                           0.0s
 => ERROR [dataspace-connector  7/13] COPY . .                                                                                                                                                                0.0s
------
 > [dataspace-connector  7/13] COPY . .:
------
failed to solve: cannot replace to directory /var/lib/docker/overlay2/5l6keyp2r6gxd7bqp4xaeqwq4/merged/usr/src/app/.git with file

This is only an issue within a submodule.
The main problem is that the line RUN git init in Dockerfile creates a .git folder, which is later to be overwritten with the local .git folder within the line COPY . ..

Temporal solution:

echo .git >>.dockerignore

This solves the build issue and the connector seems runnable whether it is built from a submodule or a regular repo.

However, I am uncertain why RUN git init is necessary in the first place and leaving out the local .git folder is a good solution without side effects.

@nuthub
Copy link

nuthub commented Mar 15, 2025

I need to echo "\n.git" >> .dockerignore, since .dockerignore doesn't have a newline at the end.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants