From 85cb70c0a3e838615bc700ed0db5be72258e691a Mon Sep 17 00:00:00 2001 From: yale <2927096163@qq.com> Date: Fri, 29 Jul 2022 07:03:48 +0800 Subject: [PATCH] Add DevContainer (#1608) With DevContainer, developers can join the project without deploy the build env. Signed-off-by: cyw3 <2927096163@qq.com> --- .devcontainer/Dockerfile | 52 ++++++++++++++++++++++++++++++ .devcontainer/devcontainer.json | 12 +++++++ docs/project/contribution_tools.md | 17 ++++++++++ 3 files changed, 81 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 000000000000..9886d9f116e1 --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,52 @@ +# Part of the Carbon Language project, under the Apache License v2.0 with LLVM +# Exceptions. See /LICENSE for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception + +FROM centos:centos7.9.2009 + +# install +RUN yum -y install which zlib zlib-devel curl perl-ExtUtils-CBuilder perl-ExtUtils-MakeMaker gcc gcc-c++ curl-devel expat-devel gettext-devel openssl-devel expect make wget gettext zip unzip scl-utils \ + && yum -y install centos-release-scl \ + && yum -y install devtoolset-7-gcc* \ + && mkdir -p /data/App \ + && cd /data/App \ + && wget https://github.com/git/git/archive/refs/tags/v2.37.1.tar.gz \ + && tar -zxvf v2.37.1.tar.gz \ + && wget https://curl.haxx.se/download/curl-7.70.0.tar.gz --no-check-certificate \ + && tar -zxvf curl-7.70.0.tar.gz \ + && rm *.tar.gz + +RUN source /opt/rh/devtoolset-7/enable \ + && gcc --version \ + && cd /data/App/git-2.37.1 \ + && make prefix=/usr/local/git all \ + && make prefix=/usr/local/git install \ + && cd ../curl-7.70.0 \ + && ./configure --prefix=/usr/local/curl \ + && make && make install \ + && cd .. \ + && export PATH=/usr/local/git/bin:/usr/local/curl/bin:$PATH \ + && NONINTERACTIVE=1 /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" \ + && echo 'eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)"' >> /root/.bash_profile \ + && eval "$(/home/linuxbrew/.linuxbrew/bin/brew shellenv)" + +RUN export PATH=/home/linuxbrew/.linuxbrew/bin/:/home/linuxbrew/.linuxbrew/opt/llvm/bin:/usr/local/git/bin:/usr/local/curl/bin:$PATH \ + && export HOMEBREW_GIT_PATH=/usr/local/git/bin/git \ + && export HOMEBREW_CURL_PATH=/usr/local/curl/bin/curl \ + && brew update \ + && brew install bazelisk \ + && brew install libxcrypt --overwrite \ + && brew install --force-bottle --only-dependencies llvm \ + && brew install --force-bottle --force --verbose llvm \ + && brew info llvm \ + && brew install node \ + && brew install python@3.9 \ + && pip3 install -U pip \ + && pip3 install pre-commit \ + && pip3 install black \ + && pip3 install codespell + +ENV LANG=en_US.UTF-8 \ + HOMEBREW_GIT_PATH=/usr/local/git/bin/git \ + HOMEBREW_CURL_PATH=/usr/local/curl/bin/curl \ + PATH=/home/linuxbrew/.linuxbrew/opt/llvm/bin:/home/linuxbrew/.linuxbrew/bin/:/home/linuxbrew/.linuxbrew/Cellar/llvm/14.0.6_1.reinstall/bin:/usr/local/git/bin:/usr/local/curl/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 000000000000..ff2b2163535a --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,12 @@ +{ + "name": "dev environment", + "dockerFile": "Dockerfile", + "extensions": [ + "bazelbuild.vscode-bazel", + "bierner.github-markdown-preview", + "daohong-emilio.yash", + "esbenp.prettier-vscode", + "llvm-vs-code-extensions.vscode-clangd", + "ms-python.python" + ] +} diff --git a/docs/project/contribution_tools.md b/docs/project/contribution_tools.md index 8d254e3c04a1..f7ddabbb45a3 100644 --- a/docs/project/contribution_tools.md +++ b/docs/project/contribution_tools.md @@ -36,6 +36,7 @@ contributions. - [Vim](#vim) - [vim-prettier](#vim-prettier) - [Visual Studio Code](#visual-studio-code) + - [DevContainer](#devcontainer) - [pre-commit enabled tools](#pre-commit-enabled-tools) - [black](#black) - [codespell](#codespell) @@ -390,6 +391,22 @@ Our recommended way of installing is to use > still be used for other purposes, such as editing files, without interfering > with `bazel`. +#### DevContainer + +To support developers join the project without deploying the build env, we +provide VSCode `DevContainer`. + +- Install VSCode and Docker; +- Install the plugin `ms-vscode-remote.remote-containers` under VSCode; +- Open `Carban` project folder in + [VSCode](https://docs.microsoft.com/en-us/azure-sphere/app-development/container-build-vscode#build-and-debug-the-project); +
Visual Studio Code detects the new files and opens a message box + saying: + `Folder contains a Dev Container configuration file. Reopen to folder to develop in a container.` +- Select the `Reopen in Container` button to reopen the folder in the + container created by the `.devcontainer/Dockerfile` file; +- And then, you are ready to start writing code. + ### pre-commit enabled tools If you're using pre-commit, it will run these tools. Installing and running them