Skip to content

Commit 9f26b3d

Browse files
Merge pull request #109 from Synicix/worktree-docker-patch
Update gpu/docker to include new git version to support git worktree
2 parents a713eaa + 1c6203e commit 9f26b3d

File tree

4 files changed

+77
-22
lines changed

4 files changed

+77
-22
lines changed

.devcontainer/gpu/Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,16 @@ RUN \
1010
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \
1111
apt-get update && \
1212
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y && \
13-
usermod -aG docker root && \
14-
apt-get clean
13+
usermod -aG docker root
14+
15+
RUN apt-get install software-properties-common -y && \
16+
apt-add-repository ppa:git-core/ppa && \
17+
apt-get install git -y
1518

1619
RUN \
1720
# dev setup
1821
apt update && \
19-
apt-get install build-essential sudo jq git bash-completion graphviz rsync -y && \
22+
apt-get install build-essential sudo jq bash-completion graphviz rsync software-properties-common -y && \
2023
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers && \
2124
echo '. /etc/bash_completion' >> /root/.bashrc && \
2225
echo 'export PS1="\[\e[32;1m\]\u\[\e[m\]@\[\e[34;1m\]\H\[\e[m\]:\[\e[33;1m\]\w\[\e[m\]$ "' >> /root/.bashrc && \

.devcontainer/gpu/devcontainer.json

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
11
{
2-
"name": "Development (GPU)",
3-
"build": {
4-
"dockerfile": "Dockerfile",
5-
"context": "../.."
6-
},
7-
"overrideCommand": false,
2+
"name": "Development-GPU",
3+
"dockerComposeFile": "./docker-compose.yaml",
4+
"service": "ide",
85
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
9-
"mounts": [
10-
"source=${localWorkspaceFolderBasename}_devcontainer_docker_data,target=/var/lib/docker,type=volume"
11-
],
12-
"remoteEnv": {
13-
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}",
14-
"RUST_BACKTRACE": "1"
15-
},
6+
"initializeCommand": ".devcontainer/gpu/make_env_file.py ${localWorkspaceFolder}",
167
"postStartCommand": "mkdir -p tests/.tmp && docker system prune -fa && docker volume prune -f",
178
"hostRequirements": {
189
"cpus": 2,
1910
"memory": "8gb",
2011
"storage": "32gb"
2112
},
22-
"runArgs": [
23-
"--name=${localWorkspaceFolderBasename}_devcontainer",
24-
"--gpus=all",
25-
"--privileged",
26-
"--cgroupns=host"
27-
],
2813
"customizations": {
2914
"vscode": {
3015
"extensions": [
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
services:
2+
ide:
3+
build:
4+
context: ..
5+
dockerfile: ./gpu/Dockerfile
6+
privileged: true # Docker-in-Docker needs this
7+
cgroup: host # Allow setting resource constraints (e.g. memory, cpu) for containers
8+
environment:
9+
- RUST_BACKTRACE=1 # Display error trace on errors/panics
10+
volumes:
11+
- ${LOCAL_WORKSPACE_PATH}:${ENV_WORKSPACE_PATH} # source
12+
- docker_data:/var/lib/docker # Docker image cache
13+
- ${LOCAL_GIT_PATH}:${ENV_GIT_PATH} # Base Git worktree history
14+
deploy:
15+
resources:
16+
reservations:
17+
devices:
18+
- driver: nvidia
19+
count: all
20+
capabilities: [gpu]
21+
volumes:
22+
docker_data:

.devcontainer/gpu/make_env_file.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/usr/bin/env python3
2+
#
3+
# assumes git worktree was made using relative paths e.g.
4+
# git worktree add ../dir-name branch-name --relative-paths
5+
import sys
6+
from pathlib import Path
7+
from textwrap import dedent
8+
import subprocess
9+
from os.path import relpath
10+
11+
12+
def make_config(local_workspace_path: Path):
13+
env_workspace_path = Path(f"/workspaces/{local_workspace_path.name}")
14+
local_git_path = Path(
15+
subprocess.run(
16+
"git rev-parse --path-format=absolute --git-common-dir".split(" "),
17+
capture_output=True,
18+
text=True,
19+
).stdout.strip()
20+
)
21+
env_git_path = (
22+
env_workspace_path / ".git"
23+
if local_workspace_path / ".git" == local_git_path
24+
else (
25+
env_workspace_path
26+
/ relpath(local_git_path.parent, local_workspace_path)
27+
/ ".git"
28+
).resolve()
29+
)
30+
31+
return dedent(
32+
f"""
33+
LOCAL_WORKSPACE_PATH={local_workspace_path}
34+
ENV_WORKSPACE_PATH={env_workspace_path}
35+
LOCAL_GIT_PATH={local_git_path}
36+
ENV_GIT_PATH={env_git_path}
37+
"""
38+
).strip()
39+
40+
41+
if __name__ == "__main__":
42+
local_workspace_path = Path(sys.argv[1])
43+
44+
with open(Path(__file__).absolute().parent / ".env", "w") as f:
45+
f.write(make_config(local_workspace_path))

0 commit comments

Comments
 (0)