From da0ff72f10014569c49536a0272994d23983630c Mon Sep 17 00:00:00 2001 From: Wenxuan Date: Wed, 4 Dec 2024 22:52:06 +0800 Subject: [PATCH] misc: Update devcontainer --- .devcontainer/Dockerfile | 65 ++++++++++++++++++++++--- .devcontainer/Makefile | 2 +- .devcontainer/misc/codespaces.zsh-theme | 19 ++++++++ .devcontainer/misc/docker-entrypoint.sh | 7 +++ 4 files changed, 84 insertions(+), 9 deletions(-) create mode 100644 .devcontainer/misc/codespaces.zsh-theme create mode 100644 .devcontainer/misc/docker-entrypoint.sh diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index de2ca91f11f..fa66404e5aa 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,13 +1,62 @@ # syntax=docker/dockerfile:1 -# The source of this image is available at https://github.com/breezewish/tiflash-devcontainer -FROM breezewish/tiflash-dev:0.0.4 +# The source of this image is available at https://github.com/pingcap/tiflash/blob/master/release-linux-llvm/dockerfiles/Dockerfile-tiflash-llvm-base +FROM hub.pingcap.net/tiflash/tiflash-llvm-base:rocky8-llvm-17.0.6 + +ARG USERNAME=dev +ARG USER_UID=1000 +ARG USER_GID=$USER_UID + +RUN --mount=type=cache,target=/var/cache/yum,sharing=locked \ + yum install -y yum-utils + +RUN --mount=type=cache,target=/var/cache/yum,sharing=locked \ + yum-config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo + +RUN --mount=type=cache,target=/var/cache/yum,sharing=locked \ + yum install -y git zsh python3 gh sudo screen + +# Use dump-init as the default entry point. +RUN if [[ "$(uname -m)" = @(x86_64|x64) ]]; then \ + PLATFORM=x86_64 ; \ + elif [[ "$(uname -m)" = @(arm64|aarch64|armv8b|armv8l) ]]; then \ + PLATFORM=aarch64 ; \ + fi \ + && wget -O /usr/local/bin/dumb-init https://github.com/Yelp/dumb-init/releases/download/v1.2.5/dumb-init_1.2.5_${PLATFORM} +RUN chmod +x /usr/local/bin/dumb-init + +RUN groupadd --gid $USER_GID $USERNAME \ + && useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \ + && echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \ + && chmod 0440 /etc/sudoers.d/$USERNAME + +ENV HOME="" +USER $USERNAME +WORKDIR /home/$USERNAME + +RUN sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" +COPY --chown=$USERNAME misc/codespaces.zsh-theme /home/$USERNAME/.oh-my-zsh/custom/themes/ +RUN { echo "zstyle ':omz:update' mode disabled" | tee -a /home/$USERNAME/.zshrc ; } \ + && sed -i -e 's/ZSH_THEME=.*/ZSH_THEME="codespaces"/g' /home/$USERNAME/.zshrc + +# Install Rust for current user +RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain none +# Override default Rust linkers. Cargo does not respect CC env variables at all. +RUN mkdir -p /home/$USERNAME/.cargo/ +RUN sudo cp /root/.cargo/config /home/$USERNAME/.cargo/config +RUN sudo chown $USERNAME:$USERNAME /home/$USERNAME/.cargo/config # Create directories to mount as volumes. These directories will be persisted # after the container is recreated. -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 +RUN mkdir -p /home/$USERNAME/.vscode-server/extensions \ + && mkdir -p /home/$USERNAME/.cargo/registry \ + && mkdir -p /home/$USERNAME/.cargo/git \ + && mkdir -p /home/$USERNAME/.rustup/toolchains \ + && mkdir -p /home/$USERNAME/.cache/ccache \ + && mkdir -p /home/$USERNAME/.config/gh + +COPY --chmod=777 misc/docker-entrypoint.sh / +ENTRYPOINT [ "/usr/local/bin/dumb-init", "--", "/usr/bin/zsh", "/docker-entrypoint.sh" ] +CMD [ "/usr/bin/zsh" ] + +# TODO: Add other handy tools like rg fd fzf diff --git a/.devcontainer/Makefile b/.devcontainer/Makefile index 0c476c17a5d..1b0bb585376 100644 --- a/.devcontainer/Makefile +++ b/.devcontainer/Makefile @@ -12,7 +12,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -CONTAINER_SHELL := devcontainer exec --workspace-folder=.. /usr/local/bin/zsh +CONTAINER_SHELL := devcontainer exec --workspace-folder=.. /usr/bin/zsh .PHONY: dev dev: SHELL := $(CONTAINER_SHELL) diff --git a/.devcontainer/misc/codespaces.zsh-theme b/.devcontainer/misc/codespaces.zsh-theme new file mode 100644 index 00000000000..52e8e332b0f --- /dev/null +++ b/.devcontainer/misc/codespaces.zsh-theme @@ -0,0 +1,19 @@ +# Codespaces zsh prompt theme +__zsh_prompt() { + local prompt_username + if [ ! -z "${GITHUB_USER}" ]; then + prompt_username="@${GITHUB_USER}" + else + prompt_username="%n" + fi + PROMPT="%{$fg[green]%}TiFlashDevContainer %(?:%{$reset_color%}➜ :%{$fg_bold[red]%}➜ )" # User/exit code arrow + PROMPT+='%{$fg_bold[blue]%}%(5~|%-1~/…/%3~|%4~)%{$reset_color%} ' # cwd + PROMPT+='$([ "$(git config --get codespaces-theme.hide-status 2>/dev/null)" != 1 ] && git_prompt_info)' # Git status + PROMPT+='%{$fg[white]%}$ %{$reset_color%}' + unset -f __zsh_prompt +} +ZSH_THEME_GIT_PROMPT_PREFIX="%{$fg_bold[cyan]%}(%{$fg_bold[red]%}" +ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%} " +ZSH_THEME_GIT_PROMPT_DIRTY=" %{$fg_bold[yellow]%}✗%{$fg_bold[cyan]%})" +ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg_bold[cyan]%})" +__zsh_prompt diff --git a/.devcontainer/misc/docker-entrypoint.sh b/.devcontainer/misc/docker-entrypoint.sh new file mode 100644 index 00000000000..5367e758e1d --- /dev/null +++ b/.devcontainer/misc/docker-entrypoint.sh @@ -0,0 +1,7 @@ +#!/usr/bin/zsh + +set -o errexit +set -o pipefail +set -o nounset + +exec "$@"