From 543f237a3c9ebcf0f9151978ba80f99b207d2711 Mon Sep 17 00:00:00 2001 From: Wenxuan Date: Thu, 13 Apr 2023 10:47:00 +0800 Subject: [PATCH] Make devcontainer work in multi-user env (#7269) ref pingcap/tiflash#5991 --- .devcontainer/.local_persist/gh/.gitignore | 2 -- .devcontainer/Dockerfile | 14 ++++---- .devcontainer/Makefile | 38 +++++++--------------- .devcontainer/devcontainer.json | 35 ++++++++++++++++---- .devcontainer/docker-compose.vscode.yml | 15 --------- .devcontainer/docker-compose.yml | 37 --------------------- .env | 1 - 7 files changed, 47 insertions(+), 95 deletions(-) delete mode 100644 .devcontainer/.local_persist/gh/.gitignore delete mode 100644 .devcontainer/docker-compose.vscode.yml delete mode 100644 .devcontainer/docker-compose.yml delete mode 100644 .env diff --git a/.devcontainer/.local_persist/gh/.gitignore b/.devcontainer/.local_persist/gh/.gitignore deleted file mode 100644 index d6b7ef32c84..00000000000 --- a/.devcontainer/.local_persist/gh/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -* -!.gitignore diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 966e34c9830..de2ca91f11f 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,13 +1,13 @@ # syntax=docker/dockerfile:1 # The source of this image is available at https://github.com/breezewish/tiflash-devcontainer -FROM breezewish/tiflash-dev:0.0.3 +FROM breezewish/tiflash-dev:0.0.4 # Create directories to mount as volumes. These directories will be persisted # after the container is recreated. -RUN mkdir -p /root/.vscode-server/extensions \ - && mkdir -p /root/.cargo/registry \ - && mkdir -p /root/.cargo/git \ - && mkdir -p /root/.rustup/toolchains \ - && mkdir -p /root/.cache/ccache \ - && mkdir -p /root/.config/gh +RUN mkdir -p /home/dev/.vscode-server/extensions \ + && mkdir -p /home/dev/.cargo/registry \ + && mkdir -p /home/dev/.cargo/git \ + && mkdir -p /home/dev/.rustup/toolchains \ + && mkdir -p /home/dev/.cache/ccache \ + && mkdir -p /home/dev/.config/gh diff --git a/.devcontainer/Makefile b/.devcontainer/Makefile index 1c7a8c052df..43cffe0974f 100644 --- a/.devcontainer/Makefile +++ b/.devcontainer/Makefile @@ -12,18 +12,11 @@ # See the License for the specific language governing permissions and # limitations under the License. -# Must keep sync with the project name in repository_root/.env -export COMPOSE_PROJECT_NAME = tiflash-devcontainer +CONTAINER_SHELL := devcontainer exec --workspace-folder=.. /usr/local/bin/zsh -CONTAINER_SHELL := docker compose run --rm -it --entrypoint /usr/local/bin/dumb-init shell -- /usr/local/bin/zsh - -.PHONY: rebuild-docker -rebuild-docker: - docker compose build - -.PHONY: dev-in-container -dev-in-container: SHELL := $(CONTAINER_SHELL) -dev-in-container: +.PHONY: dev +dev: SHELL := $(CONTAINER_SHELL) +dev: mkdir -p cmake-build-Debug \ && cd cmake-build-Debug \ && cmake .. -GNinja -DCMAKE_BUILD_TYPE=DEBUG \ @@ -32,12 +25,9 @@ dev-in-container: && cmake --build . --target tiflash \ && cmake --install . --component=tiflash-release --prefix=artifacts -.PHONY: dev -dev: rebuild-docker dev-in-container - -.PHONY: release-in-container -release-in-container: SHELL := $(CONTAINER_SHELL) -release-in-container: +.PHONY: release +release: SHELL := $(CONTAINER_SHELL) +release: mkdir -p cmake-build-Release \ && cd cmake-build-Release \ && cmake .. -GNinja -DCMAKE_BUILD_TYPE=RELWITHDEBINFO \ @@ -46,12 +36,9 @@ release-in-container: && cmake --build . --target tiflash \ && cmake --install . --component=tiflash-release --prefix=artifacts -.PHONY: release -release: rebuild-docker release-in-container - -.PHONY: test-in-container -test-in-container: SHELL := $(CONTAINER_SHELL) -test-in-container: +.PHONY: test +test: SHELL := $(CONTAINER_SHELL) +test: mkdir -p cmake-build-Debug \ && cd cmake-build-Debug \ && cmake .. -GNinja -DCMAKE_BUILD_TYPE=DEBUG \ @@ -60,9 +47,6 @@ test-in-container: && cmake --build . --target gtests_dbms \ && dbms/gtests_dbms -.PHONY: test -test: rebuild-docker test-in-container - .PHONY: clean-all clean-all: rm -rf ../cmake-build-Debug @@ -74,5 +58,5 @@ clean-cmake: rm -rf ../cmake-build-Release/CMakeCache.txt .PHONY: shell -shell: rebuild-docker +shell: $(CONTAINER_SHELL) diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 59c0b1ff55e..baa418245d9 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -1,12 +1,35 @@ // For format details, see https://aka.ms/devcontainer.json. { "name": "TiFlash", - "dockerComposeFile": [ - "docker-compose.yml", - "docker-compose.vscode.yml" + "build": { + "dockerfile": "Dockerfile", + }, + // "init": true, + "capAdd": [ + "SYS_PTRACE", ], - "service": "shell", - "workspaceFolder": "/workspace", + "securityOpt": [ + "seccomp=unconfined", + ], + "mounts": [ + // Cache Cargo downloaded deps + "source=${localEnv:HOME}/.cargo/registry,target=/home/dev/.cargo/registry,type=bind", + "source=${localEnv:HOME}/.cargo/git,target=/home/dev/.cargo/git,type=bind", + // Cache Rust toolchain + // We have to cache the entire directory due to https://github.com/rust-lang/rustup/issues/1239 + "source=${localEnv:HOME}/.rustup,target=/home/dev/.rustup,type=bind", + // Cache ccache results + "source=${localEnv:HOME}/.cache/ccache,target=/home/dev/.cache/ccache,type=bind", + // Persist GitHub CLI Config locally + "source=${localEnv:HOME}/.config/gh,target=/home/dev/.config/gh,type=bind", + // VSCode Extensions + "source=${localEnv:HOME}/.vscode-server/extensions,target=/home/dev/.vscode-server/extensions,type=bind", + ], + // Ensure mount source directories exist. + "initializeCommand": "mkdir -p ${localEnv:HOME}/.cargo/registry ${localEnv:HOME}/.cargo/git ${localEnv:HOME}/.rustup ${localEnv:HOME}/.cache/ccache ${localEnv:HOME}/.config/gh ${localEnv:HOME}/.vscode-server/extensions", + "remoteUser": "dev", + "workspaceMount": "source=${localWorkspaceFolder},target=/home/dev/workspace,type=bind", + "workspaceFolder": "/home/dev/workspace", "customizations": { "vscode": { "extensions": [ @@ -37,7 +60,7 @@ "cmake.generator": "Ninja", "cmake.configureOnOpen": true, "testMate.cpp.test.executables": "cmake-build-*/**/gtests_*", - "terminal.integrated.defaultProfile.linux": "zsh" + "terminal.integrated.defaultProfile.linux": "zsh", } } } diff --git a/.devcontainer/docker-compose.vscode.yml b/.devcontainer/docker-compose.vscode.yml deleted file mode 100644 index e0879e2921a..00000000000 --- a/.devcontainer/docker-compose.vscode.yml +++ /dev/null @@ -1,15 +0,0 @@ -version: "3.8" - -services: - - shell: - - volumes: - # Avoid reinstalling vscode extensions - - vscode-extensions:/root/.vscode-server/extensions - - # Overrides default command so things don't shut down after the process ends. - command: sleep infinity - -volumes: - vscode-extensions: diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml deleted file mode 100644 index 801a10317ef..00000000000 --- a/.devcontainer/docker-compose.yml +++ /dev/null @@ -1,37 +0,0 @@ -version: "3.8" - -services: - - shell: - - build: - context: . - dockerfile: Dockerfile - - volumes: - # The project's source code - - ..:/workspace:cached - # Cache Cargo downloaded deps - - cargo-registry:/root/.cargo/registry - - cargo-git:/root/.cargo/git - # Cache Rust toolchain - # We have to cache the entire directory due to https://github.com/rust-lang/rustup/issues/1239 - - rustup:/root/.rustup - # Cache ccache results - - ccache:/root/.cache/ccache - # Persist GitHub CLI Config locally in the repository - - .local_persist/gh:/root/.config/gh - - working_dir: /workspace - - # Enable using a ptrace-based debugger like C++, Go, and Rust. - cap_add: - - SYS_PTRACE - security_opt: - - seccomp:unconfined - -volumes: - cargo-registry: - cargo-git: - rustup: - ccache: diff --git a/.env b/.env deleted file mode 100644 index be37475f79e..00000000000 --- a/.env +++ /dev/null @@ -1 +0,0 @@ -COMPOSE_PROJECT_NAME=tiflash-devcontainer