From 277607b92f2e80d76fe8d881a17dd062ae99493f Mon Sep 17 00:00:00 2001 From: wizardchen Date: Mon, 8 Sep 2025 19:39:30 +0800 Subject: [PATCH] feat: update docker image on restart --- .github/ISSUE_TEMPLATE/bug_report.yml | 23 ------------ scripts/start_all.sh | 53 ++++++++++++++++++++++++++- 2 files changed, 51 insertions(+), 25 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml index eb25d5281..cbf2cd28b 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.yml +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -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 \ No newline at end of file diff --git a/scripts/start_all.sh b/scripts/start_all.sh index 070ce12e0..f2ec41083 100755 --- a/scripts/start_all.sh +++ b/scripts/start_all.sh @@ -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"