Skip to content

Commit

Permalink
misc: Update devcontainer (#9703)
Browse files Browse the repository at this point in the history
ref #6233

Update TiFlash devcontainer to use latest build infrastructure.
  • Loading branch information
breezewish authored Dec 4, 2024
1 parent a98d04c commit f41da70
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 9 deletions.
65 changes: 57 additions & 8 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion .devcontainer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions .devcontainer/misc/codespaces.zsh-theme
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions .devcontainer/misc/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/zsh

set -o errexit
set -o pipefail
set -o nounset

exec "$@"

0 comments on commit f41da70

Please sign in to comment.