Skip to content

Commit

Permalink
build: simplify devcontainer setup
Browse files Browse the repository at this point in the history
fixes #23
  • Loading branch information
abdes committed Mar 25, 2023
1 parent 7348d0a commit 5ddfca2
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 47 deletions.
45 changes: 9 additions & 36 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
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

# [Choice] Python version (use -bullseye variants on local arm64/Apple Silicon): 3, 3.10, 3.9, 3.8, 3.7, 3.6, 3-bullseye, 3.10-bullseye, 3.9-bullseye, 3.8-bullseye, 3.7-bullseye, 3.6-bullseye, 3-buster, 3.10-buster, 3.9-buster, 3.8-buster, 3.7-buster, 3.6-buster
ARG VARIANT="3.10-bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}

# [Choice] Node.js version: none, lts/*, 16, 14, 12, 10
ARG NODE_VERSION="none"
RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi
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 \
&& 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
Expand All @@ -25,12 +21,6 @@ RUN add-apt-repository 'deb http://apt.llvm.org/bullseye/ llvm-toolchain-bullsey
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

# 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/*

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
Expand All @@ -43,25 +33,8 @@ RUN update-alternatives --install /usr/bin/scan-view scan-view /usr/bin/scan-vie
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

# Our pip requirements rarely change, add them to the image.
COPY requirements.txt /tmp/pip-tmp/
RUN if [ -f "/tmp/pip-tmp/requirements.txt" ]; then \
pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
&& rm -rf /tmp/pip-tmp; \
fi

# Install global node packages and enable husky.
RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g husky standard-version @commitlint/cli @commitlint/config-conventional " 2>&1
# Install ccache
RUN apt-get -y install ccache

# Setup oh-my-zsh and plugins for user vscode
ARG USERNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
COPY --chown=$USER_UID:$USER_GID .devcontainer/.zshrc /home/$USERNAME
RUN chmod 644 /home/$USERNAME/.zshrc
# the user we're applying this too (otherwise it most likely install for root)
USER $USERNAME
RUN git clone https://github.com/romkatv/powerlevel10k.git ~/.oh-my-zsh/custom/themes/powerlevel10k
RUN git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
RUN git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
ENV SHELL=/bin/zsh
# Clean-up
RUN apt-get autoremove -y && apt-get clean -y && rm -rf /var/lib/apt/lists/*
35 changes: 24 additions & 11 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,21 @@
// 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": "3.10-bullseye",
// Options
"NODE_VERSION": "16"
"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.
Expand All @@ -28,10 +40,7 @@
"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",
"python.experiments.optInto": [
"pythonDeprecatePythonPath"
],
"clangd.path": "/usr/bin/clangd-14",
"clangd.path": "/usr/bin/clangd-14"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
Expand All @@ -52,8 +61,12 @@
],
// 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": "npx husky install < /dev/null",
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
"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"
}
}

0 comments on commit 5ddfca2

Please sign in to comment.