several development container environment with git
Asked Answered
T

2

6

I am using vs-code devcontainer feature to create a containerized development environment of the following setup:

root_folder (main git repository)
|- .git
|- docker-compose.yml
|- @myapi-submodule (django python API)
  |- .devcontainer.json
|- @myclient-submodule (react js client)
  |- .devcontainer.json

In the docker-compose.yml I create 2 services respectively api and client and mount their corresponding submodule folder.

I can then "Open Folder in Container..." in 2 separate windows and everything works great except for git. I need to be able to make changes, commit them change branches... from the container but since only the submodule folder is mounted I can't use git at all.

What are my options in this scenario ? How can I modify the submodule from the container without the parent folder ?

Trombley answered 30/4, 2020 at 20:0 Comment(1)
DId you find a solution for this? You could just use git from outside of vs code, I guess, using eg 'Git bash' in the root project folder on windows...Lignify
W
0

The easiest solution would be to create a single .devcontainer directory in your root project dir and in there create a new docker-compose.yml (or extend the existing one if possible.

├── .git
├── .devcontainer
│   ├── devcontainer.json
│   ├── docker-compose-extend.yml # either extend current docker-compose file
│   ├── docker-compose.yml # or create a new one
│   └── Dockerfile # your new docker-compose.yml can also use different Dockerfile(s)
├── @myapi-submodule (django python API)
└── @myclient-submodule (react js client)

The devcontainer.json file should now use the new docker-compose file. You should also consider adding the .devcontainer directory to gitignore

Wohlen answered 12/12, 2020 at 19:32 Comment(1)
You should not add .devcontainer to .gitignore. What's the point in automating the creation of your development environment if you then do not treat your code as code?Nomarchy
Y
0

I found a workaround to solve this problem, you need to add the .git folder from the main repo as a mount like this:

devcontainer.json:

{
    "name": "Node.js",
    ...
    "mounts": [
        "source=${localWorkspaceFolder}/../.git,target=/workspaces/.git,type=bind,consistency=cached"
    ]
}
Yama answered 11/12, 2021 at 15:10 Comment(1)
Just a head's up for anyone that follows... this will also cause any tracked files outside of the ${localWorkspaceFolder} to be marked as Deleted in git.Psychotechnics

© 2022 - 2024 — McMap. All rights reserved.