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
# 创建部署目录