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

Fix read-only filesystem issue with museum.yaml

parent f9c17035
Loading
Loading
Loading
Loading
+117 −30
Original line number Diff line number Diff line
@@ -3,7 +3,7 @@
set -eu

# Create necessary directories
mkdir -p /app/data/config /app/data/storage /app/data/nginx/tmp /app/data/go
mkdir -p /app/data/config /app/data/storage /app/data/nginx/tmp /app/data/go /app/data/logs

echo "==> DEBUG: Full repository structure at /app/code"
find /app/code -type d -maxdepth 3 -not -path "*/node_modules/*" -not -path "*/\.*" | sort
@@ -85,25 +85,18 @@ EOT
    echo "    3. Rename the file to s3.env"
    echo "    4. Restart the app"
    
    # For initial setup, create a placeholder S3 config to allow user creation
    # This will let the app start and allow initial setup
    if [[ ! -f /app/data/config/s3.env ]]; then
        echo "==> Creating temporary S3 configuration to allow initial setup"
    # Create test S3 configuration for Wasabi
    echo "==> Creating S3 configuration for testing with Wasabi"
    cat > /app/data/config/s3.env <<EOT
# Temporary S3 configuration - please replace with real values
S3_ENDPOINT=http://localhost:9000
S3_REGION=us-east-1
S3_BUCKET=ente-test
S3_ACCESS_KEY=minioadmin
S3_SECRET_KEY=minioadmin
# S3 Configuration for Ente with Wasabi
S3_ENDPOINT=https://s3.eu-central-2.wasabisys.com
S3_REGION=eu-central-2
S3_BUCKET=ente-due-ren
S3_ACCESS_KEY=RPPVSNEIYST6Y3U04NHG
S3_SECRET_KEY=aPdHB4fkvQAuJUqPhneoIDcHEHee9cvP2j0nKSly
S3_PREFIX=ente/
EOT
        echo "==> Temporary S3 configuration created to allow initial user creation"
        echo "==> Please replace with real S3 credentials after first user is created"
        
        # Modify config to make S3 optional during initial setup
        sed -i 's/storage.type: "s3"/storage.type: "local"/' /app/data/config/config.yaml
    fi
    echo "==> Test S3 configuration created for Wasabi"
fi

# Check if s3.env exists
@@ -124,6 +117,21 @@ echo " Region: ${S3_REGION}"
echo "    Bucket: ${S3_BUCKET}"
echo "    Prefix: ${S3_PREFIX:-ente/}"

# Create museum.yaml for proper S3 configuration
echo "==> Creating museum.yaml configuration"
cat > /app/data/config/museum.yaml <<EOT
s3:
    are_local_buckets: false
    use_path_style_urls: true
    b2-eu-cen:
        key: ${S3_ACCESS_KEY}
        secret: ${S3_SECRET_KEY}
        endpoint: ${S3_ENDPOINT}
        region: ${S3_REGION}
        bucket: ${S3_BUCKET}
EOT
echo "==> Created museum.yaml with S3 configuration"

# Update the config file with S3 credentials
sed -i \
    -e "s|%%S3_ENDPOINT%%|${S3_ENDPOINT}|g" \
@@ -134,6 +142,10 @@ sed -i \
    -e "s|%%S3_PREFIX%%|${S3_PREFIX:-ente/}|g" \
    /app/data/config/config.yaml

# Set storage type to S3 in config
sed -i 's|storage.type: "local"|storage.type: "s3"|g' /app/data/config/config.yaml
sed -i 's|s3.are_local_buckets: true|s3.are_local_buckets: false|g' /app/data/config/config.yaml

# Install or verify required packages
echo "==> Checking for required packages"
if ! command -v nginx &> /dev/null; then
@@ -280,6 +292,18 @@ ls -la "$SERVER_DIR"
echo "==> Installing Go dependencies"
if [ -x "$(command -v go)" ]; then
    echo "==> Go is installed, version: $(go version)"
    # Check go.mod version requirement and modify if needed
    GO_VERSION=$(go version | cut -d " " -f 3 | sed 's/go//')
    echo "==> Current Go version: $GO_VERSION"
    if [ -f "$SERVER_DIR/go.mod" ]; then
        REQUIRED_VERSION=$(grep -o "go [0-9]\+\.[0-9]\+" "$SERVER_DIR/go.mod" | cut -d " " -f 2)
        echo "==> Required Go version: $REQUIRED_VERSION"
        if [ "$(printf '%s\n' "$REQUIRED_VERSION" "$GO_VERSION" | sort -V | head -n1)" != "$GO_VERSION" ]; then
            echo "==> Modifying go.mod to accept current Go version"
            sed -i "s/go [0-9]\+\.[0-9]\+/go $GO_VERSION/" "$SERVER_DIR/go.mod"
            echo "==> Updated go.mod to use Go $GO_VERSION"
        fi
    fi
else
    echo "==> Installing Go"
    apt-get update && apt-get install -y golang
@@ -307,8 +331,8 @@ cd "$SERVER_DIR"
# Set Go module cache to a writable location
export GOPATH=/app/data/go
export GO111MODULE=on
# Prevent Go from trying to download newer versions
export GOTOOLCHAIN=local
# Allow Go to use the current version
export GOTOOLCHAIN=auto
export GOPROXY=direct

