Quellcode durchsuchen

Fix docker package build failure on FreeBSD and other unlisted platforms (#267)

The docker package split its PTY console and host-stats helpers into
build-tagged files that only covered linux/darwin/windows. FreeBSD (built
by the Jenkins release pipeline for amd64 and i386) matched none of them,
so startDockerExecPTY, hostStorageUsage and hostLoadAvg were undefined and
the cross-platform release build failed.

- console_unix.go now builds for freebsd too (creack/pty supports it).
- console_windows.go becomes console_other.go, a catch-all (!linux &&
  !darwin && !freebsd) stub covering windows and any other GOOS.
- host_darwin.go becomes host_bsd.go (darwin || freebsd); the Statfs-based
  storage helper works on both.
- Add host_other.go, a catch-all fallback so the package builds on any
  remaining GOOS.

Also expand the CI cross-compile smoke test to cover the full release
matrix (including freebsd/amd64 and freebsd/386) so a platform-specific
break is caught in CI instead of only in the release build.


Claude-Session: https://claude.ai/code/session_01L4oR1xiTxpcfwYjRgi4RGh

Co-authored-by: Claude <noreply@anthropic.com>
Alan Yeung vor 1 Monat
Ursprung
Commit
982fba9aac

+ 28 - 5
.github/workflows/ci.yml

@@ -81,12 +81,35 @@ jobs:
         run: go build ./...
 
       - name: Cross-compile smoke test (portability, rule 5)
-        # Mirrors the release targets in the Makefile: the shipped binary must
-        # build for other OSes from a single, dependency-free codebase.
+        # Mirrors every release target built by the Jenkins pipeline / Makefile:
+        # the shipped binary must build for all supported OS/arch pairs from a
+        # single, dependency-free codebase. Kept in lock-step with those targets
+        # so a platform-specific break (e.g. a missing build-tagged file for
+        # freebsd) fails here in CI instead of only in the release build.
         run: |
-          GOOS=windows GOARCH=amd64 go build -o /dev/null .
-          GOOS=darwin  GOARCH=arm64 go build -o /dev/null .
-          GOOS=linux   GOARCH=arm   GOARM=6 go build -o /dev/null .
+          set -e
+          # GOOS GOARCH [extra env...]
+          targets="
+          darwin/amd64
+          darwin/arm64
+          freebsd/amd64
+          freebsd/386
+          linux/amd64
+          linux/386
+          linux/arm/GOARM=6
+          linux/arm/GOARM=7
+          linux/arm64
+          linux/riscv64
+          linux/mipsle/GOMIPS=softfloat
+          windows/amd64
+          windows/386
+          "
+          for t in $targets; do
+            os="${t%%/*}"; rest="${t#*/}"; arch="${rest%%/*}"; extra=""
+            case "$rest" in */*) extra="${rest#*/}";; esac
+            echo "==> building $os/$arch $extra"
+            env GOOS="$os" GOARCH="$arch" $extra go build -o /dev/null .
+          done
 
       - name: go test
         run: go test -count=1 ./...

+ 2 - 2
src/mod/docker/console.go

@@ -7,8 +7,8 @@ package docker
 	to xterm.js over a websocket. The PTY allocation is platform-specific and
 	lives in build-tagged files:
 
-	    console_unix.go    (linux || darwin) — real PTY via github.com/creack/pty
-	    console_windows.go (windows)         — returns "not supported"
+	    console_unix.go   (linux || darwin || freebsd) — real PTY via github.com/creack/pty
+	    console_other.go  (all other GOOS, incl. windows) — returns "not supported"
 
 	Wire protocol:
 	    server -> client : binary frames  = raw terminal output bytes

+ 21 - 0
src/mod/docker/console_other.go

@@ -0,0 +1,21 @@
+//go:build !linux && !darwin && !freebsd
+
+package docker
+
+/*
+	console_other.go
+
+	PTY-backed `docker exec` is only wired up for the PTY-capable hosts handled
+	by console_unix.go (Linux / macOS / FreeBSD). On every other platform —
+	Windows (ConPTY support via creack/pty varies by Windows build) and any GOOS
+	without a supported pseudo-terminal — this catch-all stub keeps the package
+	compiling and returns a clear runtime error instead, the same pattern
+	wifi_windows.go uses for unsupported operations.
+*/
+
+import "errors"
+
+// startDockerExecPTY is unsupported on this host platform.
+func startDockerExecPTY(ref, shell string) (ptySession, error) {
+	return nil, errors.New("interactive container console is not supported when ArozOS runs on this host platform")
+}

