mirror of
https://github.com/J3vb/OwnCord.git
synced 2026-09-03 03:50:00 +03:00
PR#88 Added server linux support and optimized ci/release workflow for multiplatform server build
This commit is contained in:
@@ -16,6 +16,7 @@ import (
|
||||
|
||||
"github.com/owncord/server/auth"
|
||||
"github.com/owncord/server/db"
|
||||
"github.com/owncord/server/updater"
|
||||
)
|
||||
|
||||
// openWhiteboxTestDB opens an in-memory SQLite database for whitebox tests.
|
||||
@@ -419,7 +420,7 @@ func TestSpawnDetached_ValidExecutable(t *testing.T) {
|
||||
t.Fatalf("abs path of test binary: %v", err)
|
||||
}
|
||||
|
||||
err = spawnDetached(selfExe, []string{"-test.run=^$"})
|
||||
err = updater.SpawnDetached(selfExe, []string{"-test.run=^$"})
|
||||
if err != nil {
|
||||
t.Errorf("spawnDetached returned error: %v", err)
|
||||
}
|
||||
@@ -428,7 +429,7 @@ func TestSpawnDetached_ValidExecutable(t *testing.T) {
|
||||
// TestSpawnDetached_InvalidExecutable verifies that spawnDetached returns an
|
||||
// error when the executable path does not exist.
|
||||
func TestSpawnDetached_InvalidExecutable(t *testing.T) {
|
||||
err := spawnDetached("/nonexistent/path/to/binary", nil)
|
||||
err := updater.SpawnDetached("/nonexistent/path/to/binary", nil)
|
||||
if err == nil {
|
||||
t.Error("expected error when executable does not exist, got nil")
|
||||
}
|
||||
@@ -448,7 +449,7 @@ func TestSpawnDetached_SetsWindowsFlags(t *testing.T) {
|
||||
}
|
||||
|
||||
// Just verify it doesn't panic when setting the Windows creation flag.
|
||||
err = spawnDetached(selfExe, []string{"-test.run=^$"})
|
||||
err = updater.SpawnDetached(selfExe, []string{"-test.run=^$"})
|
||||
if err != nil {
|
||||
t.Errorf("spawnDetached on Windows returned error: %v", err)
|
||||
}
|
||||
|
||||
@@ -5,9 +5,7 @@ import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
@@ -33,6 +31,7 @@ func handleCheckUpdate(u *updater.Updater) http.HandlerFunc {
|
||||
|
||||
// handleApplyUpdate downloads and applies a server update.
|
||||
func handleApplyUpdate(u *updater.Updater, hub HubBroadcaster, _ string) http.Handler {
|
||||
//TODO: maybe disable this endpoint in future docker build type?
|
||||
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
if u == nil {
|
||||
writeErr(w, http.StatusServiceUnavailable, "UPDATE_UNAVAILABLE", "update checking is not configured")
|
||||
@@ -114,7 +113,7 @@ func handleApplyUpdate(u *updater.Updater, hub HubBroadcaster, _ string) http.Ha
|
||||
}
|
||||
|
||||
// Spawn new process.
|
||||
if err := spawnDetached(exePath, os.Args[1:]); err != nil {
|
||||
if err := updater.SpawnDetached(exePath, os.Args[1:]); err != nil {
|
||||
slog.Error("update: spawn new process failed", "error", err)
|
||||
return
|
||||
}
|
||||
@@ -133,18 +132,3 @@ func handleApplyUpdate(u *updater.Updater, hub HubBroadcaster, _ string) http.Ha
|
||||
}()
|
||||
})
|
||||
}
|
||||
|
||||
// spawnDetached starts a new process that is not attached to the current one.
|
||||
func spawnDetached(exePath string, args []string) error {
|
||||
cmd := exec.Command(exePath, args...) //nolint:gosec // G204: command path from trusted server config
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
if runtime.GOOS == "windows" {
|
||||
cmd.SysProcAttr = &syscall.SysProcAttr{
|
||||
CreationFlags: 0x00000008, // DETACHED_PROCESS
|
||||
}
|
||||
}
|
||||
|
||||
return cmd.Start()
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ func TestAdminAPI_CheckUpdate_OK(t *testing.T) {
|
||||
"html_url": "https://github.com/J3vb/OwnCord/releases/tag/v2.0.0",
|
||||
"assets": []map[string]any{
|
||||
{"name": "chatserver.exe", "browser_download_url": "https://github.com/J3vb/OwnCord/releases/download/v2.0.0/chatserver.exe"},
|
||||
{"name": "chatserver-linux-amd64.tar.gz", "browser_download_url": "https://github.com/J3vb/OwnCord/releases/download/v2.0.0/chatserver-linux-amd64.tar.gz"},
|
||||
{"name": "checksums.sha256", "browser_download_url": "https://github.com/J3vb/OwnCord/releases/download/v2.0.0/checksums.sha256"},
|
||||
},
|
||||
})
|
||||
@@ -264,6 +265,10 @@ func TestAdminAPI_ApplyUpdate_DownloadFails(t *testing.T) {
|
||||
"name": "chatserver.exe",
|
||||
"browser_download_url": "https://github.com/J3vb/OwnCord/releases/download/v2.0.0/chatserver.exe",
|
||||
},
|
||||
{
|
||||
"name": "chatserver-linux-amd64.tar.gz",
|
||||
"browser_download_url": "https://github.com/J3vb/OwnCord/releases/download/v2.0.0/chatserver-linux-amd64.tar.gz",
|
||||
},
|
||||
{
|
||||
"name": "checksums.sha256",
|
||||
"browser_download_url": "https://github.com/J3vb/OwnCord/releases/download/v2.0.0/checksums.sha256",
|
||||
|
||||
Reference in New Issue
Block a user