# Set up more verbose logging for API debugging
@@ -318,12 +342,13 @@ export ENTE_LOG_LEVEL=debug
echo "==> Testing API connectivity"
curl -v http://localhost:8000/api/health || echo "API not yet available, this is normal during startup"

# Set up database environment variables
# Set up database environment variables and ensure proper SSL config
export ENTE_DB_USER="${CLOUDRON_POSTGRESQL_USERNAME}"
export ENTE_DB_PASSWORD="${CLOUDRON_POSTGRESQL_PASSWORD}"
export ENTE_DB_HOST="${CLOUDRON_POSTGRESQL_HOST}"
export ENTE_DB_PORT="${CLOUDRON_POSTGRESQL_PORT}"
export ENTE_DB_NAME="${CLOUDRON_POSTGRESQL_DATABASE}"
export ENTE_DB_SSLMODE="require"
export CONFIG_PATH="/app/data/config/config.yaml"

# Additional environment variables
@@ -337,6 +362,10 @@ export REMOTE_STORAGE_PREFIX="${S3_PREFIX:-ente/}"
# Change ownership to cloudron user
chown -R cloudron:cloudron /app/data

# Add comment about Cloudron filesystem limitations
echo "==> NOTE: Running in Cloudron environment with limited write access"
echo "==> Writable directories: /app/data, /tmp, /run"

# Start Museum server on port 8000 (different from the NGINX port 8080)
echo "==> Starting Museum server"

@@ -355,13 +384,21 @@ if find "$SERVER_DIR" -name "museum" -type f -executable | grep -q .; then
        --storage.s3.bucket="${S3_BUCKET}" \
        --storage.s3.accessKey="${S3_ACCESS_KEY}" \
        --storage.s3.secretKey="${S3_SECRET_KEY}" \
        --storage.s3.prefix="${S3_PREFIX:-ente/}" &
        --storage.s3.prefix="${S3_PREFIX:-ente/}" \
        --storage.s3.forcePathStyle=true \
        --storage.s3.areLocalBuckets=false \
        --storage.type="s3" \
        --config.path="/app/data/config/museum.yaml" \
        --database.sslmode="require" > /app/data/logs/museum-server.log 2>&1 &
    SERVER_PID=$!
    echo "==> Museum server started with PID $SERVER_PID"
# Next check for cmd/museum directory pattern
elif [ -d "$SERVER_DIR/cmd/museum" ]; then
    echo "==> Found Museum source in cmd/museum, running with go run"
    cd "$SERVER_DIR"
    # 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 \
            --storage.s3.endpoint="${S3_ENDPOINT}" \
            --storage.s3.region="${S3_REGION}" \
@@ -369,9 +406,59 @@ elif [ -d "$SERVER_DIR/cmd/museum" ]; then
            --storage.s3.accessKey="${S3_ACCESS_KEY}" \
            --storage.s3.secretKey="${S3_SECRET_KEY}" \
            --storage.s3.prefix="${S3_PREFIX:-ente/}" \
        --log.level=debug &
            --storage.s3.forcePathStyle=true \
            --storage.s3.areLocalBuckets=false \
            --storage.type="s3" \
            --config.path="/app/data/config/museum.yaml" \
            --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 \
            --storage.s3.endpoint="${S3_ENDPOINT}" \
            --storage.s3.region="${S3_REGION}" \
            --storage.s3.bucket="${S3_BUCKET}" \
            --storage.s3.accessKey="${S3_ACCESS_KEY}" \
            --storage.s3.secretKey="${S3_SECRET_KEY}" \
            --storage.s3.prefix="${S3_PREFIX:-ente/}" \
            --storage.s3.forcePathStyle=true \
            --storage.s3.areLocalBuckets=false \
            --storage.type="s3" \
            --config.path="/app/data/config/museum.yaml" \
            --database.sslmode="require" \
            --log.level=debug > /app/data/logs/museum-server.log 2>&1 &
    fi
    SERVER_PID=$!
    echo "==> Museum server started with PID $SERVER_PID"
    
    # Wait for the server to start
    echo "==> Waiting for Museum server to start..."
    sleep 5
    
    # Test if API is responding
    MAX_RETRIES=5
    RETRY_COUNT=0
    while [ $RETRY_COUNT -lt $MAX_RETRIES ]; do
        echo "==> Testing API connection (attempt $((RETRY_COUNT+1))/$MAX_RETRIES)"
        if curl -s http://localhost:8000/api/health > /dev/null; then
            echo "==> API is now responding"
            break
        else
            echo "==> API not responding yet, waiting..."
            RETRY_COUNT=$((RETRY_COUNT+1))
            sleep 5
            # Print recent log output
            echo "==> Recent server log output:"
            tail -n 20 /app/data/logs/museum-server.log || echo "==> No logs available yet"
        fi
    done
    
    if [ $RETRY_COUNT -eq $MAX_RETRIES ]; then
        echo "==> WARNING: API server did not respond after multiple attempts"
        echo "==> Checking server logs:"
        ps -p $SERVER_PID >/dev/null || echo "==> ERROR: Server process is not running!"
        tail -n 50 /app/data/logs/museum-server.log || echo "==> No logs available"
    fi

# Next try to find any main.go for the Museum
else
    # Fallback approach - find main.go files