|
|
|
@@ -0,0 +1,288 @@
|
|
|
|
|
@echo off
|
|
|
|
|
REM SerpentRace Deployment Package Creator for Windows
|
|
|
|
|
REM This script creates a complete deployment package with Docker images
|
|
|
|
|
|
|
|
|
|
setlocal EnableDelayedExpansion
|
|
|
|
|
|
|
|
|
|
echo ========================================
|
|
|
|
|
echo SerpentRace Deployment Package Creator
|
|
|
|
|
echo ========================================
|
|
|
|
|
echo.
|
|
|
|
|
|
|
|
|
|
REM Check if Docker is installed
|
|
|
|
|
where docker >nul 2>nul
|
|
|
|
|
if %errorlevel% neq 0 (
|
|
|
|
|
echo [ERROR] Docker is not installed. Please install Docker first.
|
|
|
|
|
exit /b 1
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
REM Check if git is installed
|
|
|
|
|
where git >nul 2>nul
|
|
|
|
|
if %errorlevel% neq 0 (
|
|
|
|
|
echo [ERROR] Git is not installed. Please install Git first.
|
|
|
|
|
exit /b 1
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
REM Get current branch
|
|
|
|
|
for /f "tokens=*" %%i in ('git branch --show-current') do set CURRENT_BRANCH=%%i
|
|
|
|
|
echo [INFO] Current branch: %CURRENT_BRANCH%
|
|
|
|
|
|
|
|
|
|
REM Check for uncommitted changes
|
|
|
|
|
git diff-index --quiet HEAD --
|
|
|
|
|
if %errorlevel% neq 0 (
|
|
|
|
|
echo [WARN] You have uncommitted changes in %CURRENT_BRANCH%
|
|
|
|
|
echo [WARN] Please commit or stash your changes before creating deployment
|
|
|
|
|
choice /C YN /M "Continue anyway?"
|
|
|
|
|
if errorlevel 2 exit /b 1
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
echo.
|
|
|
|
|
echo [INFO] Step 1/7: Switching to deployment branch...
|
|
|
|
|
git checkout deployment 2>nul
|
|
|
|
|
if %errorlevel% neq 0 (
|
|
|
|
|
echo [INFO] Deployment branch doesn't exist, creating it...
|
|
|
|
|
git checkout -b deployment
|
|
|
|
|
if %errorlevel% neq 0 (
|
|
|
|
|
echo [ERROR] Failed to create deployment branch
|
|
|
|
|
exit /b 1
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
echo.
|
|
|
|
|
echo [INFO] Step 2/7: Copying necessary files from main branch...
|
|
|
|
|
|
|
|
|
|
REM Create deployment directory if it doesn't exist
|
|
|
|
|
if not exist "SerpentRace_Docker\deployment" mkdir SerpentRace_Docker\deployment
|
|
|
|
|
|
|
|
|
|
REM Copy deployment configuration files from main
|
|
|
|
|
echo [INFO] Copying docker-compose.deploy.yml...
|
|
|
|
|
git show main:SerpentRace_Docker/deployment/docker-compose.deploy.yml > SerpentRace_Docker\deployment\docker-compose.deploy.yml 2>nul
|
|
|
|
|
if %errorlevel% neq 0 (
|
|
|
|
|
echo [WARN] docker-compose.deploy.yml not found in main, using current version
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
echo [INFO] Copying .env.server template...
|
|
|
|
|
git show main:SerpentRace_Docker/deployment/.env.server > SerpentRace_Docker\deployment\.env.server 2>nul
|
|
|
|
|
if %errorlevel% neq 0 (
|
|
|
|
|
echo [WARN] .env.server not found in main, creating template...
|
|
|
|
|
(
|
|
|
|
|
echo # SerpentRace Production Environment Configuration
|
|
|
|
|
echo # IMPORTANT: Change all placeholder values before deployment!
|
|
|
|
|
echo.
|
|
|
|
|
echo # Database Configuration
|
|
|
|
|
echo POSTGRES_USER=postgres
|
|
|
|
|
echo POSTGRES_PASSWORD=CHANGE_THIS_PASSWORD
|
|
|
|
|
echo POSTGRES_DB=serpentrace
|
|
|
|
|
echo.
|
|
|
|
|
echo # JWT Configuration
|
|
|
|
|
echo JWT_SECRET=CHANGE_THIS_TO_A_RANDOM_32_CHAR_STRING
|
|
|
|
|
echo JWT_EXPIRATION=30m
|
|
|
|
|
echo JWT_REFRESH_EXPIRATION=7d
|
|
|
|
|
echo.
|
|
|
|
|
echo # Redis Configuration
|
|
|
|
|
echo REDIS_PASSWORD=CHANGE_THIS_REDIS_PASSWORD
|
|
|
|
|
echo.
|
|
|
|
|
echo # MinIO Configuration
|
|
|
|
|
echo MINIO_ROOT_USER=admin
|
|
|
|
|
echo MINIO_ROOT_PASSWORD=CHANGE_THIS_MINIO_PASSWORD
|
|
|
|
|
echo MINIO_ACCESS_KEY=serpentrace-access
|
|
|
|
|
echo MINIO_SECRET_KEY=CHANGE_THIS_MINIO_SECRET
|
|
|
|
|
echo.
|
|
|
|
|
echo # Email Configuration
|
|
|
|
|
echo EMAIL_HOST=smtp.gmail.com
|
|
|
|
|
echo EMAIL_PORT=587
|
|
|
|
|
echo EMAIL_SECURE=false
|
|
|
|
|
echo EMAIL_USER=your_email@gmail.com
|
|
|
|
|
echo EMAIL_PASS=your_email_password
|
|
|
|
|
echo EMAIL_FROM=SerpentRace ^<noreply@serpentrace.com^>
|
|
|
|
|
echo.
|
|
|
|
|
echo # Application Configuration
|
|
|
|
|
echo NODE_ENV=production
|
|
|
|
|
echo APP_BASE_URL=http://localhost
|
|
|
|
|
echo PORT=3000
|
|
|
|
|
) > SerpentRace_Docker\deployment\.env.server
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
echo [INFO] Copying README.md...
|
|
|
|
|
git show main:SerpentRace_Docker/deployment/README.md > SerpentRace_Docker\deployment\README.md 2>nul
|
|
|
|
|
if %errorlevel% neq 0 (
|
|
|
|
|
echo [WARN] README.md not found in main, using current version
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
echo [INFO] Copying load-images scripts...
|
|
|
|
|
git show main:SerpentRace_Docker/deployment/load-images.bat > SerpentRace_Docker\deployment\load-images.bat 2>nul
|
|
|
|
|
git show main:SerpentRace_Docker/deployment/load-images.sh > SerpentRace_Docker\deployment\load-images.sh 2>nul
|
|
|
|
|
|
|
|
|
|
echo [INFO] Copying SQL schema...
|
|
|
|
|
git show main:SerpentRace_Docker/deployment/sql_schema_only.sql > SerpentRace_Docker\deployment\sql_schema_only.sql 2>nul
|
|
|
|
|
|
|
|
|
|
echo [INFO] Copying pgAdmin configuration...
|
|
|
|
|
git show main:SerpentRace_Docker/deployment/pgadmin_servers_deployment.json > SerpentRace_Docker\deployment\pgadmin_servers_deployment.json 2>nul
|
|
|
|
|
if %errorlevel% neq 0 (
|
|
|
|
|
echo [WARN] pgadmin_servers_deployment.json not found in main, creating default...
|
|
|
|
|
(
|
|
|
|
|
echo {
|
|
|
|
|
echo "Servers": {
|
|
|
|
|
echo "1": {
|
|
|
|
|
echo "Name": "SerpentRace Production",
|
|
|
|
|
echo "Group": "Servers",
|
|
|
|
|
echo "Host": "postgres",
|
|
|
|
|
echo "Port": 5432,
|
|
|
|
|
echo "MaintenanceDB": "serpentrace",
|
|
|
|
|
echo "Username": "postgres",
|
|
|
|
|
echo "SSLMode": "prefer",
|
|
|
|
|
echo "Comment": "SerpentRace Production Database"
|
|
|
|
|
echo }
|
|
|
|
|
echo }
|
|
|
|
|
echo }
|
|
|
|
|
) > SerpentRace_Docker\deployment\pgadmin_servers_deployment.json
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
echo.
|
|
|
|
|
echo [INFO] Step 3/7: Building Docker images from %CURRENT_BRANCH% branch...
|
|
|
|
|
|
|
|
|
|
REM Switch back to current branch to build with latest code
|
|
|
|
|
echo [INFO] Switching back to %CURRENT_BRANCH% to build images...
|
|
|
|
|
git checkout %CURRENT_BRANCH%
|
|
|
|
|
if %errorlevel% neq 0 (
|
|
|
|
|
echo [ERROR] Failed to switch back to %CURRENT_BRANCH%
|
|
|
|
|
exit /b 1
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
REM Copy docker-compose file for building
|
|
|
|
|
echo [INFO] Checking out docker-compose files...
|
|
|
|
|
git show %CURRENT_BRANCH%:SerpentRace_Docker/docker-compose.prod.yml > SerpentRace_Docker\docker-compose.prod.yml.temp
|
|
|
|
|
if %errorlevel% neq 0 (
|
|
|
|
|
echo [ERROR] docker-compose.prod.yml not found in %CURRENT_BRANCH% branch
|
|
|
|
|
exit /b 1
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
REM Build images using production compose file
|
|
|
|
|
cd SerpentRace_Docker
|
|
|
|
|
echo [INFO] Building production Docker images (this may take several minutes)...
|
|
|
|
|
docker-compose -f docker-compose.prod.yml.temp build --no-cache
|
|
|
|
|
if %errorlevel% neq 0 (
|
|
|
|
|
echo [ERROR] Failed to build Docker images
|
|
|
|
|
cd ..
|
|
|
|
|
del SerpentRace_Docker\docker-compose.prod.yml.temp
|
|
|
|
|
git checkout deployment
|
|
|
|
|
exit /b 1
|
|
|
|
|
)
|
|
|
|
|
cd ..
|
|
|
|
|
|
|
|
|
|
REM Clean up temp file
|
|
|
|
|
del SerpentRace_Docker\docker-compose.prod.yml.temp
|
|
|
|
|
|
|
|
|
|
REM Switch to deployment branch for packaging
|
|
|
|
|
echo [INFO] Switching to deployment branch for packaging...
|
|
|
|
|
git checkout deployment
|
|
|
|
|
if %errorlevel% neq 0 (
|
|
|
|
|
echo [ERROR] Failed to switch to deployment branch
|
|
|
|
|
exit /b 1
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
echo.
|
|
|
|
|
echo [INFO] Step 4/7: Identifying built images...
|
|
|
|
|
|
|
|
|
|
REM Get list of images built for SerpentRace
|
|
|
|
|
set IMAGE_LIST=
|
|
|
|
|
for /f "tokens=*" %%i in ('docker images --filter "reference=serpentrace*" --format "{{.Repository}}:{{.Tag}}"') do (
|
|
|
|
|
set IMAGE_LIST=!IMAGE_LIST! %%i
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
if "!IMAGE_LIST!"==" " (
|
|
|
|
|
echo [ERROR] No SerpentRace images found. Build may have failed.
|
|
|
|
|
git checkout %CURRENT_BRANCH%
|
|
|
|
|
exit /b 1
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
echo [INFO] Found images: !IMAGE_LIST!
|
|
|
|
|
|
|
|
|
|
echo.
|
|
|
|
|
echo [INFO] Step 5/7: Saving Docker images to tar file...
|
|
|
|
|
echo [INFO] This may take several minutes depending on image sizes...
|
|
|
|
|
|
|
|
|
|
docker save -o SerpentRace_Docker\deployment\serpentRaceDocker.tar !IMAGE_LIST!
|
|
|
|
|
if %errorlevel% neq 0 (
|
|
|
|
|
echo [ERROR] Failed to save Docker images to tar file
|
|
|
|
|
git checkout %CURRENT_BRANCH%
|
|
|
|
|
exit /b 1
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
REM Get file size
|
|
|
|
|
for %%A in ("SerpentRace_Docker\deployment\serpentRaceDocker.tar") do set TAR_SIZE=%%~zA
|
|
|
|
|
set /a TAR_SIZE_MB=!TAR_SIZE! / 1024 / 1024
|
|
|
|
|
echo [INFO] Created serpentRaceDocker.tar (Size: !TAR_SIZE_MB! MB)
|
|
|
|
|
|
|
|
|
|
echo.
|
|
|
|
|
echo [INFO] Step 6/7: Adding files to deployment branch...
|
|
|
|
|
|
|
|
|
|
REM Add only deployment files to git
|
|
|
|
|
git add SerpentRace_Docker\deployment\*
|
|
|
|
|
|
|
|
|
|
REM Check if there are changes to commit
|
|
|
|
|
git diff --cached --quiet
|
|
|
|
|
if %errorlevel% neq 0 (
|
|
|
|
|
echo [INFO] Committing deployment package...
|
|
|
|
|
git commit -m "Add deployment package with Docker images - %date% %time%"
|
|
|
|
|
if %errorlevel% neq 0 (
|
|
|
|
|
echo [ERROR] Failed to commit deployment files
|
|
|
|
|
git checkout %CURRENT_BRANCH%
|
|
|
|
|
exit /b 1
|
|
|
|
|
)
|
|
|
|
|
) else (
|
|
|
|
|
echo [INFO] No changes to commit (deployment files are up to date)
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
echo.
|
|
|
|
|
echo [INFO] Step 7/7: Finalizing...
|
|
|
|
|
|
|
|
|
|
REM Create deployment info file
|
|
|
|
|
(
|
|
|
|
|
echo SerpentRace Deployment Package
|
|
|
|
|
echo ==============================
|
|
|
|
|
echo.
|
|
|
|
|
echo Created: %date% %time%
|
|
|
|
|
echo Source Branch: %CURRENT_BRANCH%
|
|
|
|
|
echo Docker Images: !IMAGE_LIST!
|
|
|
|
|
echo Package Size: !TAR_SIZE_MB! MB
|
|
|
|
|
echo.
|
|
|
|
|
echo Files included:
|
|
|
|
|
echo - serpentRaceDocker.tar
|
|
|
|
|
echo - docker-compose.deploy.yml
|
|
|
|
|
echo - .env.server
|
|
|
|
|
echo - load-images.bat
|
|
|
|
|
echo - load-images.sh
|
|
|
|
|
echo - README.md
|
|
|
|
|
echo - sql_schema_only.sql
|
|
|
|
|
echo - pgadmin_servers_deployment.json
|
|
|
|
|
echo.
|
|
|
|
|
echo To deploy:
|
|
|
|
|
echo 1. Copy the entire SerpentRace_Docker/deployment folder to your server
|
|
|
|
|
echo 2. Edit .env.server with your configuration
|
|
|
|
|
echo 3. Run load-images.bat (Windows^) or load-images.sh (Linux^)
|
|
|
|
|
) > SerpentRace_Docker\deployment\DEPLOYMENT_INFO.txt
|
|
|
|
|
|
|
|
|
|
git add SerpentRace_Docker\deployment\DEPLOYMENT_INFO.txt
|
|
|
|
|
git commit -m "Add deployment info file" 2>nul
|
|
|
|
|
|
|
|
|
|
echo.
|
|
|
|
|
echo ========================================
|
|
|
|
|
echo [SUCCESS] Deployment package created!
|
|
|
|
|
echo ========================================
|
|
|
|
|
echo.
|
|
|
|
|
echo Deployment branch: deployment
|
|
|
|
|
echo Package location: SerpentRace_Docker\deployment\
|
|
|
|
|
echo Package size: !TAR_SIZE_MB! MB
|
|
|
|
|
echo.
|
|
|
|
|
echo Next steps:
|
|
|
|
|
echo 1. Review the files in SerpentRace_Docker\deployment\
|
|
|
|
|
echo 2. Optionally push to remote: git push origin deployment
|
|
|
|
|
echo 3. Copy deployment folder to your production server
|
|
|
|
|
echo.
|
|
|
|
|
echo Switching back to %CURRENT_BRANCH% branch...
|
|
|
|
|
git checkout %CURRENT_BRANCH%
|
|
|
|
|
|
|
|
|
|
echo.
|
|
|
|
|
echo [INFO] Deployment package creation complete!
|
|
|
|
|
pause
|