From 572c9940750fbc350c4372c834be3112ccea0dfc Mon Sep 17 00:00:00 2001 From: m-tartari <37861893+m-tartari@users.noreply.github.com> Date: Wed, 4 Dec 2024 16:54:24 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20feat:=20add=20devcontainer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .devcontainer/bash_prompt.sh | 24 +++++++ .devcontainer/devcontainer.json | 116 +++++++++++++++++++++++++++++++ .devcontainer/docker-compose.yml | 20 ++++++ .devcontainer/post_create.sh | 2 + 4 files changed, 162 insertions(+) create mode 100644 .devcontainer/bash_prompt.sh create mode 100644 .devcontainer/devcontainer.json create mode 100644 .devcontainer/docker-compose.yml create mode 100644 .devcontainer/post_create.sh diff --git a/.devcontainer/bash_prompt.sh b/.devcontainer/bash_prompt.sh new file mode 100644 index 0000000..6cc453f --- /dev/null +++ b/.devcontainer/bash_prompt.sh @@ -0,0 +1,24 @@ +# from https://github.com/devcontainers/features/blob/2951f0481a488ea43a6f2ea6f18a47f0a0bf744d/src/common-utils/scripts/bash_theme_snippet.sh#L20 +# bash theme - partly inspired by https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/robbyrussell.zsh-theme +__bash_prompt() { + local userpart='`export XIT=$? \ + && [ ! -z "${GITHUB_USER:-}" ] && echo -n "\[\033[0;32m\]@${GITHUB_USER:-} " || echo -n "\[\033[0;32m\]\u " \ + && [ "$XIT" -ne "0" ] && echo -n "\[\033[1;31m\]➜" || echo -n "\[\033[0m\]➜"`' + local gitbranch='`\ + if [ "$(git config --get devcontainers-theme.hide-status 2>/dev/null)" != 1 ] && [ "$(git config --get codespaces-theme.hide-status 2>/dev/null)" != 1 ]; then \ + export BRANCH="$(git --no-optional-locks symbolic-ref --short HEAD 2>/dev/null || git --no-optional-locks rev-parse --short HEAD 2>/dev/null)"; \ + if [ "${BRANCH:-}" != "" ]; then \ + echo -n "\[\033[0;36m\](\[\033[1;31m\]${BRANCH:-}" \ + && if [ "$(git config --get devcontainers-theme.show-dirty 2>/dev/null)" = 1 ] && \ + git --no-optional-locks ls-files --error-unmatch -m --directory --no-empty-directory -o --exclude-standard ":/*" > /dev/null 2>&1; then \ + echo -n " \[\033[1;33m\]✗"; \ + fi \ + && echo -n "\[\033[0;36m\]) "; \ + fi; \ + fi`' + local lightblue='\[\033[1;34m\]' + local removecolor='\[\033[0m\]' + PS1="${userpart} ${lightblue}\w ${gitbranch}${removecolor}\$ " + unset -f __bash_prompt +} +__bash_prompt diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..53b5602 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,116 @@ +// 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": "m-tartari.github.io", + // 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.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": "devcontainer", + // 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}", + // Features to add to the dev container. More info: https://containers.dev/features. + "features": { + "ghcr.io/devcontainers/features/docker-outside-of-docker:1": {} + }, + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + // Uncomment the next line if you want start specific services in your Docker Compose config. + // "runServices": [], + // Uncomment the next line if you want to keep your containers running after VS Code shuts down. + // "shutdownAction": "none", + // Uncomment the next line to run commands after the container is created. + "postCreateCommand": "bash .devcontainer/post_create.sh", + "postStartCommand": "npm ci", + // Configure tool-specific properties. + "customizations": { + "vscode": { + "settings": { + // Workbench + "workbench.iconTheme": "vscode-icons", + // Files + "files.trimTrailingWhitespace": true, + "files.insertFinalNewline": true, + "files.trimFinalNewlines": true, + "files.exclude": { + "**/*.pyc": true, + "**/.git": false + }, + // Editor & Linting + "prettier.printWidth": 150, + "editor.suggestSelection": "first", + "editor.defaultFormatter": "esbenp.prettier-vscode", + "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue", + "editor.detectIndentation": true, + "editor.insertSpaces": true, + "editor.tabSize": 2, + "editor.formatOnPaste": true, + "editor.formatOnSave": true, + "editor.formatOnType": true, + "editor.codeActionsOnSave": { + "source.fixAll.eslint": "explicit" + }, + "editor.tokenColorCustomizations": { + "textMateRules": [ + { + "scope": [ + "comment" + ], + "settings": { + "fontStyle": "italic" + } + } + ] + }, + // git + "git.autofetch": true, + "git.confirmSync": false, + "git.enableSmartCommit": true, + "git-graph.dialog.rebase.ignoreDate": false, + "diffEditor.ignoreTrimWhitespace": false, + "diffEditor.wordWrap": "off", + // Javascript + "javascript.updateImportsOnFileMove.enabled": "always", + "typescript.preferences.importModuleSpecifier": "non-relative", + "typescript.updateImportsOnFileMove.enabled": "always", + "typescript.suggest.paths": true, + // JSON + "[json,jsonc]": { + "editor.defaultFormatter": "vscode.json-language-features", + "json.format.enable": true + }, + // Testing + "vitest.enable": true + }, + "extensions": [ + "adam-bender.commit-message-editor", + "christian-kohler.path-intellisense", + "codezombiech.gitignore", + "davidanson.vscode-markdownlint", + "dbaeumer.vscode-eslint", + "esbenp.prettier-vscode", + "firefox-devtools.vscode-firefox-debug", + "formulahendry.auto-close-tag", + "formulahendry.auto-rename-tag", + "github.copilot", + "github.copilot-chat", + "gruntfuggly.todo-tree", + "ibm.output-colorizer", + "mhutchie.git-graph", + "ms-azuretools.vscode-docker", + "naumovs.color-highlight", + "streetsidesoftware.code-spell-checker", + "vitest.explorer", + "vscode-icons-team.vscode-icons", + "waderyan.gitblame", + "wayou.vscode-todo-highlight" + ] + } + } + // Uncomment to connect as an existing user other than the container default. More info: https://aka.ms/dev-containers-non-root. + // "remoteUser": "devcontainer" +} diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..6da77a2 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,20 @@ +services: + devcontainer: + image: m-tartari.github.io-dev + build: + context: .. + dockerfile: Dockerfile + target: development + container_name: devcontainer-m-tartari.github.io + hostname: m-tartari.github.io-dev + command: sleep infinity + ports: + - '5173:5173' + - '4173:4173' + volumes: + - ..:/workspaces/m-tartari.github.io:cached + # Uncomment the next four lines if you will use a ptrace-based debugger like C++, Go, and Rust. + # cap_add: + # - SYS_PTRACE + # security_opt: + # - seccomp:unconfined diff --git a/.devcontainer/post_create.sh b/.devcontainer/post_create.sh new file mode 100644 index 0000000..1fd30bb --- /dev/null +++ b/.devcontainer/post_create.sh @@ -0,0 +1,2 @@ +# Update the bash PS1 to include git details +cat .devcontainer/bash_prompt.sh >> $HOME/.bashrc