262 lines
8.0 KiB
Batchfile
262 lines
8.0 KiB
Batchfile
@echo off
|
|
setlocal EnableDelayedExpansion
|
|
|
|
REM ================================================================
|
|
REM build-and-export-all-themes.bat
|
|
REM
|
|
REM Four-theme player image batch builder.
|
|
REM Automatically switches Git branches to build each theme.
|
|
REM Usage:
|
|
REM docs\docker\build-and-export-all-themes.bat
|
|
REM docs\docker\build-and-export-all-themes.bat --use-cache
|
|
REM docs\docker\build-and-export-all-themes.bat --export-only
|
|
REM docs\docker\build-and-export-all-themes.bat --skip-api-admin
|
|
REM
|
|
REM Output files (project root, already in .gitignore):
|
|
REM thebet365-player-main.tar -> thebet365-player:main
|
|
REM thebet365-player-theme-2.tar -> thebet365-player:theme-2
|
|
REM thebet365-player-theme-3.tar -> thebet365-player:theme-3
|
|
REM thebet365-player-theme-4.tar -> thebet365-player:theme-4
|
|
REM thebet365-images-latest.tar -> api:latest + admin:latest
|
|
REM ================================================================
|
|
|
|
cd /d "%~dp0..\.."
|
|
set "ROOT_DIR=%CD%"
|
|
|
|
set "USE_CACHE=0"
|
|
set "EXPORT_ONLY=0"
|
|
set "SKIP_API_ADMIN=0"
|
|
|
|
:parse_args
|
|
if "%~1"=="" goto args_done
|
|
if /i "%~1"=="--use-cache" set "USE_CACHE=1" & shift & goto parse_args
|
|
if /i "%~1"=="--export-only" set "EXPORT_ONLY=1" & shift & goto parse_args
|
|
if /i "%~1"=="--skip-api-admin" set "SKIP_API_ADMIN=1" & shift & goto parse_args
|
|
if /i "%~1"=="-h" goto show_help
|
|
if /i "%~1"=="--help" goto show_help
|
|
if /i "%~1"=="/?" goto show_help
|
|
echo Unknown argument: %~1
|
|
goto show_help
|
|
|
|
:show_help
|
|
echo.
|
|
echo Usage: docs\docker\build-and-export-all-themes.bat [options]
|
|
echo.
|
|
echo --use-cache Use Docker build cache (default: --no-cache)
|
|
echo --export-only Skip build, export existing images only
|
|
echo --skip-api-admin Only build 4 player themes, skip api/admin
|
|
echo -h, --help Show this help
|
|
echo.
|
|
echo Output (project root):
|
|
echo thebet365-player-main.tar
|
|
echo thebet365-player-theme-2.tar
|
|
echo thebet365-player-theme-3.tar
|
|
echo thebet365-player-theme-4.tar
|
|
echo thebet365-images-latest.tar (api + admin, unless --skip-api-admin)
|
|
echo.
|
|
exit /b 0
|
|
|
|
:args_done
|
|
|
|
REM -- Validate docker is available
|
|
where docker >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo ERROR: docker not found. Please start Docker Desktop first.
|
|
exit /b 1
|
|
)
|
|
|
|
REM -- Record current branch so we can restore it
|
|
set "ORIGINAL_BRANCH="
|
|
for /f "delims=" %%B in ('git rev-parse --abbrev-ref HEAD 2^>nul') do set "ORIGINAL_BRANCH=%%B"
|
|
if not defined ORIGINAL_BRANCH (
|
|
echo ERROR: Cannot determine current Git branch. Run this script from the repo root.
|
|
exit /b 1
|
|
)
|
|
echo [INFO] Current branch: %ORIGINAL_BRANCH%
|
|
|
|
REM -- Stash any local changes so branch switching works cleanly
|
|
set "DID_STASH=0"
|
|
git diff --quiet 2>nul
|
|
set "D1=!ERRORLEVEL!"
|
|
git diff --cached --quiet 2>nul
|
|
set "D2=!ERRORLEVEL!"
|
|
if not "!D1!"=="0" goto do_stash
|
|
if not "!D2!"=="0" goto do_stash
|
|
goto stash_done
|
|
|
|
:do_stash
|
|
echo [INFO] Stashing local changes before branch switching...
|
|
git stash push -m "build-all-themes auto-stash" >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo [WARN] git stash failed. Branch switching may fail if there are conflicts.
|
|
) else (
|
|
set "DID_STASH=1"
|
|
echo [INFO] Changes stashed.
|
|
)
|
|
|
|
:stash_done
|
|
|
|
REM -- Build extra arguments for the base script
|
|
set "EXTRA_ARGS="
|
|
if "%USE_CACHE%"=="1" set "EXTRA_ARGS=!EXTRA_ARGS! --use-cache"
|
|
if "%EXPORT_ONLY%"=="1" set "EXTRA_ARGS=!EXTRA_ARGS! --export-only"
|
|
|
|
set "FAILED_THEMES="
|
|
set "SUCCESS_COUNT=0"
|
|
|
|
REM ================================================================
|
|
REM Build each player theme
|
|
REM ================================================================
|
|
|
|
call :build_theme main main
|
|
call :build_theme theme-2 theme-2
|
|
call :build_theme theme-3 theme-3
|
|
call :build_theme theme-4 theme-4
|
|
|
|
REM -- Restore original branch
|
|
echo.
|
|
echo [INFO] Restoring original branch: %ORIGINAL_BRANCH%
|
|
cd /d "%ROOT_DIR%"
|
|
git checkout %ORIGINAL_BRANCH% >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo [WARN] Could not restore branch %ORIGINAL_BRANCH%. Run: git checkout %ORIGINAL_BRANCH%
|
|
) else (
|
|
echo [INFO] Restored to %ORIGINAL_BRANCH%
|
|
)
|
|
|
|
REM -- Pop stash if we stashed earlier
|
|
if "%DID_STASH%"=="1" (
|
|
echo [INFO] Restoring stashed changes...
|
|
git stash pop >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo [WARN] git stash pop failed. Run: git stash pop
|
|
) else (
|
|
echo [INFO] Stash restored.
|
|
)
|
|
)
|
|
|
|
REM -- Build api + admin on main branch
|
|
if "%SKIP_API_ADMIN%"=="1" goto skip_api_admin
|
|
|
|
echo.
|
|
echo [INFO] Building api + admin (tag: latest) on branch main...
|
|
cd /d "%ROOT_DIR%"
|
|
git checkout main >nul 2>&1
|
|
cd /d "%ROOT_DIR%"
|
|
call docs\docker\build-and-export-images.bat --tag latest!EXTRA_ARGS!
|
|
set "API_ERR=!ERRORLEVEL!"
|
|
cd /d "%ROOT_DIR%"
|
|
if "!API_ERR!"=="0" goto api_ok
|
|
echo [ERROR] api/admin build failed
|
|
set "FAILED_THEMES=!FAILED_THEMES! api/admin"
|
|
goto after_api_admin
|
|
|
|
:api_ok
|
|
set /a SUCCESS_COUNT+=1
|
|
|
|
:after_api_admin
|
|
echo.
|
|
echo [INFO] Restoring original branch: %ORIGINAL_BRANCH%
|
|
git checkout %ORIGINAL_BRANCH% >nul 2>&1
|
|
|
|
:skip_api_admin
|
|
|
|
REM ================================================================
|
|
REM Summary
|
|
REM ================================================================
|
|
echo.
|
|
echo ================================================================
|
|
echo BUILD SUMMARY
|
|
echo ================================================================
|
|
echo Succeeded: !SUCCESS_COUNT! task(s)
|
|
if not defined FAILED_THEMES goto all_ok
|
|
|
|
echo Failed: !FAILED_THEMES!
|
|
echo.
|
|
echo Tip: Retry failed themes manually:
|
|
echo git checkout ^<branch^>
|
|
echo docs\docker\build-and-export-images.bat --service player --tag ^<tag^>
|
|
echo ================================================================
|
|
echo.
|
|
endlocal
|
|
exit /b 1
|
|
|
|
:all_ok
|
|
echo.
|
|
echo All done! Output files in project root:
|
|
echo thebet365-player-main.tar
|
|
echo thebet365-player-theme-2.tar
|
|
echo thebet365-player-theme-3.tar
|
|
echo thebet365-player-theme-4.tar
|
|
if "%SKIP_API_ADMIN%"=="0" (
|
|
echo thebet365-images-latest.tar (api + admin)
|
|
)
|
|
echo.
|
|
echo Server import commands:
|
|
echo docker load -i thebet365-images-latest.tar
|
|
echo docker load -i thebet365-player-main.tar
|
|
echo docker load -i thebet365-player-theme-2.tar
|
|
echo docker load -i thebet365-player-theme-3.tar
|
|
echo docker load -i thebet365-player-theme-4.tar
|
|
echo.
|
|
echo Start (first multi-theme deploy):
|
|
echo docker compose -f docker-compose.prod.yml -f docker-compose.themes.yml --env-file .env.docker up -d
|
|
echo ================================================================
|
|
echo.
|
|
endlocal
|
|
exit /b 0
|
|
|
|
|
|
REM ================================================================
|
|
REM :build_theme <branch> <tag>
|
|
REM Switch to branch, build player, mark success/fail.
|
|
REM Uses cd /d ROOT_DIR instead of pushd to avoid stack issues.
|
|
REM ================================================================
|
|
:build_theme
|
|
set "THEME_BRANCH=%~1"
|
|
set "THEME_TAG=%~2"
|
|
|
|
echo.
|
|
echo ----------------------------------------------------------------
|
|
echo [INFO] Theme: %THEME_BRANCH% (image tag: %THEME_TAG%)
|
|
echo ----------------------------------------------------------------
|
|
|
|
cd /d "%ROOT_DIR%"
|
|
git checkout %THEME_BRANCH% >nul 2>&1
|
|
if errorlevel 1 (
|
|
echo [ERROR] Cannot switch to branch %THEME_BRANCH% -- skipping
|
|
set "FAILED_THEMES=!FAILED_THEMES! %THEME_BRANCH%"
|
|
exit /b 0
|
|
)
|
|
echo [INFO] Switched to %THEME_BRANCH%
|
|
|
|
cd /d "%ROOT_DIR%"
|
|
call docs\docker\build-and-export-images.bat --service player --tag %THEME_TAG%!EXTRA_ARGS!
|
|
set "BUILD_ERR=!ERRORLEVEL!"
|
|
|
|
cd /d "%ROOT_DIR%"
|
|
if "!BUILD_ERR!"=="0" goto build_ok_%THEME_TAG%
|
|
echo [ERROR] Player build failed for %THEME_BRANCH%
|
|
set "FAILED_THEMES=!FAILED_THEMES! %THEME_BRANCH%"
|
|
exit /b 0
|
|
|
|
:build_ok_main
|
|
echo [OK] thebet365-player:main exported successfully
|
|
set /a SUCCESS_COUNT+=1
|
|
exit /b 0
|
|
|
|
:build_ok_theme-2
|
|
echo [OK] thebet365-player:theme-2 exported successfully
|
|
set /a SUCCESS_COUNT+=1
|
|
exit /b 0
|
|
|
|
:build_ok_theme-3
|
|
echo [OK] thebet365-player:theme-3 exported successfully
|
|
set /a SUCCESS_COUNT+=1
|
|
exit /b 0
|
|
|
|
:build_ok_theme-4
|
|
echo [OK] thebet365-player:theme-4 exported successfully
|
|
set /a SUCCESS_COUNT+=1
|
|
exit /b 0
|