refactor: improve build script and Dockerfile

- Translate rebuild.sh messages to English
- Add dockerfile syntax directive
- Fix heredoc syntax in Dockerfile

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
Timi
2026-01-19 11:05:43 +08:00
parent 50255a9093
commit 7d0c092002
2 changed files with 21 additions and 20 deletions

View File

@ -2,19 +2,19 @@
set -e
# 使用说明
# Usage
usage() {
echo "Usage: $0 <DIR> [VER] [save]"
echo ""
echo " DIR - Dockerfile 所在目录路径 (必需)"
echo " VER - 镜像版本号 (可选, 默认: 1.0.0)"
echo " save - 是否保存为 tar 文件 (可选)"
echo " DIR - Directory path containing Dockerfile (required)"
echo " VER - Image version (optional, default: 1.0.0)"
echo " save - Save image as tar file (optional)"
exit 1
}
# 检查 DIR 参数
# Check DIR parameter
if [ -z "$1" ]; then
echo "Error: 缺少 DIR 参数"
echo "Error: Missing DIR parameter"
usage
fi
@ -22,35 +22,35 @@ DIR="$1"
VER="${2:-1.0.0}"
SAVE="$3"
# 检查目录是否存在
# Check if directory exists
if [ ! -d "$DIR" ]; then
echo "Error: 目录不存在: $DIR"
echo "Error: Directory not found: $DIR"
exit 1
fi
# 从目录路径提取文件夹名作为镜像名
# Extract folder name from directory path as image name
DIR_NAME=$(basename "$DIR")
NAME="timi/${DIR_NAME}"
echo "==> 构建镜像: ${NAME}:${VER}"
echo "==> Dockerfile 路径: ${DIR}"
echo "==> Building image: ${NAME}:${VER}"
echo "==> Dockerfile path: ${DIR}"
# 删除已存在的同名镜像 (忽略错误)
# Remove existing image with same name (ignore errors)
if docker image inspect "${NAME}:${VER}" > /dev/null 2>&1; then
echo "==> 删除已存在的镜像: ${NAME}:${VER}"
echo "==> Removing existing image: ${NAME}:${VER}"
docker rmi "${NAME}:${VER}" || true
fi
# 构建镜像
echo "==> 开始构建..."
# Build image
echo "==> Starting build..."
docker build -t "${NAME}:${VER}" "$DIR"
echo "==> 构建完成: ${NAME}:${VER}"
echo "==> Build completed: ${NAME}:${VER}"
# 如果指定 save 参数,保存镜像为 tar
# If save parameter specified, save image as tar
if [ "$SAVE" = "save" ]; then
TAR_FILE="${DIR_NAME}.tar"
echo "==> 保存镜像为: ${TAR_FILE}"
echo "==> Saving image as: ${TAR_FILE}"
docker save -o "$TAR_FILE" "${NAME}:${VER}"
echo "==> 保存完成: ${TAR_FILE}"
echo "==> Save completed: ${TAR_FILE}"
fi