feat: add Wine Z: path prefix for Windows platform on Linux host
CI / build (push) Successful in 1m44s

- Add winePath helper that prepends Z: when platform is windows on Linux
- Thread platform through buildModPath, buildAutoArgs, and Start()
- Apply Z: prefix to -config=, -mod=, -profiles=, and %command% binary paths
- Add tests for winePath, buildAutoArgs, and buildModPath with platform param
- Fix formatting across services package with gofmt
- Include all prior bug fixes from this branch
This commit is contained in:
MrFastwind
2026-07-24 03:57:51 +02:00
parent 41c1390972
commit 6f3175ac9a
18 changed files with 219 additions and 75 deletions
+3 -1
View File
@@ -16,6 +16,8 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: "22"
- run: cd frontend && npm ci && npm run build
- run: mkdir -p backend/embed/dist && cp -r frontend/dist/. backend/embed/dist/
- run: cd backend && go build ./...
- run: cd backend && go test ./...
- run: cd frontend && npm ci && npm run build && npm test
- run: cd frontend && npm test
+3 -4
View File
@@ -69,8 +69,7 @@ arma3-web-server/
│ │ └── components/
│ │ ├── ConfigEditor.tsx # Monaco editor wrapper
│ │ ├── LiveTerminal.tsx # xterm.js + auto-reconnect WebSocket
│ │ ── Layout.tsx # Sidebar navigation shell
│ │ └── ui/ # Empty
│ │ ── Layout.tsx # Sidebar navigation shell
│ ├── package.json
│ ├── vite.config.ts # Proxy /api + /ws to :8080
│ └── tsconfig*.json
@@ -116,8 +115,8 @@ arma3-web-server/
| `oxlint` | linter | ^1.71.0 | Linting |
| `vitest` | test runner | ^4.1.10 | Frontend unit/integration tests |
| `@testing-library/react` | test utility | ^16.3.0 | React component testing |
| `@testing-library/jest-dom` | test matcher | ^6.6.3 | DOM assertion matchers |
| `jsdom` | test env | ^26.1.0 | Browser environment for tests |
| `@testing-library/jest-dom` | test matcher | ^7.0.0 | DOM assertion matchers |
| `jsdom` | test env | ^29.1.1 | Browser environment for tests |
## Architecture
-2
View File
@@ -27,7 +27,6 @@ RUN apt-get update && \
rm -rf /var/lib/apt/lists/*
COPY --from=backend /server /usr/local/bin/arma3-web-server
COPY --from=frontend /src/dist /usr/share/arma3-web-server/frontend
EXPOSE 8080
VOLUME ["/data", "/servers"]
@@ -38,7 +37,6 @@ ENV MODS_DIR=/servers/mods
ENV CFG_DIR=/servers/cfg
ENV PROFILES_DIR=/servers/profiles
ENV LISTEN=:8080
ENV FRONTEND_DIR=/usr/share/arma3-web-server/frontend
ENV GIN_MODE=release
ENTRYPOINT ["arma3-web-server"]
-2
View File
@@ -14,7 +14,6 @@ RUN apt-get update && \
rm -rf /var/lib/apt/lists/*
COPY arma3-web-server /usr/local/bin/arma3-web-server
COPY frontend/dist /usr/share/arma3-web-server/frontend
EXPOSE 8080
VOLUME ["/data", "/servers"]
@@ -25,7 +24,6 @@ ENV MODS_DIR=/servers/mods
ENV CFG_DIR=/servers/cfg
ENV PROFILES_DIR=/servers/profiles
ENV LISTEN=:8080
ENV FRONTEND_DIR=/usr/share/arma3-web-server/frontend
ENV GIN_MODE=release
ENTRYPOINT ["arma3-web-server"]
+5 -5
View File
@@ -1,11 +1,11 @@
.PHONY: backend frontend build run clean dev test test-backend test-frontend
# Default paths for dev — override via env (absolute to avoid CWD mismatches)
SERVERFILE_DIR ?= $(abspath ../dev-deploy/serverfiles)
MODS_DIR ?= $(abspath ../dev-deploy/serverfiles/mods)
CFG_DIR ?= $(abspath ../dev-deploy/serverfiles/cfg)
PROFILES_DIR ?= $(abspath ../dev-deploy/serverfiles/profiles)
DATA_DIR ?= $(abspath ../dev-deploy/data)
SERVERFILE_DIR ?= $(abspath dev-deploy/serverfiles)
MODS_DIR ?= $(abspath dev-deploy/serverfiles/mods)
CFG_DIR ?= $(abspath dev-deploy/serverfiles/cfg)
PROFILES_DIR ?= $(abspath dev-deploy/serverfiles/profiles)
DATA_DIR ?= $(abspath dev-deploy/data)
# Server/steamcmd overrides — set to use stubs in dev
SERVER_BINARY ?= arma3server_x64
+1 -2
View File
@@ -79,8 +79,7 @@ arma3-web-server/
│ │ └── components/
│ │ ├── ConfigEditor.tsx # Monaco editor wrapper
│ │ ├── LiveTerminal.tsx # xterm.js + auto-reconnect WebSocket
│ │ ── Layout.tsx # Sidebar nav shell
│ │ └── ui/ # (empty — reserved for future shared UI primitives)
│ │ ── Layout.tsx # Sidebar nav shell
│ ├── package.json
│ └── vite.config.ts # Proxy /api + /ws to :8080
├── data/ # Runtime data (mounted volume in Docker)
+3 -1
View File
@@ -57,9 +57,11 @@ func main() {
r := gin.Default()
frontendServed := false
subFS, subErr := fs.Sub(embed.Frontend, "dist")
if subErr == nil {
if _, err := subFS.Open("index.html"); err == nil {
frontendServed = true
r.NoRoute(func(c *gin.Context) {
path := strings.TrimPrefix(c.Request.URL.Path, "/")
if path == "" {
@@ -81,7 +83,7 @@ func main() {
}
}
handler := api.New(settings, configMgr, modlistMgr, process, steamcmd, scheduler, streamer, dataDir, serverfileDir, modsDir, cfgDir, profilesDir)
handler := api.New(settings, configMgr, modlistMgr, process, steamcmd, scheduler, streamer, dataDir, serverfileDir, modsDir, cfgDir, profilesDir, frontendServed)
handler.SetupRoutes(r)
// Startup auto-tasks
+1 -3
View File
@@ -76,7 +76,7 @@ func (h *Handler) Health(c *gin.Context) {
Running: h.steamcmd.IsRunning(),
},
Frontend: FrontendHealth{
Served: true,
Served: h.frontendServed,
},
}
@@ -140,8 +140,6 @@ func findServerBinary(serverfileDir string) (string, bool) {
candidates := []string{"arma3server_x64"}
if runtime.GOOS == "windows" {
candidates = append(candidates, "arma3server_x64.exe")
} else {
candidates = append(candidates, "arma3server_x64.exe")
}
for _, name := range candidates {
p := filepath.Join(serverfileDir, name)
+3 -1
View File
@@ -117,7 +117,9 @@ func (h *Handler) StreamRPTLogs(c *gin.Context) {
if currentPath == "" {
continue
}
conn.WriteMessage(websocket.TextMessage, []byte("--- tailing: "+filepath.Base(currentPath)+" ---"))
if err := conn.WriteMessage(websocket.TextMessage, []byte("--- tailing: "+filepath.Base(currentPath)+" ---")); err != nil {
return
}
}
if currentPath == "" {
continue
+3
View File
@@ -19,6 +19,7 @@ type Handler struct {
modsDir string
cfgDir string
profilesDir string
frontendServed bool
}
func New(
@@ -30,6 +31,7 @@ func New(
scheduler *services.Scheduler,
streamer *services.LogStreamer,
dataDir, serverfileDir, modsDir, cfgDir, profilesDir string,
frontendServed bool,
) *Handler {
return &Handler{
settings: settings,
@@ -44,6 +46,7 @@ func New(
modsDir: modsDir,
cfgDir: cfgDir,
profilesDir: profilesDir,
frontendServed: frontendServed,
}
}
+1 -1
View File
@@ -63,7 +63,7 @@ func (s *Scheduler) runScheduledUpdate() {
return
}
if sett.SteamUser != "" && sett.SteamUser != "anonymous" {
if sett.SteamUser != "" {
log.Print("scheduler: running gameserver update")
if err := s.steamcmd.UpdateGame(sett.SteamBranch, sett.SteamUser); err != nil {
log.Printf("scheduler: game update failed: %v", err)
+14 -6
View File
@@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"sync"
"sync/atomic"
@@ -14,6 +15,13 @@ import (
"arma3-web-server/internal/models"
)
func winePath(path, platform string) string {
if platform == "windows" && runtime.GOOS != "windows" {
return "Z:" + path
}
return path
}
type procState int32
const (
@@ -101,7 +109,7 @@ func (pm *ProcessManager) Start() error {
ctx, cancel := context.WithCancel(context.Background())
var cmd *exec.Cmd
if strings.Contains(s.ServerParameters, "%command%") {
full := strings.ReplaceAll(s.ServerParameters, "%command%", binPath)
full := strings.ReplaceAll(s.ServerParameters, "%command%", winePath(binPath, s.Platform))
parts := splitArgs(full)
if len(parts) == 0 {
cancel()
@@ -205,18 +213,18 @@ func (pm *ProcessManager) buildAutoArgs(s *models.ServerSettings) []string {
if s.ActiveConfig != "" {
cfgPath := filepath.Join(pm.cfgDir, s.ActiveConfig+".cfg")
args = append(args, "-config="+cfgPath)
args = append(args, "-config="+winePath(cfgPath, s.Platform))
}
if s.ActiveModlist != "" {
modPath := pm.buildModPath(s.ActiveModlist)
modPath := pm.buildModPath(s.ActiveModlist, s.Platform)
if modPath != "" {
args = append(args, modPath)
}
}
if pm.profilesDir != "" && !hasArgPrefix(args, "-profiles=") {
args = append(args, "-profiles="+pm.profilesDir)
args = append(args, "-profiles="+winePath(pm.profilesDir, s.Platform))
}
if s.IPPort != "" && !hasArgPrefix(args, "-port=") {
@@ -245,7 +253,7 @@ func hasArgPrefix(args []string, prefix string) bool {
const workshopAppID = "107410"
func (pm *ProcessManager) buildModPath(modlistID string) string {
func (pm *ProcessManager) buildModPath(modlistID string, platform string) string {
ml, err := pm.modlists.Get(modlistID)
if err != nil {
return ""
@@ -256,7 +264,7 @@ func (pm *ProcessManager) buildModPath(modlistID string) string {
if !mod.Enabled {
continue
}
parts = append(parts, pm.resolveModPath(mod))
parts = append(parts, winePath(pm.resolveModPath(mod), platform))
}
if len(parts) == 0 {
@@ -294,7 +294,7 @@ func TestBuildModPath_MultipleMods(t *testing.T) {
{Name: "DisabledMod", Enabled: false},
})
got := pm.buildModPath(ml.ID)
got := pm.buildModPath(ml.ID, "")
if !strings.HasPrefix(got, "-mod=") {
t.Errorf("expected -mod= prefix, got %q", got)
}
@@ -321,7 +321,7 @@ func TestBuildModPath_EmptyModlist(t *testing.T) {
pm := NewProcessManager(dir, modsDir, filepath.Join(dir, "cfg"), filepath.Join(dir, "profiles"), sm, mm, cm, streamer)
got := pm.buildModPath("nonexistent-id")
got := pm.buildModPath("nonexistent-id", "")
if got != "" {
t.Errorf("buildModPath(nonexistent) = %q, want empty", got)
}
@@ -396,6 +396,142 @@ func TestWriteUserconfigFiles_EmptyContent(t *testing.T) {
}
}
func TestWinePath(t *testing.T) {
tests := []struct {
name string
path string
platform string
want string
}{
{"linux platform returns as-is", "/server/cfg/test.cfg", "linux", "/server/cfg/test.cfg"},
{"empty platform returns as-is", "/server/cfg/test.cfg", "", "/server/cfg/test.cfg"},
{"windows platform on linux adds prefix", "/server/cfg/test.cfg", "windows", "Z:/server/cfg/test.cfg"},
{"empty path linux", "", "linux", ""},
{"empty path windows", "", "windows", "Z:"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := winePath(tt.path, tt.platform)
if got != tt.want {
t.Errorf("winePath(%q, %q) = %q, want %q", tt.path, tt.platform, got, tt.want)
}
})
}
}
func TestBuildAutoArgs_WindowsPlatform(t *testing.T) {
dir := t.TempDir()
cfgDir := filepath.Join(dir, "cfg")
profilesDir := filepath.Join(dir, "profiles")
modsDir := filepath.Join(dir, "mods")
sm := NewSettingsManager(dir)
mm := NewModlistManager(filepath.Join(dir, "modlists"))
cm := NewConfigManager(cfgDir)
streamer := NewLogStreamer()
pm := NewProcessManager(dir, modsDir, cfgDir, profilesDir, sm, mm, cm, streamer)
s := &models.ServerSettings{
Platform: "windows",
ActiveConfig: "server_config",
IPPort: "0.0.0.0:2302",
}
args := pm.buildAutoArgs(s)
foundConfig := false
foundProfiles := false
for _, a := range args {
if strings.HasPrefix(a, "-config=Z:") && strings.HasSuffix(a, "server_config.cfg") {
foundConfig = true
}
if strings.HasPrefix(a, "-profiles=Z:") {
foundProfiles = true
}
}
if !foundConfig {
t.Errorf("expected -config=Z:...server_config.cfg in args, got %v", args)
}
if !foundProfiles {
t.Errorf("expected -profiles=Z:... in args, got %v", args)
}
}
func TestBuildAutoArgs_LinuxPlatform(t *testing.T) {
dir := t.TempDir()
cfgDir := filepath.Join(dir, "cfg")
profilesDir := filepath.Join(dir, "profiles")
modsDir := filepath.Join(dir, "mods")
sm := NewSettingsManager(dir)
mm := NewModlistManager(filepath.Join(dir, "modlists"))
cm := NewConfigManager(cfgDir)
streamer := NewLogStreamer()
pm := NewProcessManager(dir, modsDir, cfgDir, profilesDir, sm, mm, cm, streamer)
s := &models.ServerSettings{
Platform: "linux",
ActiveConfig: "server_config",
IPPort: "0.0.0.0:2302",
}
args := pm.buildAutoArgs(s)
for _, a := range args {
if strings.HasPrefix(a, "-config=Z:") {
t.Errorf("unexpected Z: prefix in args: %v", a)
}
}
}
func TestBuildModPath_WindowsPlatform(t *testing.T) {
dir := t.TempDir()
modsDir := filepath.Join(dir, "mods")
os.MkdirAll(filepath.Join(modsDir, "@CBA_A3"), 0755)
sm := NewSettingsManager(dir)
mm := NewModlistManager(filepath.Join(dir, "modlists"))
cm := NewConfigManager(filepath.Join(dir, "cfg"))
streamer := NewLogStreamer()
pm := NewProcessManager(dir, modsDir, filepath.Join(dir, "cfg"), filepath.Join(dir, "profiles"), sm, mm, cm, streamer)
ml, _ := mm.Create("Test List")
mm.Update(ml.ID, "Test List", []models.ModEntry{
{Name: "CBA_A3", Enabled: true},
})
got := pm.buildModPath(ml.ID, "windows")
if !strings.HasPrefix(got, "-mod=Z:") {
t.Errorf("expected -mod=Z: prefix, got %q", got)
}
}
func TestBuildModPath_LinuxPlatform(t *testing.T) {
dir := t.TempDir()
modsDir := filepath.Join(dir, "mods")
os.MkdirAll(filepath.Join(modsDir, "@CBA_A3"), 0755)
sm := NewSettingsManager(dir)
mm := NewModlistManager(filepath.Join(dir, "modlists"))
cm := NewConfigManager(filepath.Join(dir, "cfg"))
streamer := NewLogStreamer()
pm := NewProcessManager(dir, modsDir, filepath.Join(dir, "cfg"), filepath.Join(dir, "profiles"), sm, mm, cm, streamer)
ml, _ := mm.Create("Test List")
mm.Update(ml.ID, "Test List", []models.ModEntry{
{Name: "CBA_A3", Enabled: true},
})
got := pm.buildModPath(ml.ID, "linux")
if strings.Contains(got, "Z:") {
t.Errorf("unexpected Z: prefix in args: %q", got)
}
}
func TestStartAndStopWithStub(t *testing.T) {
dir := t.TempDir()
serverfileDir := filepath.Join(dir, "server")
-1
View File
@@ -14,6 +14,5 @@ services:
- CFG_DIR=/servers/cfg
- PROFILES_DIR=/servers/profiles
- LISTEN=:8080
- FRONTEND_DIR=/usr/share/arma3-web-server/frontend
- GIN_MODE=release
restart: unless-stopped