From 07011f2b624f54ba3d55d1cc3392c42699712092 Mon Sep 17 00:00:00 2001
From: Piotr Spieker
Date: Fri, 15 Nov 2024 16:29:43 +0100
Subject: [PATCH] Add a VSCode DevContainer for the tutorial
---
demo/.devcontainer/.zshrc | 89 +++++++++++++++++++++++++++
demo/.devcontainer/Dockerfile | 25 ++++++++
demo/.devcontainer/devcontainer.json | 44 +++++++++++++
demo/.devcontainer/docker-compose.yml | 13 ++++
demo/.vscode/launch.json | 16 +++++
demo/.vscode/tasks.json | 28 +++++++++
demo/README.md | 13 +++-
7 files changed, 227 insertions(+), 1 deletion(-)
create mode 100644 demo/.devcontainer/.zshrc
create mode 100644 demo/.devcontainer/Dockerfile
create mode 100644 demo/.devcontainer/devcontainer.json
create mode 100644 demo/.devcontainer/docker-compose.yml
create mode 100644 demo/.vscode/launch.json
create mode 100644 demo/.vscode/tasks.json
diff --git a/demo/.devcontainer/.zshrc b/demo/.devcontainer/.zshrc
new file mode 100644
index 00000000..5875b839
--- /dev/null
+++ b/demo/.devcontainer/.zshrc
@@ -0,0 +1,89 @@
+# >>> reference: https://carlosneto.dev/blog/2024/2024-02-08-starship-zsh/
+
+# list files with details
+alias ll="ls -larht"
+
+
+# set the locale of the shell
+export LANG="en_US.UTF-8"
+
+# define VSCode as the default text editor
+export EDITOR="code -w"
+
+# specify characters considered as word boundaries for command line navigation
+export WORDCHARS=""
+
+# set the location and filename of the history file
+export HISTFILE="$HOME/.zsh_history"
+
+# set the maximum number of lines to be saved in the history file
+export HISTSIZE="100000"
+export SAVEHIST="$HISTSIZE"
+
+# disable CTRL + S and CTRL + Q
+stty -ixon
+
+# enable comments "#" expressions in the prompt shell
+setopt INTERACTIVE_COMMENTS
+
+# append new history entries to the history file
+setopt APPEND_HISTORY
+
+# save each command to the history file as soon as it is executed
+setopt INC_APPEND_HISTORY
+
+# ignore recording duplicate consecutive commands in the history
+setopt HIST_IGNORE_DUPS
+
+# ignore commands that start with a space in the history
+setopt HIST_IGNORE_SPACE
+
+# >>> bindkey tip: to discovery the code of your keys, execute "$ cat -v" and press the key, the code will be printed in your shell.
+
+# use the ZLE (zsh line editor) in emacs mode. Useful to move the cursor in large commands
+bindkey -e
+
+# navigate words using Ctrl + arrow keys
+# >>> CRTL + right arrow | CRTL + left arrow
+bindkey "^[[1;5C" forward-word
+bindkey "^[[1;5D" backward-word
+
+# macosx override
+if [[ "$OSTYPE" == "darwin"* ]]; then
+ # >>> OPT + right arrow | OPT + left arrow
+ bindkey "^[^[[C" forward-word
+ bindkey "^[^[[D" backward-word
+fi
+
+# search history using Up and Down keys
+# >>> up arrow | down arrow
+bindkey "^[[A" history-beginning-search-backward
+bindkey "^[[B" history-beginning-search-forward
+
+# jump to the start and end of the command line
+# >>> CTRL + A | CTRL + E
+bindkey "^A" beginning-of-line
+bindkey "^E" end-of-line
+# >>> Home | End
+bindkey "^[[H" beginning-of-line
+bindkey "^[[F" end-of-line
+
+# navigate menu for command output
+zstyle ':completion:*:*:*:*:*' menu select
+bindkey '^[[Z' reverse-menu-complete
+
+# delete characters using the "delete" key
+bindkey "^[[3~" delete-char
+
+
+# >>> load ZSH plugin
+
+# enable kubectl plugin autocompletion
+autoload -Uz compinit
+compinit
+
+
+# start Starship prompt
+eval "$(starship init zsh)"
+
+source /home/blinky/.motd
\ No newline at end of file
diff --git a/demo/.devcontainer/Dockerfile b/demo/.devcontainer/Dockerfile
new file mode 100644
index 00000000..72ca2e1a
--- /dev/null
+++ b/demo/.devcontainer/Dockerfile
@@ -0,0 +1,25 @@
+ARG VERSION=latest
+
+FROM ghcr.io/kit-mrt/arbitration_graphs_pacman_tutorial:$VERSION
+
+USER root
+
+# Install clangd for the VSCode extension to work out of the box
+# Install zsh and tig as modern dev tools
+RUN apt-get update && \
+ apt-get install -y --no-install-recommends \
+ clangd \
+ curl \
+ tig \
+ zsh && \
+ apt-get clean
+
+# Install and use starship terminal prompt
+RUN curl https://starship.rs/install.sh > /tmp/starship_install.sh && \
+ chmod +x /tmp/starship_install.sh && \
+ /tmp/starship_install.sh -y && \
+ rm /tmp/starship_install.sh
+
+COPY .devcontainer/.zshrc /home/blinky/.zshrc
+
+USER blinky
diff --git a/demo/.devcontainer/devcontainer.json b/demo/.devcontainer/devcontainer.json
new file mode 100644
index 00000000..d83ac6f0
--- /dev/null
+++ b/demo/.devcontainer/devcontainer.json
@@ -0,0 +1,44 @@
+// For format details, see https://aka.ms/devcontainer.json. For config options, see the
+// README at: https://github.com/devcontainers/templates/tree/main/src/docker-existing-docker-compose
+{
+ "name": "Arbitration Graphs Tutorial",
+
+ // Update the 'dockerComposeFile' list if you have more compose files or use different names.
+ // The .devcontainer/docker-compose.yml file contains any overrides you need/want to make.
+ "dockerComposeFile": [
+ "../docker-compose.tutorial.yaml",
+ "docker-compose.yml"
+ ],
+
+ // The 'service' property is the name of the service for the container that VS Code should
+ // use. Update this value and .devcontainer/docker-compose.yml to the real service name.
+ "service": "tutorial",
+
+ // The optional 'workspaceFolder' property is the path VS Code should open by default when
+ // connected. This is typically a file mount in .devcontainer/docker-compose.yml
+ "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",
+ "customizations": {
+ "vscode": {
+ // Install some useful VSCode C++ extensions
+ "extensions": [
+ "llvm-vs-code-extensions.vscode-clangd",
+ "vadimcn.vscode-lldb",
+ "matepek.vscode-catch2-test-adapter",
+ "twxs.cmake"
+ ],
+ "settings": {
+ // Use zsh as default terminal
+ "terminal.integrated.profiles.linux": {
+ "zsh": {
+ "path": "/bin/zsh",
+ "args": ["-l", "-i"]
+ }
+ },
+ "terminal.integrated.defaultProfile.linux": "zsh",
+
+ // Use system installation of clangd
+ "clangd.path": "clangd"
+ }
+ }
+ }
+}
diff --git a/demo/.devcontainer/docker-compose.yml b/demo/.devcontainer/docker-compose.yml
new file mode 100644
index 00000000..77fba341
--- /dev/null
+++ b/demo/.devcontainer/docker-compose.yml
@@ -0,0 +1,13 @@
+version: '3.8'
+services:
+ tutorial:
+ build:
+ context: .
+ dockerfile: .devcontainer/Dockerfile
+
+ volumes:
+ - ..:/workspaces:cached
+
+ # Overrides default command so things don't shut down after the process ends.
+ command: sleep infinity
+
diff --git a/demo/.vscode/launch.json b/demo/.vscode/launch.json
new file mode 100644
index 00000000..ca4040dc
--- /dev/null
+++ b/demo/.vscode/launch.json
@@ -0,0 +1,16 @@
+{
+ // Use IntelliSense to learn about possible attributes.
+ // Hover to view descriptions of existing attributes.
+ // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
+ "version": "0.2.0",
+ "configurations": [
+ {
+ "type": "lldb",
+ "request": "launch",
+ "name": "Debug Pacman Demo",
+ "program": "${workspaceFolder}/build/arbitration_graphs_pacman_demo",
+ "args": [],
+ "cwd": "${workspaceFolder}"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/demo/.vscode/tasks.json b/demo/.vscode/tasks.json
new file mode 100644
index 00000000..e0db91d6
--- /dev/null
+++ b/demo/.vscode/tasks.json
@@ -0,0 +1,28 @@
+{
+ // See https://go.microsoft.com/fwlink/?LinkId=733558
+ // for the documentation about the tasks.json format
+ "version": "2.0.0",
+ "tasks": [
+ {
+ "label": "Create build folder",
+ "type": "shell",
+ "command": "mkdir -p ${workspaceFolder}/build"
+ },
+ {
+ "label": "CMake build for debug",
+ "dependsOn": ["Create build folder"],
+ "type": "shell",
+ "command": "cmake -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=true -S ${workspaceFolder} -B ${workspaceFolder}/build",
+ "group": {
+ "kind": "build",
+ "isDefault": true
+ }
+ },
+ {
+ "label": "CMake build for release",
+ "dependsOn": ["Create build folder"],
+ "type": "shell",
+ "command": "cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTS=true -S ${workspaceFolder} -B ${workspaceFolder}/build"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/demo/README.md b/demo/README.md
index 834175e3..03a3f39b 100644
--- a/demo/README.md
+++ b/demo/README.md
@@ -17,4 +17,15 @@ Open the GUI with your favorite browser:
## Tutorial
-If you're here for the tutorial, follow the instructions on our [Tutorial GitHub Page](https://kit-mrt.github.io/arbitration_graphs/docs/Tutorial.md).
\ No newline at end of file
+If you're here for the tutorial, follow the instructions on our [Tutorial GitHub Page](https://kit-mrt.github.io/arbitration_graphs/docs/Tutorial.md).
+
+For a smooth out-of-the-box experience, we recommend using [Visual Studio Code](https://code.visualstudio.com/) with our DevContainer setup.
+
+- Open this folder in VSCode
+- Build and open the Dev Container by running this [command](https://code.visualstudio.com/docs/getstarted/userinterface#_command-palette) (use `Ctrl+Shift+P`):
+ `Dev Containers: Reopen in Container`
+- Enjoy a full-blown IDE with code-completion, code-navigation etc.
+ - Compile via `Ctrl+Shift+B`
+ - View, run and debug unit tests via [Testing](https://code.visualstudio.com/docs/editor/testing) sidebar
+ - Debug the PacMan Demo via [Run and Debug](https://code.visualstudio.com/docs/editor/debugging) sidebar
+ - Debug with breakpoints etc.
\ No newline at end of file