@echo off
setlocal
cd /d "%~dp0"

echo =======================================================
echo Building and pushing to registry.cn-qingdao.aliyuncs.com/fzxs/
echo =======================================================

echo.
echo ^>^> Building server image...
docker build -t registry.cn-qingdao.aliyuncs.com/fzxs/aurak-server:latest -f ./server/Dockerfile ./server
if %errorlevel% neq 0 (
    echo Server build failed! Please check if Docker is running and network is connected.
    pause
    exit /b %errorlevel%
)

echo.
echo ^>^> Building web image...
docker build -t registry.cn-qingdao.aliyuncs.com/fzxs/aurak-web:latest --build-arg VITE_API_BASE_URL=/api -f ./web/Dockerfile .
if %errorlevel% neq 0 (
    echo Web build failed! Please check if Docker is running and network is connected.
    pause
    exit /b %errorlevel%
)

echo.
echo ^>^> Building libreoffice image...
docker build -t registry.cn-qingdao.aliyuncs.com/fzxs/aurak-libreoffice:latest -f ./libreoffice-server/Dockerfile ./libreoffice-server
if %errorlevel% neq 0 (
    echo LibreOffice build failed! Please check if Docker is running and network is connected.
    pause
    exit /b %errorlevel%
)

echo.
echo ^>^> Pushing server image...
docker push registry.cn-qingdao.aliyuncs.com/fzxs/aurak-server:latest
if %errorlevel% neq 0 (
    echo Push server failed! Please check if you have logged in via: docker login --username=YOUR_USERNAME registry.cn-qingdao.aliyuncs.com
    pause
    exit /b %errorlevel%
)

echo.
echo ^>^> Pushing web image...
docker push registry.cn-qingdao.aliyuncs.com/fzxs/aurak-web:latest
if %errorlevel% neq 0 (
    echo Push web failed! Please check if you have logged in to Aliyun registry.
    pause
    exit /b %errorlevel%
)

echo.
echo ^>^> Pushing libreoffice image...
docker push registry.cn-qingdao.aliyuncs.com/fzxs/aurak-libreoffice:latest
if %errorlevel% neq 0 (
    echo Push libreoffice failed! Please check if you have logged in to Aliyun registry.
    pause
    exit /b %errorlevel%
)

echo.
echo =======================================================
echo Images successfully built and pushed!
echo =======================================================
pause
