Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 23 additions & 15 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,40 @@
# DevContainer image
FROM rust:1.87-slim
FROM ubuntu:24.04
RUN \
adduser --system --disabled-password --shell /bin/bash --home /home/vscode vscode && \
# install docker
apt-get update && \
apt-get install ca-certificates curl gnupg lsb-release -y && \
apt-get install ca-certificates curl -y && \
mkdir -m 0755 -p /etc/apt/keyrings && \
curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg && \
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 && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc && \
chmod a+r /etc/apt/keyrings/docker.asc && \
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "${UBUNTU_CODENAME:-$VERSION_CODENAME}") stable" | \
tee /etc/apt/sources.list.d/docker.list > /dev/null && \
apt-get update && \
apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y && \
usermod -aG docker vscode && \
usermod -aG docker ubuntu && \
apt-get clean
RUN \
# dev setup
apt update && \
apt-get install sudo jq git bash-completion graphviz rsync -y && \
usermod -aG sudo vscode && \
apt-get install sudo jq bash-completion graphviz rsync software-properties-common gcc -y && \
add-apt-repository ppa:git-core/ppa && \
apt update && \
apt-get install git -y && \
usermod -aG sudo ubuntu && \
echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers && \
echo '. /etc/bash_completion' >> /home/vscode/.bashrc && \
echo 'export PS1="\[\e[32;1m\]\u\[\e[m\]@\[\e[34;1m\]\H\[\e[m\]:\[\e[33;1m\]\w\[\e[m\]$ "' >> /home/vscode/.bashrc && \
chown vscode:nogroup /home/vscode/.bashrc && \
echo '. /etc/bash_completion' >> /home/ubuntu/.bashrc && \
echo 'export PS1="\[\e[32;1m\]\u\[\e[m\]@\[\e[34;1m\]\H\[\e[m\]:\[\e[33;1m\]\w\[\e[m\]$ "' >> /home/ubuntu/.bashrc && \
chown ubuntu:nogroup /home/ubuntu/.bashrc && \
apt-get clean

USER vscode
ENV CARGO_HOME=/home/vscode/.cargo \
PATH=/home/vscode/.cargo/bin:/home/vscode/.local/bin:$PATH
USER ubuntu
ENV CARGO_HOME=/home/ubuntu/.cargo \
PATH=/home/ubuntu/.cargo/bin:/home/ubuntu/.local/bin:$PATH
RUN \
# install rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain=1.87.0 -y && \
# rust auto formatting
rustup component add rustfmt && \
# rust style linter
Expand All @@ -47,5 +55,5 @@ RUN \
# useful in examples
uv pip install ipykernel eclipse-zenoh -p ~/.local/share/base && \
echo '. ~/.local/share/base/bin/activate' >> ~/.bashrc
ENV VIRTUAL_ENV=/home/vscode/.local/share/base
ENV VIRTUAL_ENV=/home/ubuntu/.local/share/base
CMD ["bash", "-c", "sudo rm /var/run/docker.pid; sudo dockerd"]
20 changes: 3 additions & 17 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,15 @@
{
"name": "Development",
"build": {
"dockerfile": "Dockerfile",
"context": ".."
},
"overrideCommand": false,
"dockerComposeFile": "docker-compose.yaml",
"service": "ide",
"workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
"mounts": [
"source=${localWorkspaceFolderBasename}_devcontainer_docker_data,target=/var/lib/docker,type=volume"
],
"remoteEnv": {
"LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}",
"RUST_BACKTRACE": "1"
},
"initializeCommand": ".devcontainer/make_env_file.py ${localWorkspaceFolder}",
"postStartCommand": "mkdir -p tests/.tmp && docker system prune -fa && docker volume prune -f",
"hostRequirements": {
"cpus": 2,
"memory": "8gb",
"storage": "32gb"
},
"runArgs": [
"--name=${localWorkspaceFolderBasename}_devcontainer",
"--privileged",
"--cgroupns=host"
],
"customizations": {
"vscode": {
"extensions": [
Expand Down
15 changes: 15 additions & 0 deletions .devcontainer/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
services:
ide:
build:
context: ..
dockerfile: .devcontainer/Dockerfile
privileged: true # Docker-in-Docker needs this
cgroup: host # Allow setting resource constraints (e.g. memory, cpu) for containers
environment:
- RUST_BACKTRACE=1 # Display error trace on errors/panics
volumes:
- ${LOCAL_WORKSPACE_PATH}:${ENV_WORKSPACE_PATH} # source
- docker_data:/var/lib/docker # Docker image cache
- ${LOCAL_GIT_PATH}:${ENV_GIT_PATH} # Base Git worktree history
volumes:
docker_data:
45 changes: 45 additions & 0 deletions .devcontainer/make_env_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#!/usr/bin/env python3
#
# assumes git worktree was made using relative paths e.g.
# git worktree add ../dir-name branch-name --relative-paths
import sys
from pathlib import Path
from textwrap import dedent
import subprocess
from os.path import relpath


def make_config(local_workspace_path: Path):
env_workspace_path = Path(f"/workspaces/{local_workspace_path.name}")
local_git_path = Path(
subprocess.run(
"git rev-parse --path-format=absolute --git-common-dir".split(" "),
capture_output=True,
text=True,
).stdout.strip()
)
env_git_path = (
env_workspace_path / ".git"
if local_workspace_path / ".git" == local_git_path
else (
env_workspace_path
/ relpath(local_git_path.parent, local_workspace_path)
/ ".git"
).resolve()
)

return dedent(
f"""
LOCAL_WORKSPACE_PATH={local_workspace_path}
ENV_WORKSPACE_PATH={env_workspace_path}
LOCAL_GIT_PATH={local_git_path}
ENV_GIT_PATH={env_git_path}
"""
).strip()


if __name__ == "__main__":
local_workspace_path = Path(sys.argv[1])

with open(Path(__file__).absolute().parent / ".env", "w") as f:
f.write(make_config(local_workspace_path))
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ lcov.info
*.tar.gz
*.dot
tests/.tmp
*.pyc
24 changes: 14 additions & 10 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
{
"editor.formatOnPaste": false,
"editor.formatOnSave": true,
"files.insertFinalNewline": true,
"editor.rulers": [
100
],
"files.autoSave": "off",
"files.insertFinalNewline": true,
"[markdown]": {
"editor.defaultFormatter": null
},
"gitlens.showWelcomeOnInstall": false,
"gitlens.showWhatsNewAfterUpgrades": false,
"lldb.consoleMode": "evaluate",
"rust-analyzer.check.command": "clippy",
"rust-analyzer.runnables.extraTestBinaryArgs": [
"--nocapture"
],
"rust-analyzer.rustfmt.extraArgs": [
"--config",
"max_width=100"
],
"rust-analyzer.check.command": "clippy",
"rust-analyzer.runnables.extraTestBinaryArgs": [
"--nocapture"
"jupyter.kernels.excludePythonEnvironments": [
"/bin/python3",
"/usr/bin/python3",
],
"files.autoSave": "off",
"gitlens.showWelcomeOnInstall": false,
"gitlens.showWhatsNewAfterUpgrades": false,
"lldb.consoleMode": "evaluate",
"notebook.formatOnSave.enabled": true,
"notebook.output.scrolling": true,
"python.defaultInterpreterPath": "~/.local/share/base/bin/python3",
"python.terminal.activateEnvironment": false,
"notebook.formatOnSave.enabled": true,
"notebook.output.scrolling": true
}