Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify devcontainer setup #23

Closed
abdes opened this issue Dec 12, 2022 · 0 comments
Closed

Simplify devcontainer setup #23

abdes opened this issue Dec 12, 2022 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@abdes
Copy link
Owner

abdes commented Dec 12, 2022

Dev container setup for vscode can be greatly simplified by using devcontainer features and additional container lifecycle commands.

The Dockerfile can be simplified to the following:

ARG VARIANT=debian-11
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.205.2/containers/python-3/.devcontainer/base.Dockerfile
FROM mcr.microsoft.com/vscode/devcontainers/cpp:0-${VARIANT}

RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
  && apt-get -y install lsb-release wget software-properties-common

RUN export DEBIAN_FRONTEND=noninteractive \
  && apt-get -y install build-essential ninja-build valgrind gdb lcov doxygen graphviz

# Install latest cmake 3.22 so we have support for cmake presets and a better integration in IDEs
RUN wget https://github.com/Kitware/CMake/releases/download/v3.22.0/cmake-3.22.0-linux-x86_64.sh \
  -q -O /tmp/cmake-install.sh \
  && chmod u+x /tmp/cmake-install.sh \
  && /tmp/cmake-install.sh --skip-license --prefix=/usr \
  && rm /tmp/cmake-install.sh

# Install clang-14
RUN wget -qO - https://apt.llvm.org/llvm-snapshot.gpg.key | apt-key add -
RUN add-apt-repository 'deb http://apt.llvm.org/bullseye/ llvm-toolchain-bullseye-14 main'
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
  && apt-get -y install clang-14 clangd-14 lldb-14 llvm-14 clang-format-14 clang-tidy-14

RUN update-alternatives --install /usr/bin/clang clang /usr/bin/clang-14 100
RUN update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-14 100
RUN update-alternatives --install /usr/bin/clang-apply-replacements clang-apply-replacements /usr/bin/clang-apply-replacements-14 100
RUN update-alternatives --install /usr/bin/clang-check clang-check /usr/bin/clang-check-14 100
RUN update-alternatives --install /usr/bin/clang-query clang-query /usr/bin/clang-query-14 100
RUN update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-14 100
RUN update-alternatives --install /usr/bin/clang-format clang-format /usr/bin/clang-format-14 100
RUN update-alternatives --install /usr/bin/scan-build scan-build /usr/bin/scan-build-14 100
RUN update-alternatives --install /usr/bin/scan-view scan-view /usr/bin/scan-view-14 100
RUN update-alternatives --install /usr/bin/llvm-cov llvm-cov /usr/bin/llvm-cov-14 100
RUN update-alternatives --install /usr/bin/llvm-profdata llvm-profdata /usr/bin/llvm-profdata-14 100

# Install ccache
RUN apt-get -y install ccache

# Clean-up
RUN apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*

The devcontainer.json gets enhanced as following:

// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.205.2/containers/python-3
{
  "name": "asap_dev",
  "build": {
    "dockerfile": "Dockerfile",
    "context": "..",
    "args": {
      // Update 'VARIANT' to pick a Python version: 3, 3.10, 3.9, 3.8, 3.7, 3.6
      // Append -bullseye or -buster to pin to an OS version.
      // Use -bullseye variants on local on arm64/Apple Silicon.
      "VARIANT": "debian-11"
    }
  },
  "features": {
    "ghcr.io/devcontainers/features/common-utils:1": {
      "configureZshAsDefaultShell": true,
      "userName": "vscode",
      "uid": "1000",
      "gid": "1000"
    },
    "ghcr.io/devcontainers/features/node:1": {
      "version": "16"
    },
    "ghcr.io/devcontainers/features/python:1": {
      "version": "os-provided"
    }
  },
  // Set *default* container specific settings.json values on container create.
  "settings": {
    "python.defaultInterpreterPath": "/usr/local/bin/python",
    "python.linting.enabled": true,
    "python.linting.pylintEnabled": true,
    "python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
    "python.formatting.blackPath": "/usr/local/py-utils/bin/black",
    "python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
    "python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
    "python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
    "python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
    "python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
    "python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
    "python.linting.pylintPath": "/usr/local/py-utils/bin/pylint",
    "clangd.path": "/usr/bin/clangd-14"
  },
  // Add the IDs of extensions you want installed when the container is created.
  "extensions": [
    "ms-python.python",
    "ms-python.vscode-pylance",
    "ms-vscode.cpptools",
    "matepek.vscode-catch2-test-adapter",
    "llvm-vs-code-extensions.vscode-clangd",
    "twxs.cmake",
    "ms-vscode.cmake-tools",
    "swyddfa.esbonio",
    "eamodio.gitlens",
    "hbenl.vscode-test-explorer",
    "guyutongxue.cpp-reference",
    "cheshirekow.cmake-format",
    "kevinkyang.auto-comment-blocks",
    "editorconfig.editorconfig"
  ],
  // Use 'forwardPorts' to make a list of ports inside the container available locally.
  // "forwardPorts": [],
  // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
  "remoteUser": "vscode",
  "postCreateCommand": {
    "git_dubious_fix": "git config --global --add safe.directory ${containerWorkspaceFolder}",
    "commit_tools": "npm install -g husky standard-version @commitlint/cli @commitlint/config-conventional",
    "enable_husky": "npx husky install < /dev/null",
    "update_python_modules": "pip --disable-pip-version-check --no-cache-dir install -r requirements.txt"
  }
}
@abdes abdes added the enhancement New feature or request label Dec 12, 2022
@abdes abdes self-assigned this Dec 12, 2022
@abdes abdes closed this as completed in 5ddfca2 Mar 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant