Skip to content

Commit 74c2612

Browse files
authored
Merge pull request #107 from guzman-raphael/git-worktree
Enable using Git Worktrees
2 parents 80c09a6 + 47c86d1 commit 74c2612

File tree

6 files changed

+101
-42
lines changed

6 files changed

+101
-42
lines changed

.devcontainer/Dockerfile

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,40 @@
11
# DevContainer image
2-
FROM rust:1.87-slim
2+
FROM ubuntu:24.04
33
RUN \
4-
adduser --system --disabled-password --shell /bin/bash --home /home/vscode vscode && \
54
# install docker
65
apt-get update && \
7-
apt-get install ca-certificates curl gnupg lsb-release -y && \
6+
apt-get install ca-certificates curl -y && \
87
mkdir -m 0755 -p /etc/apt/keyrings && \
9-
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
10-
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \
8+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc && \
9+
chmod a+r /etc/apt/keyrings/docker.asc && \
10+
echo \
11+
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
12+
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
13+
tee /etc/apt/sources.list.d/docker.list > /dev/null && \
1114
apt-get update && \
1215
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y && \
13-
usermod -aG docker vscode && \
16+
usermod -aG docker ubuntu && \
1417
apt-get clean
1518
RUN \
1619
# dev setup
1720
apt update && \
18-
apt-get install sudo jq git bash-completion graphviz rsync -y && \
19-
usermod -aG sudo vscode && \
21+
apt-get install sudo jq bash-completion graphviz rsync software-properties-common gcc -y && \
22+
add-apt-repository ppa:git-core/ppa && \
23+
apt update && \
24+
apt-get install git -y && \
25+
usermod -aG sudo ubuntu && \
2026
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers && \
21-
echo '. /etc/bash_completion' >> /home/vscode/.bashrc && \
22-
echo 'export PS1="\[\e[32;1m\]\u\[\e[m\]@\[\e[34;1m\]\H\[\e[m\]:\[\e[33;1m\]\w\[\e[m\]$ "' >> /home/vscode/.bashrc && \
23-
chown vscode:nogroup /home/vscode/.bashrc && \
27+
echo '. /etc/bash_completion' >> /home/ubuntu/.bashrc && \
28+
echo 'export PS1="\[\e[32;1m\]\u\[\e[m\]@\[\e[34;1m\]\H\[\e[m\]:\[\e[33;1m\]\w\[\e[m\]$ "' >> /home/ubuntu/.bashrc && \
29+
chown ubuntu:nogroup /home/ubuntu/.bashrc && \
2430
apt-get clean
2531

26-
USER vscode
27-
ENV CARGO_HOME=/home/vscode/.cargo \
28-
PATH=/home/vscode/.cargo/bin:/home/vscode/.local/bin:$PATH
32+
USER ubuntu
33+
ENV CARGO_HOME=/home/ubuntu/.cargo \
34+
PATH=/home/ubuntu/.cargo/bin:/home/ubuntu/.local/bin:$PATH
2935
RUN \
36+
# install rust
37+
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain=1.87.0 -y && \
3038
# rust auto formatting
3139
rustup component add rustfmt && \
3240
# rust style linter
@@ -47,5 +55,5 @@ RUN \
4755
# useful in examples
4856
uv pip install ipykernel eclipse-zenoh -p ~/.local/share/base && \
4957
echo '. ~/.local/share/base/bin/activate' >> ~/.bashrc
50-
ENV VIRTUAL_ENV=/home/vscode/.local/share/base
58+
ENV VIRTUAL_ENV=/home/ubuntu/.local/share/base
5159
CMD ["bash", "-c", "sudo rm /var/run/docker.pid; sudo dockerd"]

.devcontainer/devcontainer.json

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,15 @@
11
{
22
"name": "Development",
3-
"build": {
4-
"dockerfile": "Dockerfile",
5-
"context": ".."
6-
},
7-
"overrideCommand": false,
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/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-
"--privileged",
25-
"--cgroupns=host"
26-
],
2713
"customizations": {
2814
"vscode": {
2915
"extensions": [

.devcontainer/docker-compose.yaml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
services:
2+
ide:
3+
build:
4+
context: ..
5+
dockerfile: .devcontainer/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+
volumes:
15+
docker_data:

.devcontainer/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))

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ lcov.info
66
*.tar.gz
77
*.dot
88
tests/.tmp
9+
*.pyc

.vscode/settings.json

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
{
22
"editor.formatOnPaste": false,
33
"editor.formatOnSave": true,
4-
"files.insertFinalNewline": true,
54
"editor.rulers": [
65
100
76
],
7+
"files.autoSave": "off",
8+
"files.insertFinalNewline": true,
89
"[markdown]": {
910
"editor.defaultFormatter": null
1011
},
12+
"gitlens.showWelcomeOnInstall": false,
13+
"gitlens.showWhatsNewAfterUpgrades": false,
14+
"lldb.consoleMode": "evaluate",
15+
"rust-analyzer.check.command": "clippy",
16+
"rust-analyzer.runnables.extraTestBinaryArgs": [
17+
"--nocapture"
18+
],
1119
"rust-analyzer.rustfmt.extraArgs": [
1220
"--config",
1321
"max_width=100"
1422
],
15-
"rust-analyzer.check.command": "clippy",
16-
"rust-analyzer.runnables.extraTestBinaryArgs": [
17-
"--nocapture"
23+
"jupyter.kernels.excludePythonEnvironments": [
24+
"/bin/python3",
25+
"/usr/bin/python3",
1826
],
19-
"files.autoSave": "off",
20-
"gitlens.showWelcomeOnInstall": false,
21-
"gitlens.showWhatsNewAfterUpgrades": false,
22-
"lldb.consoleMode": "evaluate",
27+
"notebook.formatOnSave.enabled": true,
28+
"notebook.output.scrolling": true,
2329
"python.defaultInterpreterPath": "~/.local/share/base/bin/python3",
2430
"python.terminal.activateEnvironment": false,
25-
"notebook.formatOnSave.enabled": true,
26-
"notebook.output.scrolling": true
2731
}

0 commit comments

Comments
 (0)