Reputation: 1378
I am trying to set up some legacy project with docker. To do so I have created a main repository with docker
files and added actual project as a submodule
. As a result I have:
root
|- data
|- etc
| |-php
| |-etc
|- project
| |- .git
| |- (actual project files)
|- docker-compose.yml
|- .dockerignore
In such setup the project/.git
is just a text file containing gitdir: ../.git/modules/project
.
Now, in docker-compose.yml
I have following volume mapped:
- ${APP_PATH}:/var/www/html
Within this container I install npm install
(I know I should prepare separate container for node
and I will do it in the future but for now I need to run what I do have) and this ends up with following git
root@06fc2e3fe52a:/var/www/html# npm install
npm ERR! Error while executing:
npm ERR! /usr/bin/git ls-remote -h -t ssh://[email protected]/bengourley/stack-generator.git
npm ERR!
npm ERR! fatal: Not a git repository: ../.git/modules/project
I have already created following .dockerignore
file:
project/.git
project/.gitignore
project/.gitattributes
.git
Dockerfile
.DS_Store
.gitignore
README.md
/tmp/*
Is it possible to make this work without mapping a root docker directory above the www
in container so that this npm install
could go through?
Upvotes: 4
Views: 720
Reputation: 2347
I had the very same problem but could solve it with a .dockerignore
-file.
src/.git
src/.gitignore
src/.gitattributes
but at the level of the Dockerfile (while src is the sub-repo), not on the top-level.
Upvotes: 1
Reputation: 1323055
Is it possible to make this work without mapping a root docker directory above the www in container so that this npm install could go through?
That might be a bit of a challenge, considering that within the docker build
process, all Git-related folder are ignored (per your .dockerignore
file).
I'd really need an answer on how to handle npm install in connection with git subrepositories
That is what npm
issue 6700 is about.
It proposes several approaches:
- a
postinstall
script to initialize your git submodules. As in this example- checking out all the git repositories into parallel directories, e.g.,
src/
src/mod1
src/mod2
src/mod3
and then use
npm link
to connect the dependencies:
$ cd src/mod1
$ npm link
# this makes a link from the system-wide node_modules to the current dir
$ cd ../mod2
$ npm link mod1
# this makes a link from node_modules/mod1 to ../mod2
That way if you make changes in mod1 or mod2, they can be committed to the appropriate git repository, and you can see the changes right away without having to re-install, re-download etc.
- using the
grunt-git
package
The second approach is promising, provided you can mount a pre-initialized submodule repo into a separate path, and use npm link
to reference the right folder while still being in /var/www/html
.
Upvotes: 2