Fix Go compatibility and mock server issues

This commit is contained in:
Andreas Düren 2025-03-14 23:03:47 +01:00
parent 192ebd0b5d
commit 4b7fb0fd9c

View File

@ -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, "<html><body><h1>Ente Museum Server Error</h1>")
fmt.Fprintf(w, "<p>The Ente Museum server could not be started due to compatibility issues.</p>")
fmt.Fprintf(w, "<p>Please check the logs for more information.</p>")
// 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, "<h2>Recent Log Output:</h2><pre>%s</pre>", logs)
}
}
fmt.Fprintf(w, "</body></html>")
html := "<html><body><h1>Ente Museum Server Error</h1>"
html += "<p>The Ente Museum server could not be started due to compatibility issues.</p>"
html += "<p>Please check the application logs for more information.</p>"
html += "</body></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=$!