Commit 50a19a79 authored by Andreas Düren's avatar Andreas Düren
Browse files

Fix Go module structure for mock servers to resolve build issues

parent c00be35f
Loading
Loading
Loading
Loading
+435 −396
Original line number Diff line number Diff line
@@ -1068,7 +1068,13 @@ else
    
    # Create a temporary directory for a simple Go server
    mkdir -p /tmp/mock-server
    cat > /tmp/mock-server/main.go <<"GOMOCK"
    cd /tmp/mock-server
    
    # Initialize a proper Go module
    go mod init mock-server
    
    # Write the program to a file
    cat > main.go << 'GOMOCK'
package main

import (
@@ -1177,6 +1183,16 @@ func main() {
                "ott": verificationCode,
                "exp": time.Now().Add(time.Hour).Unix(),
                "email": email,
                "createdAt": time.Now().Format(time.RFC3339),
                "updatedAt": time.Now().Format(time.RFC3339),
                "key": map[string]interface{}{
                    "pubKey": "mockPubKey123456",
                    "encPubKey": "mockEncPubKey123456",
                    "kty": "mockKty",
                    "kid": "mockKid",
                    "alg": "mockAlg",
                    "verifyKey": "mockVerifyKey123456",
                },
            }
            json.NewEncoder(w).Encode(jsonResponse)
        } else {
@@ -1440,16 +1456,15 @@ func main() {
GOMOCK
    
    # Unset any module-related flags before running standalone Go program
    echo "==> Unsetting module flags before building mock server"
    unset GO111MODULE
    unset GOFLAGS
    unset GOMODCACHE
    
    # Build and run the mock server in the background
    echo "==> Building and starting mock API server on port 8080"
    
    # Make sure we're using Go 1.24.1 for the build
    export PATH="/usr/local/go/bin:${PATH}"
    
    if go build -o mock_server main.go; then
    if go build -o mock_server; then
        echo "==> Successfully compiled mock API server"
        
        # Create log directory if it doesn't exist
@@ -1486,10 +1501,12 @@ GOMOCK
        echo "==> ERROR: Failed to build mock API server"
        # Print Go version for debugging
        go version
        # Set a bogus server PID to prevent unbound variable error
        SERVER_PID=0
    fi
fi

echo "==> Server started with PID $SERVER_PID"
echo "==> Server started with PID ${SERVER_PID:-0}"

# Test if API is responding
echo "==> Testing API connectivity"
@@ -1525,7 +1542,12 @@ elif [ -d "$SERVER_DIR/cmd/museum" ]; then
    # Create a startup script but don't use module flags
    echo "==> Creating mock Public Albums API server"
    mkdir -p /tmp/mock-public-server
    cat > /tmp/mock-public-server/main.go <<"EOT"
    cd /tmp/mock-public-server
    
    # Initialize a proper Go module
    go mod init mock-public-server
    
    cat > main.go <<"EOT"
package main

import (
@@ -1620,22 +1642,24 @@ func main() {
EOT

        # Unset any module-related flags before running standalone Go program
        echo "==> Unsetting module flags before building public albums mock server"
        unset GO111MODULE
        unset GOFLAGS
        unset GOMODCACHE
        
        # Build and run the public albums mock server
        echo "==> Building and starting Public Albums mock server on port 8081"
    cd /tmp/mock-public-server
    if go build -o mock_public_server main.go; then
        if go build -o mock_public_server; then
            echo "==> Successfully compiled Public Albums mock server"
            # Start the server and log both to file and to console
            chmod +x ./mock_public_server
            nohup ./mock_public_server > /app/data/logs/mock_public_server.log 2>&1 &
            PUBLIC_SERVER_PID=$!
            echo "==> Public Albums mock server started with PID $PUBLIC_SERVER_PID"
            
            # Wait to ensure the server is up
            echo "==> Waiting for Public Albums server to start..."
        sleep 2
            sleep 3
            
            # Check if the server is actually running
            if ps -p $PUBLIC_SERVER_PID > /dev/null; then
@@ -1647,7 +1671,7 @@ EOT
                else
                    echo "==> WARNING: Public Albums mock server doesn't appear to be listening on port 8081"
                    echo "==> Checking server logs:"
                tail -n 10 /app/data/logs/mock_public_server.log
                    tail -n 20 /app/data/logs/mock_public_server.log
                fi
            else
                echo "==> ERROR: Public Albums mock server failed to start"
@@ -1656,6 +1680,10 @@ EOT
            fi
        else
            echo "==> ERROR: Failed to build Public Albums mock server"
            # Print Go version for debugging
            go version
            # Set a fallback value for PUBLIC_SERVER_PID
            PUBLIC_SERVER_PID=0
        fi
    else
        echo "==> ERROR: Museum server not found for public albums"
@@ -1663,7 +1691,12 @@ else
        
        # Create a temporary directory for a simple Go server
        mkdir -p /tmp/mock-public-server
    cat > /tmp/mock-public-server/main.go <<"EOT"
        cd /tmp/mock-public-server
        
        # Initialize a proper Go module
        go mod init mock-public-server
        
        cat > main.go <<"EOT"
package main

import (
@@ -1758,22 +1791,24 @@ func main() {
EOT

        # Unset any module-related flags before running standalone Go program
        echo "==> Unsetting module flags before building public albums mock server"
        unset GO111MODULE
        unset GOFLAGS
        unset GOMODCACHE
        
        # Build and run the public albums mock server
        echo "==> Building and starting Public Albums mock server on port 8081"
    cd /tmp/mock-public-server
    if go build -o mock_public_server main.go; then
        if go build -o mock_public_server; then
            echo "==> Successfully compiled Public Albums mock server"
            # Start the server and log both to file and to console
            chmod +x ./mock_public_server
            nohup ./mock_public_server > /app/data/logs/mock_public_server.log 2>&1 &
            PUBLIC_SERVER_PID=$!
            echo "==> Public Albums mock server started with PID $PUBLIC_SERVER_PID"
            
            # Wait to ensure the server is up
            echo "==> Waiting for Public Albums server to start..."
        sleep 2
            sleep 3
            
            # Check if the server is actually running
            if ps -p $PUBLIC_SERVER_PID > /dev/null; then
@@ -1785,7 +1820,7 @@ EOT
                else
                    echo "==> WARNING: Public Albums mock server doesn't appear to be listening on port 8081"
                    echo "==> Checking server logs:"
                tail -n 10 /app/data/logs/mock_public_server.log
                    tail -n 20 /app/data/logs/mock_public_server.log
                fi
            else
                echo "==> ERROR: Public Albums mock server failed to start"
@@ -1794,10 +1829,14 @@ EOT
            fi
        else
            echo "==> ERROR: Failed to build Public Albums mock server"
            # Print Go version for debugging
            go version
            # Set a fallback value for PUBLIC_SERVER_PID
            PUBLIC_SERVER_PID=0
        fi
    fi

echo "==> Public Albums server started with PID $PUBLIC_SERVER_PID"
    echo "==> Public Albums server started with PID ${PUBLIC_SERVER_PID:-0}"

    # Test if Public Albums API is responding
    echo "==> Testing Public Albums API connectivity"