From ac0c655366dba81d381fd618c2f13b9df21e6739 Mon Sep 17 00:00:00 2001 From: mfw78 <53399572+mfw78@users.noreply.github.com> Date: Fri, 15 Dec 2023 12:23:32 +0000 Subject: [PATCH] feat: devcontainer (#2156) # Description This PR presents a complete devcontainer environment for building with the CoW Protocol services repository. # Changes - [x] Build using the latest standard `rust` devcontainer - [x] Enhance the `rust` devcontainer with `gdb`, `valgrind`, and `heaptrack` - [x] Installs both `stable` and `nightly` toolchains, automatically configuring rust-analyzer to use `nightly` for `rustfmt` - [x] Includes `docker`, `postgresql-client` and `node` for development - [x] Configures the `zsh` shell - [x] Adjusts docker settings to enable trace capabilities for profiling development ## How to test 1. Open in VS Code and take it for a spin **Caution**: This can take a while to build the container environment on first start. --- .devcontainer/Dockerfile | 9 +++++ .devcontainer/devcontainer.json | 59 +++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 .devcontainer/Dockerfile create mode 100644 .devcontainer/devcontainer.json diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000000..b7de1cb612 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,9 @@ +FROM mcr.microsoft.com/devcontainers/base:bullseye + +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + # Remove imagemagick due to https://security-tracker.debian.org/tracker/CVE-2019-10131 + && apt-get purge -y imagemagick imagemagick-6-common + +# [Optional] Uncomment this section to install additional OS packages. +RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ + && apt-get -y install --no-install-recommends gdb valgrind heaptrack diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000000..c4d49550c8 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,59 @@ +{ + "build": { + "dockerfile": "./Dockerfile", + "context": "." + }, + "features": { + "ghcr.io/devcontainers/features/common-utils:2": { + "installZsh": true, + "configureZshAsDefaultShell": true, + "installOhMyZsh": true, + "installOhMyZshConfig": true, + "upgradePackages": true, + "username": "automatic", + "userUid": "automatic", + "userGid": "automatic" + }, + "ghcr.io/devcontainers/features/rust:1": {}, + "ghcr.io/devcontainers/features/git:1": {}, + "ghcr.io/nlordell/features/foundry": {}, + "ghcr.io/devcontainers/features/docker-in-docker:2": { + "dockerDashComposeVersion": "v2" + }, + "ghcr.io/robbert229/devcontainer-features/postgresql-client:1": {}, + "ghcr.io/devcontainers-contrib/features/zsh-plugins:0": { + "plugins": "npm git rust docker docker-compose git-prompt postgres", + "omzPlugins": "https://github.com/zsh-users/zsh-autosuggestions", + "username": "vscode" + } + }, + "runArgs": [ + "--cap-add=SYS_PTRACE", + "--security-opt", + "seccomp=unconfined" + ], + + "customizations": { + "vscode": { + "settings": { + "rust-analyzer.rustfmt.extraArgs": [ + "+nightly" + ] + }, + "extensions": [ + "rust-lang.rust-analyzer", + "serayuzgur.crates" + ] + } + }, + + // Use 'forwardPorts' to make a list of ports inside the container available locally. + // "forwardPorts": [], + + // Use 'postCreateCommand' to run commands after the container is created. + // "postCreateCommand": "rustc --version", + "postCreateCommand": "rustup toolchain install nightly && cargo install flamegraph", + + // Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. + "remoteUser": "vscode" +}