Update start.sh to handle Museum Go server component

This commit is contained in:
Andreas Düren 2025-03-14 21:42:26 +01:00
parent fb0d4fd34f
commit 1d30b3d943

158
start.sh
View File

@ -89,79 +89,121 @@ sed -i \
-e "s|%%S3_PREFIX%%|${S3_PREFIX:-ente/}|g" \ -e "s|%%S3_PREFIX%%|${S3_PREFIX:-ente/}|g" \
/app/data/config/config.yaml /app/data/config/config.yaml
# Find the correct server directory # Looking for Museum (Go server component)
SERVER_DIR="" echo "==> Looking for Museum (Go server component)"
# More thorough search for server directory # Find the server directory
# Try specific paths first if [ -d "/app/code/server" ]; then
for dir in "/app/code/server" "/app/code/packages/server"; do echo "==> Found server directory at /app/code/server"
if [ -f "$dir/package.json" ]; then SERVER_DIR="/app/code/server"
SERVER_DIR="$dir" else
break echo "==> ERROR: Could not find server directory at /app/code/server"
fi echo "==> Looking for Museum executable or source in alternate locations"
done
# If not found, search for any directory containing package.json with "server" in its path # Search for Museum executable or Go source files
if [ -z "$SERVER_DIR" ]; then GO_FILES=$(find /app/code -name "*.go" -not -path "*/\.*" | sort)
SERVER_CANDIDATES=$(find /app/code -name "package.json" -not -path "*/node_modules/*" -path "*/server*" | sort) if [ -n "$GO_FILES" ]; then
if [ -n "$SERVER_CANDIDATES" ]; then echo "==> Found Go files in repository:"
FIRST_CANDIDATE=$(echo "$SERVER_CANDIDATES" | head -n 1) echo "$GO_FILES"
SERVER_DIR=$(dirname "$FIRST_CANDIDATE")
# Check for museum in Go files path
if find /app/code -path "*/museum/*" -name "*.go" | grep -q .; then
MUSEUM_DIR=$(find /app/code -path "*/museum/*" -name "*.go" | head -1 | xargs dirname)
echo "==> Found Museum directory at $MUSEUM_DIR"
else
echo "==> No clear Museum directory found"
echo "==> Using first Go file directory as fallback"
FIRST_GO_FILE=$(echo "$GO_FILES" | head -1)
MUSEUM_DIR=$(dirname "$FIRST_GO_FILE")
fi
# Check for cmd/museum pattern which is mentioned in docs
if [ -d "/app/code/server/cmd/museum" ]; then
MUSEUM_DIR="/app/code/server/cmd/museum"
echo "==> Found Museum main directory at $MUSEUM_DIR"
fi
SERVER_DIR=$(dirname $(dirname "$MUSEUM_DIR"))
else
echo "==> FATAL ERROR: Could not find Go files in repository"
echo "==> Repository structure:"
find /app/code -type d -maxdepth 3 | sort
exit 1
fi fi
fi fi
# Last resort - look for package.json in the monorepo root echo "==> Selected server directory: $SERVER_DIR"
if [ -z "$SERVER_DIR" ] && [ -f "/app/code/package.json" ]; then
echo "==> Using root package.json as server directory"
SERVER_DIR="/app/code"
fi
if [ -z "$SERVER_DIR" ]; then
echo "==> ERROR: Could not find server directory with package.json"
echo " Server directory structure may have changed."
echo " Please check the ente repository structure."
exit 1
fi
echo "==> Found server directory at $SERVER_DIR"
echo "==> Contents of $SERVER_DIR:" echo "==> Contents of $SERVER_DIR:"
ls -la "$SERVER_DIR" ls -la "$SERVER_DIR"
echo "==> Contents of package.json:"
cat "$SERVER_DIR/package.json" # Check for server dependencies
echo "==> Installing Go dependencies"
if [ -x "$(command -v go)" ]; then
echo "==> Go is installed, version: $(go version)"
else
echo "==> Installing Go"
apt-get update && apt-get install -y golang
fi
# Check for libsodium
if dpkg -l | grep -q libsodium; then
echo "==> libsodium is installed"
else
echo "==> Installing libsodium"
apt-get update && apt-get install -y libsodium23 libsodium-dev
fi
# Check for pkg-config
if [ -x "$(command -v pkg-config)" ]; then
echo "==> pkg-config is installed"
else
echo "==> Installing pkg-config"
apt-get update && apt-get install -y pkg-config
fi
# Change to server directory # Change to server directory
cd "$SERVER_DIR" cd "$SERVER_DIR"
# Run database migrations if the script exists # Set up database environment variables
if grep -q "\"db-migrate\"" package.json; then export ENTE_DB_USER="${CLOUDRON_POSTGRESQL_USERNAME}"
echo "==> Running database migrations" export ENTE_DB_PASSWORD="${CLOUDRON_POSTGRESQL_PASSWORD}"
NODE_ENV=production yarn run db-migrate || { export ENTE_DB_HOST="${CLOUDRON_POSTGRESQL_HOST}"
echo "==> WARNING: Database migration failed, but continuing anyway" export ENTE_DB_PORT="${CLOUDRON_POSTGRESQL_PORT}"
} export ENTE_DB_NAME="${CLOUDRON_POSTGRESQL_DATABASE}"
else export CONFIG_PATH="/app/data/config/config.yaml"
echo "==> Skipping database migrations (script not found)"
fi
# Check for alternative start scripts if "serve" doesn't exist # Additional environment variables
SERVE_SCRIPT="" export REMOTE_STORAGE_ENDPOINT="${S3_ENDPOINT}"
for script in "serve" "start" "dev" "server"; do export REMOTE_STORAGE_REGION="${S3_REGION}"
if grep -q "\"$script\"" package.json; then export REMOTE_STORAGE_BUCKET="${S3_BUCKET}"
SERVE_SCRIPT="$script" export REMOTE_STORAGE_ACCESS_KEY="${S3_ACCESS_KEY}"
break export REMOTE_STORAGE_SECRET_KEY="${S3_SECRET_KEY}"
fi export REMOTE_STORAGE_PREFIX="${S3_PREFIX:-ente/}"
done
# Change ownership to cloudron user # Change ownership to cloudron user
chown -R cloudron:cloudron /app/data chown -R cloudron:cloudron /app/data
# Start the server # Look for Museum binary first
if [ -n "$SERVE_SCRIPT" ]; then if [ -x "$SERVER_DIR/museum" ]; then
echo "==> Starting Ente server with script: $SERVE_SCRIPT" echo "==> Found Museum binary, running it directly"
exec /usr/local/bin/gosu cloudron:cloudron NODE_ENV=production CONFIG_PATH=/app/data/config/config.yaml yarn run "$SERVE_SCRIPT" exec /usr/local/bin/gosu cloudron:cloudron "$SERVER_DIR/museum"
elif [ -d "$SERVER_DIR/cmd/museum" ]; then
echo "==> Found Museum source in cmd/museum, running with go run"
cd "$SERVER_DIR"
exec /usr/local/bin/gosu cloudron:cloudron go run cmd/museum/main.go
else else
echo "==> ERROR: Could not find any server script in package.json" # Fallback approach - find main.go files
echo " Available scripts:" MAIN_FILES=$(find "$SERVER_DIR" -name "main.go" | grep -v "test")
grep -o '"[^"]*"\s*:\s*"[^"]*"' package.json | grep -o '"[^"]*"' | head -n 1 | tr -d '"' if [ -n "$MAIN_FILES" ]; then
echo " Please check the ente repository structure." MAIN_FILE=$(echo "$MAIN_FILES" | head -1)
exit 1 MAIN_DIR=$(dirname "$MAIN_FILE")
echo "==> Using main.go file at $MAIN_FILE"
cd "$MAIN_DIR"
exec /usr/local/bin/gosu cloudron:cloudron go run main.go
else
echo "==> FATAL ERROR: Could not find Museum binary or main.go source file"
echo "==> Available Go files:"
find "$SERVER_DIR" -name "*.go" | sort
exit 1
fi
fi fi