mirror of
https://github.com/csunny/DB-GPT.git
synced 2025-08-01 08:11:45 +00:00
feat:get user info by get_env.sh
chore(build):Optimize the zsh setup fix(dev):Load .env on demand fix(dev):install oh-my-zsh from mirror
This commit is contained in:
parent
9e9308beaa
commit
69b71a8cac
@ -1,17 +1,16 @@
|
|||||||
{
|
{
|
||||||
// Set container runtime user
|
// Set container runtime user
|
||||||
"remoteUser": "work",
|
|
||||||
"build": {
|
"build": {
|
||||||
"dockerfile": ".devcontainer/Dockerfile.dev",
|
"dockerfile": ".devcontainer/Dockerfile.dev",
|
||||||
"context": "./",
|
"context": "./",
|
||||||
"args": {
|
"args": {
|
||||||
"USER_UID": "${localEnv:UID:1001}",
|
"USERNAME": "${localEnv:USER}"
|
||||||
"USER_GID": "${localEnv:GID:1001}",
|
|
||||||
"USER_NAME":"${localEnv:USER:work}"
|
|
||||||
},
|
},
|
||||||
"options": ["--no-cache"]
|
"options": [
|
||||||
|
"--no-cache"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
|
"initializeCommand": ".devcontainer/get_env.sh",
|
||||||
"name": "dbgpt",
|
"name": "dbgpt",
|
||||||
"workspaceFolder": "/app",
|
"workspaceFolder": "/app",
|
||||||
"workspaceMount": "source=${localWorkspaceFolder},target=/app,type=bind",
|
"workspaceMount": "source=${localWorkspaceFolder},target=/app,type=bind",
|
||||||
@ -38,8 +37,10 @@
|
|||||||
],
|
],
|
||||||
"mounts": [
|
"mounts": [
|
||||||
// sharing-git-credentials see https://code.visualstudio.com/remote/advancedcontainers/sharing-git-credentials
|
// sharing-git-credentials see https://code.visualstudio.com/remote/advancedcontainers/sharing-git-credentials
|
||||||
|
// This will enable you to work with the repository code using Git inside the Dev container.
|
||||||
"source=${localEnv:SSH_AUTH_SOCK},target=/run/host-services/ssh-auth.sock,type=bind",
|
"source=${localEnv:SSH_AUTH_SOCK},target=/run/host-services/ssh-auth.sock,type=bind",
|
||||||
// mount to local models
|
// mount to local models
|
||||||
|
// Persist the model to avoid redundant downloads.
|
||||||
"source=${localWorkspaceFolder}/models/text2vec-large-chinese,target=/app/models/text2vec-large-chinese,type=bind"
|
"source=${localWorkspaceFolder}/models/text2vec-large-chinese,target=/app/models/text2vec-large-chinese,type=bind"
|
||||||
],
|
],
|
||||||
"containerEnv": {
|
"containerEnv": {
|
||||||
@ -61,7 +62,7 @@
|
|||||||
"python.formatting.provider": "ruff"
|
"python.formatting.provider": "ruff"
|
||||||
},
|
},
|
||||||
"extensions": [
|
"extensions": [
|
||||||
"ms-python.python",
|
"ms-python.python",
|
||||||
"ms-python.isort",
|
"ms-python.isort",
|
||||||
"ms-python.vscode-pylance",
|
"ms-python.vscode-pylance",
|
||||||
"ms-python.autopep8",
|
"ms-python.autopep8",
|
||||||
@ -73,4 +74,4 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,11 +1,8 @@
|
|||||||
FROM eosphorosai/dbgpt:latest
|
FROM eosphorosai/dbgpt:latest
|
||||||
ARG EXTRAS="proxy_openai,rag,storage_chromadb,quant_bnb,graph_rag"
|
ARG PYTHON_VERSION=3.11
|
||||||
ARG PYTHON_VERSION=3.10
|
ARG PIP_INDEX_URL="https://mirrors.aliyun.com/pypi/simple"
|
||||||
ARG USER_UID=1001
|
ARG USERNAME
|
||||||
ARG USER_GID=1001
|
ARG DEFAULT_VEN=/opt/.uv.venv
|
||||||
ARG USER=work
|
|
||||||
ARG PIP_INDEX_URL="https://pypi.tuna.tsinghua.edu.cn/simple"
|
|
||||||
|
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY . .
|
COPY . .
|
||||||
USER root
|
USER root
|
||||||
@ -13,10 +10,10 @@ USER root
|
|||||||
# add a user to prevent permission mismatches
|
# add a user to prevent permission mismatches
|
||||||
# between the container user (root) and the host user,
|
# between the container user (root) and the host user,
|
||||||
# and to resolve the issue of the host user lacking write permissions.
|
# and to resolve the issue of the host user lacking write permissions.
|
||||||
RUN groupadd -g $USER_GID $USER && \
|
RUN . .devcontainer/.env && \
|
||||||
useradd -u $USER_UID -g $USER_GID -m $USER && \
|
groupadd -g $USER_GID $USERNAME && \
|
||||||
|
useradd -u $USER_UID -g $USER_GID -m $USERNAME && \
|
||||||
chown -R $USER_UID:$USER_GID /app
|
chown -R $USER_UID:$USER_GID /app
|
||||||
|
|
||||||
RUN apt-get update && apt-get install -y \
|
RUN apt-get update && apt-get install -y \
|
||||||
git \
|
git \
|
||||||
curl \
|
curl \
|
||||||
@ -24,17 +21,20 @@ RUN apt-get update && apt-get install -y \
|
|||||||
ssh zsh autojump curl git-flow vim sudo \
|
ssh zsh autojump curl git-flow vim sudo \
|
||||||
&& python${PYTHON_VERSION} -m pip install --upgrade pip \
|
&& python${PYTHON_VERSION} -m pip install --upgrade pip \
|
||||||
&& python${PYTHON_VERSION} -m pip install --upgrade pipx \
|
&& python${PYTHON_VERSION} -m pip install --upgrade pipx \
|
||||||
&& pipx install uv --global \
|
&& pipx install -i $PIP_INDEX_URL uv --global \
|
||||||
&& chown -R $USER:$USER /opt/.uv.venv \
|
&& chown -R $USERNAME:$USERNAME $DEFAULT_VEN \
|
||||||
&& echo "$USER ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USER \
|
&& echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/$USERNAME \
|
||||||
&& chmod 0440 /etc/sudoers.d/$USER
|
&& chmod 0440 /etc/sudoers.d/$USERNAME
|
||||||
USER $USER
|
USER $USERNAME
|
||||||
ENV UV_LINK_MODE=copy
|
ENV UV_LINK_MODE=copy \
|
||||||
RUN /opt/.uv.venv/bin/python3 -m pip install uv -i https://mirrors.aliyun.com/pypi/simple/ && \
|
PIP_INDEX_URL=$PIP_INDEX_URL \
|
||||||
extras=$(echo $EXTRAS | tr ',' '\n' | while read extra; do echo "--extra $extra"; done | tr '\n' ' ') && \
|
VIRTUAL_ENV=$DEFAULT_VEN \
|
||||||
echo $extras && \
|
UV_PROJECT_ENVIRONMENT=$DEFAULT_VEN \
|
||||||
/opt/.uv.venv/bin/uv pip install -r pyproject.toml --all-extras && \
|
UV_PYTHON=$DEFAULT_VEN/bin/python3
|
||||||
/opt/.uv.venv/bin/uv pip install -r requirements/dev-requirements.txt && \
|
|
||||||
/opt/.uv.venv/bin/uv pip install -r requirements/lint-requirements.txt && \
|
RUN . $DEFAULT_VEN/bin/activate && \
|
||||||
cp .devcontainer/dbgpt.pth /opt/.uv.venv/lib/python3.10/site-packages/dbgpt.pth && \
|
uv pip install --prefix $VIRTUAL_ENV -r pyproject.toml --all-extras --index-url=$PIP_INDEX_URL && \
|
||||||
|
uv pip install --prefix $VIRTUAL_ENV -r requirements/dev-requirements.txt --index-url=$PIP_INDEX_URL && \
|
||||||
|
uv pip install --prefix $VIRTUAL_ENV -r requirements/lint-requirements.txt --index-url=$PIP_INDEX_URL && \
|
||||||
|
cp .devcontainer/dbgpt.pth /opt/.uv.venv/lib/python${PYTHON_VERSION}/site-packages/dbgpt.pth && \
|
||||||
python -c "import dbgpt; print(dbgpt.__version__)"
|
python -c "import dbgpt; print(dbgpt.__version__)"
|
22
.devcontainer/get_env.sh
Executable file
22
.devcontainer/get_env.sh
Executable file
@ -0,0 +1,22 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
OS=$(uname -s)
|
||||||
|
USERNAME="$USER"
|
||||||
|
USER_UID=$(id -u "$USER")
|
||||||
|
|
||||||
|
if [ "$OS" = "Linux" ]; then
|
||||||
|
GROUPNAME=$(id -gn "$USER")
|
||||||
|
USER_GID=$(id -g "$USER")
|
||||||
|
else
|
||||||
|
GROUPNAME="root"
|
||||||
|
USER_GID="0"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
printf "OS=%s\nUSERNAME=%s\nUSER_UID=%s\nGROUPNAME=%s\nUSER_GID=%s\n" \
|
||||||
|
"$OS" \
|
||||||
|
"$USERNAME" \
|
||||||
|
"$USER_UID" \
|
||||||
|
"$GROUPNAME" \
|
||||||
|
"$USER_GID" > .devcontainer/.env
|
@ -1,12 +1,14 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
set -e
|
set -e
|
||||||
cd /app
|
cd /app
|
||||||
# Install Oh My Zsh
|
|
||||||
if [ ! -d ~/.oh-my-zsh ]; then
|
# Install Oh My Zsh with mirror fallback
|
||||||
sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
|
if [ ! -f ~/.oh-my-zsh/oh-my-zsh.sh ]; then
|
||||||
|
echo "Installing Oh My Zsh..."
|
||||||
|
REPO=mirrors/oh-my-zsh REMOTE=https://gitee.com/mirrors/oh-my-zsh.git sh -c "$(curl -fsSL https://gitee.com/mirrors/oh-my-zsh/raw/master/tools/install.sh)" "" --unattended
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Install plugins
|
# Install plugins with mirror switching
|
||||||
plugins=(
|
plugins=(
|
||||||
"zsh-users/zsh-autosuggestions"
|
"zsh-users/zsh-autosuggestions"
|
||||||
"zsh-users/zsh-syntax-highlighting"
|
"zsh-users/zsh-syntax-highlighting"
|
||||||
@ -15,21 +17,29 @@ plugins=(
|
|||||||
for plugin in "${plugins[@]}"; do
|
for plugin in "${plugins[@]}"; do
|
||||||
repo_name=$(basename $plugin)
|
repo_name=$(basename $plugin)
|
||||||
if [ ! -d ~/.oh-my-zsh/custom/plugins/$repo_name ]; then
|
if [ ! -d ~/.oh-my-zsh/custom/plugins/$repo_name ]; then
|
||||||
git clone --depth=1 https://github.com/$plugin.git ~/.oh-my-zsh/custom/plugins/$repo_name
|
echo "Installing plugin: $plugin"
|
||||||
|
# Clone from GitHub with Gitee mirror fallback
|
||||||
|
git clone --depth=1 https://github.com/$plugin.git ~/.oh-my-zsh/custom/plugins/$repo_name || \
|
||||||
|
git clone --depth=1 https://gitee.com/zsh-users/$repo_name.git ~/.oh-my-zsh/custom/plugins/$repo_name
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# Install theme
|
|
||||||
|
# Install theme with mirror fallback
|
||||||
if [ ! -d ~/.oh-my-zsh/custom/themes/powerlevel10k ]; then
|
if [ ! -d ~/.oh-my-zsh/custom/themes/powerlevel10k ]; then
|
||||||
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/.oh-my-zsh/custom/themes/powerlevel10k
|
echo "Installing powerlevel10k theme..."
|
||||||
|
# Clone from GitHub with Gitee mirror fallback
|
||||||
|
git clone --depth=1 https://github.com/romkatv/powerlevel10k.git ~/.oh-my-zsh/custom/themes/powerlevel10k || \
|
||||||
|
git clone --depth=1 https://gitee.com/romkatv/powerlevel10k.git ~/.oh-my-zsh/custom/themes/powerlevel10k
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Configuration section remains the same...
|
||||||
# Apply custom configuration
|
# Apply custom configuration
|
||||||
if [ -f /workspace/.devcontainer/zshrc-config ]; then
|
if [ -f /workspace/.devcontainer/zshrc-config ]; then
|
||||||
cp /workspace/.devcontainer/zshrc-config ~/.zshrc
|
cp /workspace/.devcontainer/zshrc-config ~/.zshrc
|
||||||
else
|
else
|
||||||
# Generate basic .zshrc if no custom configuration exists
|
# Generate basic .zshrc if no custom configuration exists
|
||||||
cat << EOF > ~/.zshrc
|
cat << EOF >> ~/.zshrc
|
||||||
export ZSH="\$HOME/.oh-my-zsh"
|
export ZSH="\$HOME/.oh-my-zsh"
|
||||||
ZSH_THEME="robbyrussell"
|
ZSH_THEME="robbyrussell"
|
||||||
plugins=(git zsh-autosuggestions zsh-syntax-highlighting autojump)
|
plugins=(git zsh-autosuggestions zsh-syntax-highlighting autojump)
|
||||||
@ -46,9 +56,15 @@ if ! grep -q "autojump.sh" ~/.zshrc; then
|
|||||||
fi
|
fi
|
||||||
cat << EOF >> ~/.zshrc
|
cat << EOF >> ~/.zshrc
|
||||||
# Add the following to ~/.zshrc
|
# Add the following to ~/.zshrc
|
||||||
if [ -f /app/.env ]; then
|
load_env() {
|
||||||
export $(grep -vE '^#|^$' /app/.env | xargs)
|
if [ -f /app/.env ]; then
|
||||||
fi
|
ENV_CONTENT=$(grep -vE '^#|^$' /app/.env | xargs)
|
||||||
|
if [ -n "$ENV_CONTENT" ]; then
|
||||||
|
export $ENV_CONTENT
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
load_env
|
||||||
EOF
|
EOF
|
||||||
rm -rf .venv.make
|
rm -rf .venv.make
|
||||||
echo "Post-create setup completed!"
|
echo "Post-create setup completed!"
|
Loading…
Reference in New Issue
Block a user