#!/bin/bash

# 本地构建 nginx 镜像
# 使用方法: 在 docker/nginx 目录下执行 ./build.sh

set -e

# 获取脚本所在目录
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# 项目根目录（脚本所在目录的上两级）
PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"

# 配置变量
IMAGE_NAME="polaris-nginx"
VERSION="latest"

echo "=========================================="
echo "开始构建本地 Nginx 镜像"
echo "=========================================="
echo "项目根目录: ${PROJECT_ROOT}"
echo "镜像名称: ${IMAGE_NAME}:${VERSION}"
echo "=========================================="

# 切换到项目根目录作为构建上下文
cd "${PROJECT_ROOT}"

# 构建镜像
echo ""
echo "开始构建镜像..."
docker build -t ${IMAGE_NAME}:${VERSION} -f docker/nginx/Dockerfile .

echo ""
echo "=========================================="
echo "构建完成！"
echo "本地镜像: ${IMAGE_NAME}:${VERSION}"
echo "=========================================="