This commit is contained in:
2025-11-01 19:39:31 +08:00
parent a192e5f434
commit 3401c943ce
2 changed files with 21 additions and 4 deletions

View File

@@ -117,6 +117,12 @@ check_scripts() {
done
}
# 镜像是否存在
image_exists() {
local image_ref="$1"
docker image inspect "$image_ref" >/dev/null 2>&1
}
# 构建镜像
build_image() {
log_info "开始构建Docker镜像..."
@@ -183,10 +189,13 @@ deploy_app() {
log_info "部署应用到: $deploy_dir"
# 检查镜像
if ! docker images | grep -q "${PROJECT_NAME}:${VERSION}"; then
log_error "镜像 ${PROJECT_NAME}:${VERSION} 不存在,请先构建: $0 build"
exit 1
# 检查镜像(若不存在则自动构建一次)
if ! image_exists "${PROJECT_NAME}:${VERSION}"; then
log_warn "未找到镜像 ${PROJECT_NAME}:${VERSION},尝试自动构建..."
build_image || {
log_error "自动构建镜像失败,请手动执行: $0 build";
exit 1;
}
fi
# 创建部署目录

View File

@@ -7,3 +7,11 @@
- 目的修复构建阶段报错“Option g is ambiguous (gecos, gid, group)”,避免不同基础镜像工具链参数差异导致失败。
- 工具apply_patch补丁写入
- 结果:补丁应用成功,建议以 `docker build --no-cache` 重新构建验证。
- 时间2025-11-01 19:40UTC+8
- 动作:修复部署脚本 archive-manager.sh 镜像检查逻辑
- 位置archive-manager.shdeploy_app 函数)
- 变更:新增 `image_exists` 检查,通过 `docker image inspect` 判断本地镜像是否存在;若不存在,`deploy` 流程自动调用 `build_image` 进行构建,避免 `docker compose up` 因尝试拉取远端镜像而失败(镜像找不到)。
- 目的:解决部署时报“镜像找不到”的问题,提升一键部署体验。
- 工具apply_patch补丁写入
- 结果:补丁应用成功,可通过 `./archive-manager.sh deploy <目录>` 直接部署,首次会自动构建镜像。