Skip to content

Commit

Permalink
📝 docs: update docker auto-update script (lobehub#1165)
Browse files Browse the repository at this point in the history
* 📝 docs: update docker auto-update script

* 📝 docs: update envfile configuration way

* 🐛 fix: typo
  • Loading branch information
zhuozhiyongde authored Jan 30, 2024
1 parent d9d921c commit b72f842
Show file tree
Hide file tree
Showing 2 changed files with 236 additions and 0 deletions.
118 changes: 118 additions & 0 deletions docs/Deployment/Docker-Deployment.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,69 @@ $ docker run -d -p 3210:3210 \
>
> As the official Docker image build takes about half an hour, if there is a "update available" prompt after updating deployment, wait for the image to finish building before deploying again.
#### Crontab Auto-Update Script

If you want to automatically get the latest images, you can do the following.

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
CUSTOM_MODELS=-gpt-4,-gpt-4-32k,-gpt-3.5-turbo-16k,gpt-3.5-turbo-1106=gpt-3.5-turbo-16k,gpt-4-1106-preview=gpt-4-turbo,gpt-4-vision-preview=gpt-4-vision
```

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

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

# Set 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 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, then do nothing
if [ $? -eq 0 ]; then
exit 0
fi

echo "Detected Lobe-Chat update"

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

# Run 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."
```

This script can be used in Crontab, but make sure your Crontab can find the correct Docker command. It's recommended to use absolute paths.

Configure Crontab to execute the script every 5 minutes:

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

### `B` Docker Compose

The configuration file for using `docker-compose` is as follows:
Expand All @@ -91,6 +154,61 @@ services:
ACCESS_CODE: lobe66
```
#### Crontab Auto-Update Script
Similarly, you can use the following script to update Lobe Chat automatically. When using `Docker Compose`, environment variables do not need additional configuration.

```bash
#!/bin/bash
# auto-update-lobe-chat.sh
# Set 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 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, then do nothing
if [ $? -eq 0 ]; then
exit 0
fi
echo "Detected Lobe-Chat update"
# Remove old container
echo "Removed: $(docker rm -f Lobe-Chat)"
# Maybe you need to enter the directory where `docker-compose.yml` is located first
# cd /path/to/docker-compose-folder

# Run new container
echo "Started: $(docker-compose up)"

# 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."
```

This script can also be used in Crontab, but make sure your Crontab can find the correct Docker command. It's recommended to use absolute paths.

Configure Crontab to execute the script every 5 minutes:

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

<!-- LINK GROUP -->

[docker-pulls-link]: https://hub.docker.com/r/lobehub/lobe-chat
Expand Down
118 changes: 118 additions & 0 deletions docs/Deployment/Docker-Deployment.zh-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,69 @@ $ docker run -d -p 3210:3210 \
>
> 由于官方的 Docker 镜像构建大约需要半小时左右,如果在更新部署后会出现「存在更新」的提示,可以等待镜像构建完成后再次部署。
#### Crontab 自动更新脚本

如果你想自动获得最新的镜像,你可以如下操作。

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

```env
OPENAI_API_KEY=sk-xxxx
OPENAI_PROXY_URL=https://api-proxy.com/v1
ACCESS_CODE=arthals2333
CUSTOM_MODELS=-gpt-4,-gpt-4-32k,-gpt-3.5-turbo-16k,gpt-3.5-turbo-1106=gpt-3.5-turbo-16k,gpt-4-1106-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."
```

此脚本可以在 Crontab 中使用,但请确认你的 Crontab 可以找到正确的 Docker 命令。建议使用绝对路径。

配置 Crontab,每 5 分钟执行一次脚本:

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

### `B` Docker Compose

使用 `docker-compose` 时配置文件如下:
Expand All @@ -91,6 +154,61 @@ services:
ACCESS_CODE: lobe66
```
#### Crontab 自动更新脚本
类似地,你可以使用以下脚本来自动更新 Lobe Chat,使用 `Docker Compose` 时,环境变量无需额外配置。

```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)"
# 也许需要先进入 `docker-compose.yml` 所在的目录
# cd /path/to/docker-compose-folder

# 运行新的容器
echo "Started: $(docker-compose up)"

# 打印更新的时间和版本
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."
```

此脚本亦可以在 Crontab 中使用,但请确认你的 Crontab 可以找到正确的 Docker 命令。建议使用绝对路径。

配置 Crontab,每 5 分钟执行一次脚本:

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

[docker-pulls-link]: https://hub.docker.com/r/lobehub/lobe-chat
[docker-pulls-shield]: https://img.shields.io/docker/pulls/lobehub/lobe-chat?color=45cc11&labelColor=black&style=flat-square
[docker-release-link]: https://hub.docker.com/r/lobehub/lobe-chat
Expand Down

0 comments on commit b72f842

Please sign in to comment.