-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdeploy-server.bat
More file actions
138 lines (125 loc) · 4.31 KB
/
Copy pathdeploy-server.bat
File metadata and controls
138 lines (125 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
@echo off
setlocal
set "BUNDLE_DIR=deploy-bundle"
set "ZIP_NAME=ciphergate-deploy.zip"
echo [1/7] Build backend JAR...
call gradlew.bat clean bootJar --no-daemon
if errorlevel 1 goto :fail
echo [2/7] Build crypto plugins...
call gradlew.bat -p plugins\rsa-crypto-plugin clean jar --no-daemon
if errorlevel 1 goto :fail
echo [3/7] Build frontend dist...
pushd frontend
if not exist "node_modules" (
call npm install --include=dev --no-audit --no-fund
if errorlevel 1 (
popd
goto :fail
)
)
if not exist "node_modules\.bin\tsc.cmd" (
echo [INFO] typescript not found, reinstalling dev dependencies...
call npm install --include=dev --no-audit --no-fund
if errorlevel 1 (
popd
goto :fail
)
)
call npm run build
if errorlevel 1 (
popd
goto :fail
)
popd
echo [4/7] Build docs...
pushd docs
if not exist "node_modules" (
call npm install --no-audit --no-fund
if errorlevel 1 (
popd
goto :fail
)
)
call npm run build
if errorlevel 1 (
popd
goto :fail
)
popd
echo [5/7] Prepare bundle...
if exist "%BUNDLE_DIR%" rmdir /s /q "%BUNDLE_DIR%"
mkdir "%BUNDLE_DIR%\app"
mkdir "%BUNDLE_DIR%\plugins"
mkdir "%BUNDLE_DIR%\frontend"
mkdir "%BUNDLE_DIR%\docs"
set "JAR_FILE="
for /f "delims=" %%f in ('dir /b /o:-d "build\libs\*.jar" ^| findstr /v /i "\-plain\.jar$"') do (
if not defined JAR_FILE set "JAR_FILE=build\libs\%%f"
)
if not defined JAR_FILE (
echo [ERROR] No runnable bootJar found in build\libs
goto :fail
)
echo [INFO] Using jar: %JAR_FILE%
copy /y "%JAR_FILE%" "%BUNDLE_DIR%\app\app.jar" >nul
if errorlevel 1 goto :fail
xcopy /e /i /y "frontend\dist" "%BUNDLE_DIR%\frontend\dist" >nul
if errorlevel 1 goto :fail
copy /y "frontend\nginx.conf" "%BUNDLE_DIR%\frontend\nginx.conf" >nul
if errorlevel 1 goto :fail
copy /y "docker-compose.server.yml" "%BUNDLE_DIR%\docker-compose.server.yml" >nul
if errorlevel 1 goto :fail
:: Copy docs
if exist "docs\.vitepress\dist" (
xcopy /e /i /y "docs\.vitepress\dist\*" "%BUNDLE_DIR%\docs\" >nul
echo [INFO] Docs bundled.
) else (
echo [WARN] docs\.vitepress\dist not found, skipping docs.
)
:: Copy plugin JARs (use powershell for reliability on Windows CI)
powershell -NoProfile -Command ^
"$src = 'plugins';" ^
"$dst = '%BUNDLE_DIR%\plugins';" ^
"$jars = Get-ChildItem -Path $src -Recurse -Filter '*.jar' | Where-Object { $_.FullName -match '\\build\\libs\\' };" ^
"if ($jars.Count -eq 0) { Write-Host '[WARN] No plugin JARs found' } else { foreach ($j in $jars) { Copy-Item $j.FullName -Destination $dst -Force; Write-Host ('[INFO] Plugin: ' + $j.Name) }; Write-Host ('[INFO] ' + $jars.Count + ' plugin(s) bundled.') }"
if not exist ".env.server" (
echo [ERROR] Missing .env.server. Copy from .env.server.example and edit it.
goto :fail
)
copy /y ".env.server" "%BUNDLE_DIR%\.env" >nul
if errorlevel 1 goto :fail
echo [INFO] Randomizing host ports in bundle .env ...
powershell -NoProfile -Command ^
"$dst='%BUNDLE_DIR%\.env';" ^
"$lines=Get-Content -LiteralPath $dst -Encoding UTF8;" ^
"$used=@{}; function New-Port([int]$min,[int]$max){ do{ $p=Get-Random -Minimum $min -Maximum ($max+1) } while($used.ContainsKey($p)); $used[$p]=$true; return $p };" ^
"$ports=@{" ^
" 'MYSQL_PORT'=[string](New-Port 20000 49999);" ^
" 'REDIS_PORT_HOST'=[string](New-Port 20000 49999);" ^
" 'MINIO_API_PORT'=[string](New-Port 20000 49999);" ^
" 'MINIO_CONSOLE_PORT'=[string](New-Port 20000 49999);" ^
" 'BACKEND_PORT'=[string](New-Port 20000 49999);" ^
" 'FRONTEND_PORT'=[string](New-Port 20000 49999);" ^
" 'RABBITMQ_PORT'=[string](New-Port 20000 49999);" ^
" 'RABBITMQ_MGMT_PORT'=[string](New-Port 20000 49999)" ^
"};" ^
"$out = foreach($line in $lines){" ^
" if($line -match '^\s*([A-Z0-9_]+)\s*='){" ^
" $k=$Matches[1]; if($ports.ContainsKey($k)){ $k + '=' + $ports[$k] } else { $line }" ^
" } else { $line }" ^
"};" ^
"Set-Content -LiteralPath $dst -Value $out -Encoding UTF8"
if errorlevel 1 goto :fail
echo [6/7] Create zip package...
if exist "%ZIP_NAME%" del /f /q "%ZIP_NAME%"
powershell -NoProfile -Command "Compress-Archive -Path '%BUNDLE_DIR%\*' -DestinationPath '%ZIP_NAME%' -Force"
if errorlevel 1 goto :fail
echo [7/7] Done.
echo Bundle folder: %BUNDLE_DIR%
echo Zip package : %ZIP_NAME%
echo Upload one of them to server, then run:
echo docker compose -f docker-compose.server.yml up -d
goto :eof
:fail
echo Build failed.
exit /b 1