-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.bat
More file actions
124 lines (111 loc) · 4.17 KB
/
Copy pathdeploy.bat
File metadata and controls
124 lines (111 loc) · 4.17 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
@echo off
setlocal enabledelayedexpansion
REM Deploy Foundation to a remote Debian server
REM Usage: deploy.bat <user@host> [options]
REM
REM Options:
REM --domain <domain> Domain name for Let's Encrypt SSL
REM --email <email> Email for Let's Encrypt notifications
REM --port <port> App listen port (default 5110)
REM --key <ssh-key> SSH key file
REM --skip-build Reuse the existing tarball instead of publishing fresh
REM --rebuild-db Delete and recreate the database (CAUTION: destroys data!)
set "SCRIPT_DIR=%~dp0"
set "TARBALL=%SCRIPT_DIR%foundation-deploy.tar.gz"
set "REMOTE="
set "DOMAIN="
set "EMAIL="
set "APP_PORT=5110"
set "SSH_KEY="
set "REBUILD_DB=0"
set "SKIP_BUILD=0"
REM Parse arguments
:parse_args
if "%~1"=="" goto :done_args
if "%~1"=="--domain" ( set "DOMAIN=%~2" & shift & shift & goto :parse_args )
if "%~1"=="--email" ( set "EMAIL=%~2" & shift & shift & goto :parse_args )
if "%~1"=="--port" ( set "APP_PORT=%~2" & shift & shift & goto :parse_args )
if "%~1"=="--key" ( set "SSH_KEY=%~2" & shift & shift & goto :parse_args )
if "%~1"=="--rebuild-db" ( set "REBUILD_DB=1" & shift & goto :parse_args )
if "%~1"=="--skip-build" ( set "SKIP_BUILD=1" & shift & goto :parse_args )
set "REMOTE=%~1"
shift
goto :parse_args
:done_args
REM Strip protocol prefix from domain if present
if defined DOMAIN (
set "DOMAIN=%DOMAIN:https://=%"
set "DOMAIN=%DOMAIN:http://=%"
REM Remove trailing slash if any
if "%DOMAIN:~-1%"=="/" set "DOMAIN=%DOMAIN:~0,-1%"
)
if "%REMOTE%"=="" (
echo Usage: deploy.bat ^<user@host^> [options]
echo.
echo Options:
echo --domain ^<domain^> Domain for Let's Encrypt SSL
echo --email ^<email^> Email for Let's Encrypt
echo --port ^<port^> App port ^(default 5110^)
echo --key ^<ssh-key^> SSH key file
echo --rebuild-db Delete and recreate the database
echo.
echo Examples:
echo deploy.bat admin@192.168.1.100
echo deploy.bat admin@149.28.xxx.xxx --domain scale.example.com --email admin@example.com
exit /b 1
)
REM Build SSH options
set "SSH_OPTS=-o StrictHostKeyChecking=no"
set "SCP_OPTS=-o StrictHostKeyChecking=no"
if not "%SSH_KEY%"=="" (
set "SSH_OPTS=!SSH_OPTS! -i %SSH_KEY%"
set "SCP_OPTS=!SCP_OPTS! -i %SSH_KEY%"
)
REM Verify DNS resolves before deploying (if domain specified)
if not "%DOMAIN%"=="" (
echo ==^> Verifying DNS for %DOMAIN%...
nslookup %DOMAIN% >nul 2>&1
if errorlevel 1 (
echo ERROR: DNS lookup failed for %DOMAIN%
echo Create an A record pointing %DOMAIN% to your server IP.
echo Then wait for propagation and try again.
exit /b 1
)
echo DNS OK: %DOMAIN% resolves.
)
REM Always publish a fresh build — a cached tarball silently deploys stale
REM code. Pass --skip-build to reuse the existing tarball.
if "%SKIP_BUILD%"=="1" if exist "%TARBALL%" (
echo ==^> Reusing existing tarball ^(--skip-build^).
goto :upload
)
echo ==^> Publishing fresh build...
call "%SCRIPT_DIR%publish.bat"
if errorlevel 1 exit /b 1
:upload
echo ==^> Uploading to %REMOTE%...
scp %SCP_OPTS% "%TARBALL%" "%REMOTE%:/tmp/foundation-deploy.tar.gz"
if errorlevel 1 (
echo ERROR: Upload failed
exit /b 1
)
REM Build install command - sed fixes Windows CRLF line endings before running
set "INSTALL_CMD=cd /tmp && mkdir -p /tmp/foundation-install && tar -xzf /tmp/foundation-deploy.tar.gz -C /tmp/foundation-install && cd /tmp/foundation-install && sed -i 's/\r$//' install.sh && sudo DOMAIN='%DOMAIN%' EMAIL='%EMAIL%' PORT='%APP_PORT%' REBUILD_DB='%REBUILD_DB%' bash install.sh && rm -rf /tmp/foundation-install /tmp/foundation-deploy.tar.gz"
echo ==^> Installing on remote server...
ssh %SSH_OPTS% "%REMOTE%" "%INSTALL_CMD%"
if errorlevel 1 (
echo ERROR: Remote install failed
exit /b 1
)
echo.
echo ==========================================
echo Deploy complete!
echo ==========================================
echo Server: %REMOTE%
if not "%DOMAIN%"=="" (
echo URL: https://%DOMAIN%
) else (
echo URL: https://%REMOTE%
)
echo Check: ssh %REMOTE% "systemctl status foundation"
echo ==========================================