Skip to content

Commit

Permalink
📝 docs: Update upstream-sync (lobehub#2262)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuozhiyongde authored Apr 28, 2024
1 parent d601fe7 commit 80d8eec
Show file tree
Hide file tree
Showing 4 changed files with 147 additions and 2 deletions.
74 changes: 74 additions & 0 deletions docs/self-hosting/advanced/upstream-sync.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,77 @@ Ensure that you have sufficient permissions to stop and remove the container bef
No need to worry, you won't. All of LobeChat's chat records are stored in your local browser. Therefore, when redeploying LobeChat using Docker, your chat records will not be lost.

</Callout>

If you wish to automate the above steps, you can follow the method below and use Crontab scheduling to complete it. The specific steps are as follows.

<Steps>

### Write automatic update scripts and configuration files

First, create a `lobe.env` configuration file with various environment variables, for example:

```env
OPENAI_API_KEY=sk-xxxx
OPENAI_PROXY_URL=https://api-proxy.com/v1
ACCESS_CODE=arthals2333
OPENAI_MODEL_LIST=-gpt-4,-gpt-4-32k,-gpt-3.5-turbo-16k,gpt-3.5-turbo-1106=gpt-3.5-turbo-16k,gpt-4-0125-preview=gpt-4-turbo,gpt-4-vision-preview=gpt-4-vision
```

Then, you can use the following script to automate the update:

```bash
#!/bin/bash
# auto-update-lobe-chat.sh

# Set up proxy (optional)
export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890

# Pull the latest image and store the output in a variable
output=$(docker pull lobehub/lobe-chat:latest 2>&1)

# Check if the pull command was executed successfully
if [ $? -ne 0 ]; then
exit 1
fi

# Check if the output contains a specific string
echo "$output" | grep -q "Image is up to date for lobehub/lobe-chat:latest"

# If the image is already up to date, do nothing
if [ $? -eq 0 ]; then
exit 0
fi

echo "Detected Lobe-Chat update"

# Remove the old container
echo "Removed: $(docker rm -f Lobe-Chat)"

# Run the new container
echo "Started: $(docker run -d --network=host --env-file /path/to/lobe.env --name=Lobe-Chat --restart=always lobehub/lobe-chat)"

# Print the update time and version
echo "Update time: $(date)"
echo "Version: $(docker inspect lobehub/lobe-chat:latest | grep 'org.opencontainers.image.version' | awk -F'"' '{print $4}')"

# Clean up unused images
docker images | grep 'lobehub/lobe-chat' | grep -v 'latest' | awk '{print $3}' | xargs -r docker rmi > /dev/null 2>&1
echo "Removed old images."
```

<Callout type={'warning'}>
This script can be used in Crontab, but please ensure that your Crontab can find the correct
Docker command. It is recommended to use absolute paths.
</Callout>

Configure Crontab to execute the script every 5 minutes:

### Configure Crontab to automatically execute scripts

The following command configures Crontab to execute scripts every 5 minutes, or as often as you like:

```bash
*/5 * * * * /path/to/auto-update-lobe-chat.sh >> /path/to/auto-update-lobe-chat.log 2>&1
```

</Steps>
71 changes: 71 additions & 0 deletions docs/self-hosting/advanced/upstream-sync.zh-CN.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,74 @@ docker run -d -p 3210:3210 \
放心,不会的。LobeChat 的聊天记录全部都存储在你的本地浏览器中。因此使用 Docker 重新部署 LobeChat 时,你的聊天记录并不会丢失。

</Callout>

如果你希望自动化执行以上步骤,你可以参照下面的方法,利用 Crontab 定时来完成。具体步骤如下。

<Steps>

### 撰写自动更新脚本、配置文件

首先,新建一个 `lobe.env` 配置文件,内容为各种环境变量,例如:

```env
OPENAI_API_KEY=sk-xxxx
OPENAI_PROXY_URL=https://api-proxy.com/v1
ACCESS_CODE=arthals2333
OPENAI_MODEL_LIST=-gpt-4,-gpt-4-32k,-gpt-3.5-turbo-16k,gpt-3.5-turbo-1106=gpt-3.5-turbo-16k,gpt-4-0125-preview=gpt-4-turbo,gpt-4-vision-preview=gpt-4-vision
```

然后,你可以使用以下脚本来自动更新:

```bash
#!/bin/bash
# auto-update-lobe-chat.sh

# 设置代理(可选)
export https_proxy=http://127.0.0.1:7890 http_proxy=http://127.0.0.1:7890 all_proxy=socks5://127.0.0.1:7890

# 拉取最新的镜像并将输出存储在变量中
output=$(docker pull lobehub/lobe-chat:latest 2>&1)

# 检查拉取命令是否成功执行
if [ $? -ne 0 ]; then
exit 1
fi

# 检查输出中是否包含特定的字符串
echo "$output" | grep -q "Image is up to date for lobehub/lobe-chat:latest"

# 如果镜像已经是最新的,则不执行任何操作
if [ $? -eq 0 ]; then
exit 0
fi

echo "Detected Lobe-Chat update"

# 删除旧的容器
echo "Removed: $(docker rm -f Lobe-Chat)"

# 运行新的容器
echo "Started: $(docker run -d --network=host --env-file /path/to/lobe.env --name=Lobe-Chat --restart=always lobehub/lobe-chat)"

# 打印更新的时间和版本
echo "Update time: $(date)"
echo "Version: $(docker inspect lobehub/lobe-chat:latest | grep 'org.opencontainers.image.version' | awk -F'"' '{print $4}')"

# 清理不再使用的镜像
docker images | grep 'lobehub/lobe-chat' | grep -v 'latest' | awk '{print $3}' | xargs -r docker rmi > /dev/null 2>&1
echo "Removed old images."
```

<Callout type={'warning'}>
此脚本可以在 Crontab 中使用,但请确认你的 Crontab 可以找到正确的 Docker 命令。建议使用绝对路径。
</Callout>

### 配置 Crontab 自动执行脚本

以下命令可以配置 Crontab 每 5 分钟执行一次脚本,你也可以根据需要调整执行频率:

```bash
*/5 * * * * /path/to/auto-update-lobe-chat.sh >> /path/to/auto-update-lobe-chat.log 2>&1
```

</Steps>
2 changes: 1 addition & 1 deletion docs/usage/providers/ollama.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ This document will guide you on how to use Ollama in LobeChat:

<Video
alt="demonstration of using Ollama in LobeChat"
height={556}
height={580}
src="https://github.com/lobehub/lobe-chat/assets/28616219/c32b56db-c6a1-4876-9bc3-acbd37ec0c0c"
/>

Expand Down
2 changes: 1 addition & 1 deletion docs/usage/providers/ollama.zh-CN.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Ollama 是一款强大的本地运行大型语言模型(LLM)的框架,支

<Video
alt={'在 LobeChat 中使用 Ollama的完整演示'}
height={556}
height={580}
src="https://github.com/lobehub/lobe-chat/assets/28616219/c32b56db-c6a1-4876-9bc3-acbd37ec0c0c"
/>

Expand Down

0 comments on commit 80d8eec

Please sign in to comment.