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

Fix Museum server binary issues using Docker approach

parent e95fd0a7
Loading
Loading
Loading
Loading
+51 −91
Original line number Diff line number Diff line
@@ -287,44 +287,48 @@ start_placeholder_server() {
    return 1
}

# Setup and attempt to run Museum server
# Setting up and attempting to run the Museum server
echo "==> Setting up Museum server..."

# Set GOPATH for Go builds
export GOPATH="/app/data/go"
export PATH="$GOPATH/bin:$PATH"

# Check for existing Museum binary
# Try using Docker to pull and run the Museum server
MUSEUM_BIN="/app/data/ente/server/museum"
MUSEUM_IMAGE="ghcr.io/ente-io/server:latest"
VALID_BINARY=false

if [ -f "$MUSEUM_BIN" ]; then
    # Check if the file is a valid binary
    echo "==> Checking if Museum binary is valid..."
    file_type=$(file -b "$MUSEUM_BIN")
    
    # Log the file type for debugging
    echo "==> Museum binary file type: $file_type"
# Check if Docker is available
if command -v docker >/dev/null 2>&1; then
    echo "==> Docker is available, attempting to use Museum server image"
    
    # Check file content for debugging
    echo "==> First few lines of Museum binary:"
    head -n 3 "$MUSEUM_BIN" || echo "==> Unable to read binary file"
    # Try pulling the Museum server image
    if docker pull $MUSEUM_IMAGE; then
        echo "==> Successfully pulled Museum server image"
        
    # Check if it's an ELF executable or contains ELF in the description
    if [[ "$file_type" == *"ELF"* ]] && [ -x "$MUSEUM_BIN" ]; then
        echo "==> Found valid Museum binary, using it"
        # Extract the Museum binary from the Docker image
        TEMP_CONTAINER=$(docker create $MUSEUM_IMAGE)
        if [ -n "$TEMP_CONTAINER" ]; then
            echo "==> Created temporary container to extract Museum binary"
            mkdir -p "$(dirname "$MUSEUM_BIN")"
            if docker cp "$TEMP_CONTAINER:/app/museum" "$MUSEUM_BIN"; then
                chmod +x "$MUSEUM_BIN"
                docker rm "$TEMP_CONTAINER" >/dev/null
                echo "==> Successfully extracted Museum binary from Docker image"
                VALID_BINARY=true
            else
        echo "==> Museum binary exists but is not a valid executable, removing it"
        rm -f "$MUSEUM_BIN"
                echo "==> Failed to extract Museum binary from container"
                docker rm "$TEMP_CONTAINER" >/dev/null
            fi
        else
            echo "==> Failed to create temporary container"
        fi
    else
        echo "==> Failed to pull Museum server image"
    fi
else
    echo "==> Docker not available, skipping Docker-based Museum binary extraction"
fi

if [ "$VALID_BINARY" = false ]; then
    echo "==> No valid Museum binary found, trying to build or download one"
    
    # Check if Go is installed
    if command -v go >/dev/null 2>&1; then
# If Docker extraction failed, try building from source
if [ "$VALID_BINARY" = false ] && command -v go >/dev/null 2>&1; then
    echo "==> Building Museum server from source..."
    
    # Navigate to the server directory
@@ -333,6 +337,12 @@ if [ "$VALID_BINARY" = false ]; then
    # Build the Museum server
    echo "==> Building Museum server..."
    mkdir -p "$(dirname "$MUSEUM_BIN")"
    export GOPATH="/app/data/go"
    export PATH="$GOPATH/bin:$PATH"
    
    # Install required build dependencies
    apt-get update -y && apt-get install -y golang-go gcc libsodium-dev pkg-config
    
    go build -o "$MUSEUM_BIN" ./cmd/museum
    
    if [ $? -eq 0 ] && [ -f "$MUSEUM_BIN" ] && [ -x "$MUSEUM_BIN" ]; then
@@ -341,56 +351,6 @@ if [ "$VALID_BINARY" = false ]; then
    else
        echo "==> Failed to build Museum server"
    fi
    else
        echo "==> Go not found, skipping build"
    fi
    
    # If build failed or Go not available, try downloading
    if [ "$VALID_BINARY" = false ]; then
        echo "==> Trying to download Museum binary..."
        
        # Determine architecture and platform
        ARCH=$(uname -m)
        OS=$(uname -s | tr '[:upper:]' '[:lower:]')
        
        case "$ARCH" in
            x86_64)
                ARCH="amd64"
                ;;
            aarch64|arm64)
                ARCH="arm64"
                ;;
        esac
        
        # Try downloading from GitHub releases
        URLS=(
            "https://github.com/ente-io/ente/releases/latest/download/museum-${OS}-${ARCH}"
            "https://github.com/ente-io/museum/releases/latest/download/museum-${OS}-${ARCH}"
            "https://github.com/ente-io/ente/releases/download/latest/museum-${OS}-${ARCH}"
        )
        
        for URL in "${URLS[@]}"; do
            echo "==> Trying to download from: $URL"
            if curl -L -o "$MUSEUM_BIN" "$URL" && [ -f "$MUSEUM_BIN" ]; then
                chmod +x "$MUSEUM_BIN"
                
                # Verify the downloaded file is executable
                file_type=$(file -b "$MUSEUM_BIN")
                echo "==> Downloaded file type: $file_type"
                
                if [[ "$file_type" == *"ELF"* ]] || [[ "$file_type" == *"executable"* ]]; then
                    echo "==> Successfully downloaded Museum binary"
                    VALID_BINARY=true
                    break
                else
                    echo "==> Downloaded file is not an executable"
                    rm -f "$MUSEUM_BIN"
                fi
            else
                echo "==> Failed to download from $URL"
            fi
        done
    fi
fi

# Try running the Museum server if we have a valid binary