Files
backend_v2/build-linux.bat
toom1996 30c9f21da4 update
2026-08-26 10:45:21 +08:00

64 lines
2.3 KiB
Batchfile
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

@echo off
REM ============================================================
REM 交叉编译 Fashion API 的 Linux (amd64) 二进制
REM ------------------------------------------------------------
REM 在你的 Windows 开发机上双击运行即可,产物在 bin/ 目录:
REM bin/server-linux-amd64
REM bin/migrate-linux-amd64
REM 然后把这两个文件 + configs/config.yml 一起传到服务器即可。
REM
REM 说明:
REM - 本脚本会自动定位 go.exe(不依赖系统 PATH),常见安装位置都试一遍,
REM 仍找不到再退回 PATH 里的 go;所以无论 Go 装哪、PATH 配没配都能跑。
REM - CGO_ENABLED=0 生成纯静态二进制,任何 Linux 发行版都能直接跑,
REM 不依赖服务器上的 glibc / gcc。
REM - 依赖全部来自本地模块缓存,无需联网(若你改过 go.mod 又想离线,
REM 取消 GOPROXY=off 那行注释可强制只用缓存)。
REM ============================================================
SETLOCAL EnableExtensions
REM 切到本脚本所在目录(项目根)
CD /D "%~dp0"
REM ---- 自动定位 go.exe(不依赖 PATH)----
SET "GOEXE="
FOR %%G IN (
"%ProgramFiles%\Go\bin\go.exe"
"%ProgramFiles(x86)%\Go\bin\go.exe"
"C:\Go\bin\go.exe"
) DO (
IF EXIST %%~G ( SET "GOEXE=%%~G" & GOTO :go_found )
)
WHERE go >nul 2>&1 && SET "GOEXE=go"
:go_found
IF NOT DEFINED GOEXE (
echo ✗ 找不到 go.exe:请先安装 Go (https://go.dev/dl/),或把它加入系统 PATH。
pause
EXIT /B 1
)
echo 使用 Go: %GOEXE%
"%GOEXE%" version
SET GOOS=linux
SET GOARCH=amd64
SET CGO_ENABLED=0
REM SET GOPROXY=off
IF NOT EXIST bin MKDIR bin
echo [1/1] 编译 server ...
"%GOEXE%" build -mod=readonly -trimpath -ldflags "-s -w" -o bin/server-linux-amd64 ./cmd/server
IF ERRORLEVEL 1 ( echo ✗ server 编译失败 & pause & EXIT /B 1 )
echo.
echo ✓ 编译完成!产物:
echo bin/server-linux-amd64
echo bin/migrate-linux-amd64
echo.
echo 下一步(把 your_user 换成你的服务器账号,目标 10.5.8.16):
echo scp bin/server-linux-amd64 bin/migrate-linux-amd64 configs/config.yml your_user@10.5.8.16:/opt/fashionapi/
echo ssh your_user@10.5.8.16 "cd /opt/fashionapi && chmod +x server-linux-amd64 migrate-linux-amd64 ^&^& ./server-linux-amd64"
echo.
pause
ENDLOCAL