Skip to content

Commit

Permalink
Make devcontainer work in multi-user env (pingcap#7269)
Browse files Browse the repository at this point in the history
  • Loading branch information
breezewish committed Apr 20, 2023
1 parent 5720e8d commit 543f237
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 95 deletions.
2 changes: 0 additions & 2 deletions .devcontainer/.local_persist/gh/.gitignore

This file was deleted.

14 changes: 7 additions & 7 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
38 changes: 11 additions & 27 deletions .devcontainer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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 \
Expand All @@ -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 \
Expand All @@ -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
Expand All @@ -74,5 +58,5 @@ clean-cmake:
rm -rf ../cmake-build-Release/CMakeCache.txt

.PHONY: shell
shell: rebuild-docker
shell:
$(CONTAINER_SHELL)
35 changes: 29 additions & 6 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down Expand Up @@ -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",
}
}
}
Expand Down
15 changes: 0 additions & 15 deletions .devcontainer/docker-compose.vscode.yml

This file was deleted.

37 changes: 0 additions & 37 deletions .devcontainer/docker-compose.yml

This file was deleted.

1 change: 0 additions & 1 deletion .env

This file was deleted.

0 comments on commit 543f237

Please sign in to comment.