From 4b7fb0fd9c552035d940ec9fb456f43b0d50c798 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20D=C3=BCren?= Date: Fri, 14 Mar 2025 23:03:47 +0100 Subject: [PATCH] Fix Go compatibility and mock server issues --- start.sh | 52 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/start.sh b/start.sh index f1e8f45..58437ff 100644 --- a/start.sh +++ b/start.sh @@ -353,7 +353,9 @@ cd "$SERVER_DIR" export GOPATH=/app/data/go export GO111MODULE=on # Set version compatibility flags -export GOTOOLCHAIN=local +export GOTOOLCHAIN=auto +# Override version requirements +export GOFLAGS="-mod=mod" # Create a temporary directory for Go module cache and build in writable area export GOCACHE=/app/data/go/cache export GOMODCACHE=/app/data/go/modcache @@ -432,12 +434,14 @@ elif [ -d "$SERVER_DIR/cmd/museum" ]; then # Instead of modifying go.mod, set environment variables for compatibility echo "==> Setting Go environment variables for compatibility" export GOFLAGS="-mod=mod" - export GOTOOLCHAIN=local + # Explicitly skip version check + export GOTOOLCHAIN=auto # For Wasabi specific settings if [[ "${S3_ENDPOINT}" == *"wasabi"* ]]; then echo "==> Detected Wasabi S3 endpoint, adjusting settings" - /usr/local/bin/gosu cloudron:cloudron go run cmd/museum/main.go --port 8000 \ + echo "==> Adding -mod=mod to go run to ignore version mismatch" + /usr/local/bin/gosu cloudron:cloudron go run -mod=mod cmd/museum/main.go --port 8000 \ --storage.s3.endpoint="${S3_ENDPOINT}" \ --storage.s3.region="${S3_REGION}" \ --storage.s3.bucket="${S3_BUCKET}" \ @@ -451,7 +455,7 @@ elif [ -d "$SERVER_DIR/cmd/museum" ]; then --database.sslmode="require" \ --log.level=debug > /app/data/logs/museum-server.log 2>&1 & else - /usr/local/bin/gosu cloudron:cloudron go run cmd/museum/main.go --port 8000 \ + /usr/local/bin/gosu cloudron:cloudron go run -mod=mod cmd/museum/main.go --port 8000 \ --storage.s3.endpoint="${S3_ENDPOINT}" \ --storage.s3.region="${S3_REGION}" \ --storage.s3.bucket="${S3_BUCKET}" \ @@ -510,10 +514,10 @@ else # Instead of trying to modify go.mod, set environment variables for compatibility echo "==> Setting Go environment variables for compatibility" export GOFLAGS="-mod=mod" - export GOTOOLCHAIN=local + export GOTOOLCHAIN=auto echo "==> Running main.go with Go" - /usr/local/bin/gosu cloudron:cloudron go run main.go --port 8000 \ + /usr/local/bin/gosu cloudron:cloudron go run -mod=mod main.go --port 8000 \ --storage.s3.endpoint="${S3_ENDPOINT}" \ --storage.s3.region="${S3_REGION}" \ --storage.s3.bucket="${S3_BUCKET}" \ @@ -558,44 +562,40 @@ import ( "fmt" "log" "net/http" - "os" ) func main() { + // Set up a handler for the root path http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") - fmt.Fprintf(w, "

Ente Museum Server Error

") - fmt.Fprintf(w, "

The Ente Museum server could not be started due to compatibility issues.

") - fmt.Fprintf(w, "

Please check the logs for more information.

") - - // Show log excerpts if available - if _, err := os.Stat("/app/data/logs/museum-server.log"); err == nil { - logs, err := os.ReadFile("/app/data/logs/museum-server.log") - if err == nil && len(logs) > 0 { - fmt.Fprintf(w, "

Recent Log Output:

%s
", logs) - } - } - - fmt.Fprintf(w, "") + html := "

Ente Museum Server Error

" + html += "

The Ente Museum server could not be started due to compatibility issues.

" + html += "

Please check the application logs for more information.

" + html += "" + fmt.Fprint(w, html) }) // Add a health endpoint http.HandleFunc("/api/health", func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/json") - w.Write([]byte(`{"status": "error", "message": "Running in fallback mode"}`)) + fmt.Fprint(w, `{"status":"error","message":"Running in fallback mode"}`) }) + // Start the server log.Println("Starting mock server on port 8000") + + // Start in a goroutine to prevent blocking + server := &http.Server{Addr: ":8000"} go func() { - log.Fatal(http.ListenAndServe(":8000", nil)) + if err := server.ListenAndServe(); err != nil { + log.Fatalf("Server error: %v", err) + } }() } EOT - cd /tmp/mock-server - # Set Go environment variables for compatibility with the mock server - export GOFLAGS="-mod=mod" - export GOTOOLCHAIN=local + # Make sure we're in the mock-server directory + cd /tmp/mock-server go run main.go & SERVER_PID=$!