feat: update docker image on restart

This commit is contained in:
wizardchen
2025-09-08 19:39:30 +08:00
committed by lyingbug
parent 6330287ca9
commit 277607b92f
2 changed files with 51 additions and 25 deletions

View File

@@ -32,19 +32,6 @@ body:
validations:
required: true
- type: textarea
id: steps
attributes:
label: 重现步骤
description: 重现此 bug 的步骤
placeholder: |
1. 进入 '...'
2. 点击 '...'
3. 滚动到 '...'
4. 看到错误
validations:
required: true
- type: textarea
id: expected
attributes:
@@ -54,14 +41,6 @@ body:
validations:
required: true
- type: textarea
id: actual
attributes:
label: 实际行为
description: 描述实际发生的情况
placeholder: "实际发生了什么..."
validations:
required: true
- type: markdown
attributes:
@@ -109,6 +88,4 @@ body:
description: 请确认以下事项
options:
- label: 我已经搜索了现有的 issues确认这是一个新问题
required: true
- label: 我已经提供了足够的信息来重现这个问题
required: true

View File

@@ -29,6 +29,7 @@ show_help() {
echo " -c, --check 检查环境并诊断问题"
echo " -r, --restart 重新构建并重启指定容器"
echo " -l, --list 列出所有正在运行的容器"
echo " -p, --pull 拉取最新的Docker镜像"
echo " -v, --version 显示版本信息"
exit 0
}
@@ -332,8 +333,8 @@ start_docker() {
# 启动基本服务
log_info "启动核心服务容器..."
# 统一通过已检测到的 Compose 命令启动
PLATFORM=$PLATFORM "$DOCKER_COMPOSE_BIN" $DOCKER_COMPOSE_SUBCMD up --build -d
# 统一通过已检测到的 Compose 命令启动,添加 --pull always 确保使用最新镜像
PLATFORM=$PLATFORM "$DOCKER_COMPOSE_BIN" $DOCKER_COMPOSE_SUBCMD up --build --pull always -d
if [ $? -ne 0 ]; then
log_error "Docker容器启动失败"
return 1
@@ -393,6 +394,45 @@ list_containers() {
return 0
}
# 拉取最新的Docker镜像
pull_images() {
log_info "正在拉取最新的Docker镜像..."
# 检查Docker环境
check_docker
if [ $? -ne 0 ]; then
return 1
fi
# 检查.env文件
check_env_file
# 读取.env文件
source "$PROJECT_ROOT/.env"
storage_type=${STORAGE_TYPE:-local}
check_platform
# 进入项目根目录再执行docker-compose命令
cd "$PROJECT_ROOT"
# 拉取所有镜像
log_info "拉取所有服务的最新镜像..."
PLATFORM=$PLATFORM "$DOCKER_COMPOSE_BIN" $DOCKER_COMPOSE_SUBCMD pull
if [ $? -ne 0 ]; then
log_error "镜像拉取失败"
return 1
fi
log_success "所有镜像已成功拉取到最新版本"
# 显示拉取的镜像信息
log_info "已拉取的镜像:"
docker images --format "table {{.Repository}}\t{{.Tag}}\t{{.CreatedAt}}\t{{.Size}}" | head -10
return 0
}
# 重启指定容器
restart_container() {
local container_name="$1"
@@ -523,6 +563,7 @@ STOP_SERVICES=false
CHECK_ENVIRONMENT=false
LIST_CONTAINERS=false
RESTART_CONTAINER=false
PULL_IMAGES=false
CONTAINER_NAME=""
# 没有参数时默认启动所有服务
@@ -548,6 +589,8 @@ while [ "$1" != "" ]; do
;;
-l | --list ) LIST_CONTAINERS=true
;;
-p | --pull ) PULL_IMAGES=true
;;
-r | --restart ) RESTART_CONTAINER=true
CONTAINER_NAME="$2"
shift
@@ -573,6 +616,12 @@ if [ "$LIST_CONTAINERS" = true ]; then
exit $?
fi
# 拉取最新镜像
if [ "$PULL_IMAGES" = true ]; then
pull_images
exit $?
fi
# 重启指定容器
if [ "$RESTART_CONTAINER" = true ]; then
restart_container "$CONTAINER_NAME"