@echo off
REM Build and push Docker image to Local Docker Registry
REM Usage: build-and-push.bat [VERSION_TAG]

setlocal enabledelayedexpansion

REM Configuration
set LOCAL_REGISTRY=192.168.0.107:5000
set REPO=owi-cms
set IMAGE_NAME=%LOCAL_REGISTRY%/%REPO%

REM Get version tag (default to 'latest')
if "%~1"=="" (
  set VERSION_TAG=latest
) else (
  set VERSION_TAG=%~1
)

set FULL_IMAGE=%IMAGE_NAME%:%VERSION_TAG%

echo.
echo ==========================================
echo Building Docker image: %FULL_IMAGE%
echo ==========================================
echo.

REM Build the Docker image
docker build ^
  --tag %FULL_IMAGE% ^
  --tag %IMAGE_NAME%:%VERSION_TAG% ^
  --file Dockerfile ^
  .

if %ERRORLEVEL% neq 0 (
  echo.
  echo xx Build failed!
  exit /b 1
)

echo.
echo OK Build successful!
echo.
echo ==========================================
echo Next steps:
echo ==========================================
echo.
echo 1. Push to Local Docker Registry:
echo    docker push %FULL_IMAGE%
echo    docker push %IMAGE_NAME%:%VERSION_TAG%
echo.
echo 2. Push to GitHub Container Registry:
echo    docker push %FULL_IMAGE%
echo    docker push %IMAGE_NAME%:%VERSION_TAG%
echo.
echo 3. Update Dockge to pull the new image:
echo    Image: %FULL_IMAGE%
echo    Registry: %GITHUB_REGISTRY%
echo.
pause
