From 597f679901eac6410e6835daeede474f4e2c3887 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <209825114+claude[bot]@users.noreply.github.com> Date: Tue, 24 Jun 2025 13:13:12 +0000 Subject: [PATCH] fix: configure Docker to use mounted volume for basic-memory data - Add docker-init.sh script to initialize config.json pointing to /app/data - Update Dockerfile to use initialization script as entrypoint - Update docker-compose.yml comments to reflect automatic configuration - Ensures mounted knowledge files in /app/data are properly indexed Fixes issue where .basic-memory/config.json wasn't configured to use the mounted directory, causing files in /app/data to not get indexed. Co-authored-by: Paul Hernandez --- Dockerfile | 7 ++++++- docker-compose.yml | 4 ++-- docker-init.sh | 42 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 docker-init.sh diff --git a/Dockerfile b/Dockerfile index dcd52801..13cfccb1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -17,6 +17,10 @@ RUN uv sync --locked # Create data directory RUN mkdir -p /app/data +# Copy and setup initialization script +COPY docker-init.sh /app/docker-init.sh +RUN chmod +x /app/docker-init.sh + # Set default data directory and add venv to PATH ENV BASIC_MEMORY_HOME=/app/data \ PATH="/app/.venv/bin:$PATH" @@ -28,5 +32,6 @@ EXPOSE 8000 HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \ CMD basic-memory --version || exit 1 -# Use the basic-memory entrypoint to run the MCP server with default SSE transport +# Use initialization script as entrypoint with the basic-memory command +ENTRYPOINT ["/app/docker-init.sh"] CMD ["basic-memory", "mcp", "--transport", "sse", "--host", "0.0.0.0", "--port", "8000"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 79ec6a62..9e87e9a4 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,8 +27,8 @@ services: # - ./work-notes:/app/data/work:rw # - ./personal-notes:/app/data/personal:rw - # You can edit the project config manually in the mounted config volume - # The default project will be configured to use /app/data + # Configuration is automatically initialized to use the mounted /app/data directory + # You can edit the project config manually in the mounted config volume if needed environment: # Project configuration - BASIC_MEMORY_DEFAULT_PROJECT=main diff --git a/docker-init.sh b/docker-init.sh new file mode 100644 index 00000000..d0a9c24f --- /dev/null +++ b/docker-init.sh @@ -0,0 +1,42 @@ +#!/bin/bash +set -e + +# Initialize Basic Memory configuration for Docker +CONFIG_DIR="/root/.basic-memory" +CONFIG_FILE="$CONFIG_DIR/config.json" +DATA_DIR="/app/data" + +echo "Initializing Basic Memory Docker configuration..." + +# Create config directory if it doesn't exist +mkdir -p "$CONFIG_DIR" + +# Create config.json if it doesn't exist or if it doesn't point to the correct data directory +if [ ! -f "$CONFIG_FILE" ] || ! grep -q '"main".*"/app/data"' "$CONFIG_FILE" 2>/dev/null; then + echo "Creating config.json pointing to mounted volume at $DATA_DIR" + cat > "$CONFIG_FILE" << EOF +{ + "projects": { + "main": "$DATA_DIR" + }, + "default_project": "main", + "env": "user", + "log_level": "INFO", + "sync_changes": true, + "sync_delay": 1000, + "update_permalinks_on_move": false +} +EOF +else + echo "Config file already exists and points to correct data directory" +fi + +# Ensure data directory exists +mkdir -p "$DATA_DIR" + +echo "Configuration initialized successfully" +echo "Config file contents:" +cat "$CONFIG_FILE" + +# Execute the original command +exec "$@" \ No newline at end of file