@echo off
REM 泉友米车友会 - Docker 构建脚本 (Windows)
REM 版本: 0.0.1

echo ==========================================
echo 泉友米车友会 Docker 镜像构建
echo 版本: 0.0.1
echo ==========================================

REM 检查 Docker 是否安装
docker --version >nul 2>&1
if errorlevel 1 (
    echo 错误: Docker 未安装，请先安装 Docker Desktop
    pause
    exit /b 1
)

echo.
echo 开始构建 Docker 镜像...
docker build -t quanyoumi-app:0.0.1 -t quanyoumi-app:latest .

if errorlevel 1 (
    echo.
    echo 构建失败！
    pause
    exit /b 1
)

echo.
echo ==========================================
echo 构建完成！
echo ==========================================
echo.
echo 镜像信息:
docker images | findstr quanyoumi-app
echo.

REM 标记镜像到阿里云仓库
echo 正在标记镜像到阿里云仓库...
docker tag quanyoumi-app:0.0.1 registry.cn-hangzhou.aliyuncs.com/yvan329/quanyoumi-app:0.0.1
docker tag quanyoumi-app:latest registry.cn-hangzhou.aliyuncs.com/yvan329/quanyoumi-app:latest

echo.
echo 正在推送镜像到阿里云仓库...
docker push registry.cn-hangzhou.aliyuncs.com/yvan329/quanyoumi-app:0.0.1
docker push registry.cn-hangzhou.aliyuncs.com/yvan329/quanyoumi-app:latest

if errorlevel 1 (
    echo.
    echo 推送失败！请检查是否已登录阿里云镜像仓库
    echo 登录命令: docker login --username=你的用户名 registry.cn-hangzhou.aliyuncs.com
    pause
    exit /b 1
)

echo.
echo ==========================================
echo 推送完成！
echo ==========================================
echo.
echo 镜像地址:
echo   registry.cn-hangzhou.aliyuncs.com/yvan329/quanyoumi-app:0.0.1
echo   registry.cn-hangzhou.aliyuncs.com/yvan329/quanyoumi-app:latest
echo.
echo 在 NAS 上使用:
echo   docker pull registry.cn-hangzhou.aliyuncs.com/yvan329/quanyoumi-app:0.0.1
echo   docker-compose up -d
echo.
pause
