Fix Museum server binary issues using Docker approach

This commit is contained in:
Andreas Düren 2025-03-20 16:35:30 +01:00
parent e95fd0a705
commit fc7135d483

132
start.sh
View File

@ -287,109 +287,69 @@ start_placeholder_server() {
return 1 return 1
} }
# Setup and attempt to run Museum server # Setting up and attempting to run the Museum server
echo "==> Setting up Museum server..." echo "==> Setting up Museum server..."
# Set GOPATH for Go builds # Try using Docker to pull and run the Museum server
export GOPATH="/app/data/go"
export PATH="$GOPATH/bin:$PATH"
# Check for existing Museum binary
MUSEUM_BIN="/app/data/ente/server/museum" MUSEUM_BIN="/app/data/ente/server/museum"
MUSEUM_IMAGE="ghcr.io/ente-io/server:latest"
VALID_BINARY=false VALID_BINARY=false
if [ -f "$MUSEUM_BIN" ]; then # Check if Docker is available
# Check if the file is a valid binary if command -v docker >/dev/null 2>&1; then
echo "==> Checking if Museum binary is valid..." echo "==> Docker is available, attempting to use Museum server image"
file_type=$(file -b "$MUSEUM_BIN")
# Log the file type for debugging # Try pulling the Museum server image
echo "==> Museum binary file type: $file_type" if docker pull $MUSEUM_IMAGE; then
echo "==> Successfully pulled Museum server image"
# Check file content for debugging # Extract the Museum binary from the Docker image
echo "==> First few lines of Museum binary:" TEMP_CONTAINER=$(docker create $MUSEUM_IMAGE)
head -n 3 "$MUSEUM_BIN" || echo "==> Unable to read binary file" if [ -n "$TEMP_CONTAINER" ]; then
echo "==> Created temporary container to extract Museum binary"
# Check if it's an ELF executable or contains ELF in the description mkdir -p "$(dirname "$MUSEUM_BIN")"
if [[ "$file_type" == *"ELF"* ]] && [ -x "$MUSEUM_BIN" ]; then if docker cp "$TEMP_CONTAINER:/app/museum" "$MUSEUM_BIN"; then
echo "==> Found valid Museum binary, using it" chmod +x "$MUSEUM_BIN"
VALID_BINARY=true docker rm "$TEMP_CONTAINER" >/dev/null
else echo "==> Successfully extracted Museum binary from Docker image"
echo "==> Museum binary exists but is not a valid executable, removing it" VALID_BINARY=true
rm -f "$MUSEUM_BIN" else
fi echo "==> Failed to extract Museum binary from container"
fi docker rm "$TEMP_CONTAINER" >/dev/null
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
echo "==> Building Museum server from source..."
# Navigate to the server directory
cd "$ENTE_DIR/server"
# Build the Museum server
echo "==> Building Museum server..."
mkdir -p "$(dirname "$MUSEUM_BIN")"
go build -o "$MUSEUM_BIN" ./cmd/museum
if [ $? -eq 0 ] && [ -f "$MUSEUM_BIN" ] && [ -x "$MUSEUM_BIN" ]; then
echo "==> Successfully built Museum server"
VALID_BINARY=true
else else
echo "==> Failed to build Museum server" echo "==> Failed to create temporary container"
fi fi
else else
echo "==> Go not found, skipping build" echo "==> Failed to pull Museum server image"
fi fi
else
echo "==> Docker not available, skipping Docker-based Museum binary extraction"
fi
# If build failed or Go not available, try downloading # If Docker extraction failed, try building from source
if [ "$VALID_BINARY" = false ]; then if [ "$VALID_BINARY" = false ] && command -v go >/dev/null 2>&1; then
echo "==> Trying to download Museum binary..." echo "==> Building Museum server from source..."
# Determine architecture and platform # Navigate to the server directory
ARCH=$(uname -m) cd "$ENTE_DIR/server"
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
case "$ARCH" in # Build the Museum server
x86_64) echo "==> Building Museum server..."
ARCH="amd64" mkdir -p "$(dirname "$MUSEUM_BIN")"
;; export GOPATH="/app/data/go"
aarch64|arm64) export PATH="$GOPATH/bin:$PATH"
ARCH="arm64"
;;
esac
# Try downloading from GitHub releases # Install required build dependencies
URLS=( apt-get update -y && apt-get install -y golang-go gcc libsodium-dev pkg-config
"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 go build -o "$MUSEUM_BIN" ./cmd/museum
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 if [ $? -eq 0 ] && [ -f "$MUSEUM_BIN" ] && [ -x "$MUSEUM_BIN" ]; then
file_type=$(file -b "$MUSEUM_BIN") echo "==> Successfully built Museum server"
echo "==> Downloaded file type: $file_type" VALID_BINARY=true
else
if [[ "$file_type" == *"ELF"* ]] || [[ "$file_type" == *"executable"* ]]; then echo "==> Failed to build Museum server"
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
fi fi