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

REM === 載入 .env 變數（忽略註解與空行） ===
for /f "usebackq tokens=1,* delims==" %%a in (".env") do (
    if "%%a" neq "" (
        if not "%%a"=="REM" (
            set "%%a=%%b"
        )
    )
)

REM === 檢查變數 ========================
echo -----------------------------------
echo Check: IMAGE_PROJ_NAME=!IMAGE_PROJ_NAME!
echo Check: IMAGE_NAME=!IMAGE_NAME!
echo Check: TAG_VERSION=!TAG_VERSION!
echo Check: REMOTE_URL=!REMOTE_URL!
echo -----------------------------------
echo.

REM === 設定目標 image tag ==============
set "LOCAL_TAG=!IMAGE_NAME!:!TAG_VERSION!"
set "REMOTE_TAG=!REMOTE_URL!/!IMAGE_PROJ_NAME!/!IMAGE_NAME!:!TAG_VERSION!"


REM === 流程 ============================

:: 1. 登入 遠端倉庫
echo.
echo Login...
docker login !REMOTE_URL!

:: 2. 標簽 標記映像檔
echo.
echo Tagging image...
docker tag !LOCAL_TAG! !REMOTE_TAG!

:: 3. 推送 映像檔
echo.
echo Pushing image...
docker push !REMOTE_TAG!

:: 4. 完成
echo Done.
pause