+ 4 - 4
src/mod/docker/console_unix.go

@@ -1,14 +1,14 @@
-//go:build linux || darwin
+//go:build linux || darwin || freebsd
 
 package docker
 
 /*
 	console_unix.go
 
-	Real PTY-backed `docker exec -it` for Linux/macOS hosts using
+	Real PTY-backed `docker exec -it` for Linux/macOS/FreeBSD hosts using
 	github.com/creack/pty (MIT). Isolated behind a build tag so non-PTY
-	platforms (Windows) compile against console_windows.go instead, per the
-	project's cross-platform rule.
+	platforms (Windows and any other GOOS) compile against console_other.go
+	instead, per the project's cross-platform rule.
 */
 
 import (

+ 0 - 19
src/mod/docker/console_windows.go

@@ -1,19 +0,0 @@
-//go:build windows
-
-package docker
-
-/*
-	console_windows.go
-
-	PTY-backed `docker exec` is not wired up for Windows hosts in this version
-	(ConPTY support via creack/pty varies by Windows build). This stub keeps the
-	package compiling on Windows and returns a clear runtime error instead, the
-	same pattern wifi_windows.go uses for unsupported operations.
-*/
-
-import "errors"
-
-// startDockerExecPTY is unsupported on Windows hosts.
-func startDockerExecPTY(ref, shell string) (ptySession, error) {
-	return nil, errors.New("interactive container console is not supported when ArozOS runs on a Windows host")
-}

+ 2 - 2
src/mod/docker/host.go

@@ -6,8 +6,8 @@ package docker
 	Lightweight host resource snapshot for the Docker Manager overview cards
 	(CPU / RAM / Storage / Load). CPU and RAM reuse the shared usageinfo monitor;
 	storage and load average are read via build-tagged platform helpers
-	(host_linux.go / host_darwin.go / host_windows.go) so each platform reports
-	what it can and the rest degrade to "unavailable".
+	(host_linux.go / host_bsd.go / host_windows.go / host_other.go) so each
+	platform reports what it can and the rest degrade to "unavailable".
 */
 
 import (

+ 5 - 4
src/mod/docker/host_darwin.go → src/mod/docker/host_bsd.go

@@ -1,11 +1,12 @@
-//go:build darwin
+//go:build darwin || freebsd
 
 package docker
 
 import "syscall"
 
 // hostStorageUsage reports used/total bytes of the filesystem holding the
-// current working directory.
+// current working directory. syscall.Statfs is available on both macOS and
+// FreeBSD with the same Statfs_t block-count fields.
 func hostStorageUsage() (int64, int64, bool) {
 	var st syscall.Statfs_t
 	if err := syscall.Statfs(".", &st); err != nil {
@@ -20,8 +21,8 @@ func hostStorageUsage() (int64, int64, bool) {
 	return total - avail, total, true
 }
 
-// hostLoadAvg is not wired up on macOS (getloadavg needs cgo); report
-// unavailable so the UI hides the value.
+// hostLoadAvg is not wired up on macOS (getloadavg needs cgo) or FreeBSD (no
+// /proc/loadavg); report unavailable so the UI hides the value.
 func hostLoadAvg() (float64, float64, float64, bool) {
 	return 0, 0, 0, false
 }

+ 22 - 0
src/mod/docker/host_other.go

@@ -0,0 +1,22 @@
+//go:build !linux && !darwin && !freebsd && !windows
+
+package docker
+
+/*
+	host_other.go
+
+	Catch-all host-stats helpers for any GOOS not covered by host_linux.go,
+	host_bsd.go (darwin/freebsd) or host_windows.go. These report "unavailable"
+	so the Docker Manager overview cards degrade gracefully instead of failing to
+	build, keeping the package portable per the project's cross-platform rule.
+*/
+
+// hostStorageUsage is not wired up on this platform.
+func hostStorageUsage() (int64, int64, bool) {
+	return 0, 0, false
+}
+
+// hostLoadAvg is not wired up on this platform.
+func hostLoadAvg() (float64, float64, float64, bool) {
+	return 0, 0, 0, false
+}