8000 Multiple Docker setup and database migration issues complementing issue #12 · Issue #29 · metatool-ai/metamcp · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Multiple Docker setup and database migration issues complementing issue #12 #29
Closed
@horoong

Description

@horoong

Problem Description

When trying to set up MetaMCP using Docker Compose, I encountered several issues that prevented the application from starting correctly. The main problems were:

  1. Package Installation Dependency Conflicts: React version conflicts when installing dependencies.
  2. Container File Structure Issues: Missing configuration files in the container.
  3. Database Migration Timing: Migrations attempt to run before PostgreSQL is fully initialized (related to issue unable to get image 'metatool-app-drizzle-migrate #12, but with additional problems).

This issue is related to issue #12 which addresses the drizzle-migrate image problem, but presents additional problems and more comprehensive solutions. While issue #12 focuses on the Docker image build process, this issue covers broader problems related to database connection settings, migration timing, and container file structure.

Steps to Reproduce

  1. Clone the repository:
    git clone https://github.com/metatool-ai/metatool-app.git
  2. Copy the example environment file:
    cp example.env .env
  3. Start the containers:
    docker-compose up -d
  4. Try to access the application at http://localhost:12005

Expected Behavior

The application should start successfully with all necessary database tables created, and the web interface should be accessible at http://localhost:12005.

Actual Behavior

The application starts but fails to connect to the database with errors like "relation 'api_keys' does not exist" because the database migration fails to complete successfully. The web server appears to start, but the UI is not accessible due to database connection errors.

Error Logs

metatool-postgres  | 2025-04-06 18:08:37.699 UTC [117] DETAIL:  Role "postgres" does not exist.
metatool-postgres  |    Connection matched file "/var/lib/postgresql/data/pg_hba.conf" line 128: "host all all all scram-sha-256"

drizzle-migrate  | No config path provided, using default 'drizzle.config.ts'
drizzle-migrate  | Reading config file '/app/drizzle.config.ts'
drizzle-migrate  | Using 'pg' driver for database querying
drizzle-migrate  | error: the database system is starting up

metatool-web  | error: relation "api_keys" does not exist

When trying to install dependencies:

npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: metamcp-app@0.1.0
npm error Found: react@19.1.0
npm error node_modules/react
npm error   react@"^19.0.0" from the root project
npm error
npm error Could not resolve dependency:
npm error peer react@"^18.0.0" from cmdk@1.0.0

When trying to run migrations:

docker-compose exec metatool-web npx dotenv-cli -e .env.local -- npx drizzle-kit migrate --config=drizzle.config.ts
/app/drizzle.config.ts file does not exist
exit status 1

Solution

I was able to resolve these issues with the following steps:

  1. Handle Migrations Manually:

    • Wait for PostgreSQL to fully initialize
    • Create a combined SQL file from the migration files:
    # Combine all migration SQL files
    cat drizzle/*.sql > migrations.sql
    
    # Copy to PostgreSQL container
    docker cp migrations.sql metatool-postgres:/tmp/
    
    # Execute the SQL file
    docker-compose exec metatool-postgres psql -U metatool -d metatool -f /tmp/migrations.sql
  2. Fix Package Installation Issues:

    • Use --legacy-peer-deps flag when installing dependencies:
    docker-compose exec metatool-web npm install --save-dev dotenv-cli drizzle-kit --legacy-peer-deps

The Dockerfile modification suggested in issue #12 (RUN corepack enable && corepack prepare pnpm@9.0.0 --activate) can resolve the drizzle-migrate image build problem, but the additional steps proposed here address the more fundamental issues related to database migration failures.

After applying these steps, I was able to successfully access the web application and all tables were created correctly:

docker-compose exec metatool-postgres psql -U metatool -d metatool -c "\dt"
               List of relations
 Schema |        Name        | Type  |  Owner   
--------+--------------------+-------+----------
 public | api_keys           | table | metatool
 public | codes              | table | metatool
 public | custom_mcp_servers | table | metatool
 public | mcp_servers        | table | metatool
 public | profiles           | table | metatool
 public | projects           | table | metatool
 public | tools              | table | metatool
(7 rows)

Suggestions for Improvement

  1. Add a healthcheck for PostgreSQL and make the migration container wait for it:
    services:
      postgres:
        # Existing config
        healthcheck:
          test: ["CMD-SHELL", "pg_isready -U metatool"]
          interval: 5s
          timeout: 5s
          retries: 5
      
      drizzle-migrate:
        # Existing config
        depends_on:
          postgres:
            condition: service_healthy
  2. Include the drizzle.config.ts file in the container's build process
  3. Add a check for React version compatibility issues in the package.json
  4. Consider adding a startup script that ensures migrations are applied correctly

Applying the Dockerfile modifications from issue #12 combined with the PostgreSQL healthcheck and migration script improvements suggested here would provide a more reliable installation experience.

Environment Information

  • Docker version: Docker Desktop 4.30.0
  • Operating System: macOS Ventura 13.5
  • Node.js version: 20.10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0