Prn-Ice / medusa-docker

Spin up a full medusa store with docker.
29 stars 18 forks source link

Medusa backend doesn't start (even after heavy modifications) #19

Open TrezOne opened 6 months ago

TrezOne commented 6 months ago

Subject says it all. The other containers seem to spin up fine up until trying to access the storefront or seeding data (this is the installation guide I've been following thus far). Please see below for the error message, docker-compose.yml entries, and modifications.

Dockerfile modifications

Change node version from node:17.1.0-alpine to node:18-alpine3.18 in the Dockerfiles for admin, backend, and storefront.

Error message from backend

{
   "level": "error",
   "message": "Error starting server",
   "stack": [
      {
         "columnNumber": 15,
         "fileName": "node:internal/modules/cjs/loader",
         "functionName": "Module._resolveFilename",
         "lineNumber": 933,
         "methodName": "_resolveFilename",
         "native": false,
         "typeName": "Function"
      },
      {
         "columnNumber": 27,
         "fileName": "node:internal/modules/cjs/loader",
         "functionName": "Module._load",
         "lineNumber": 778,
         "methodName": "_load",
         "native": false,
         "typeName": "Function"
      },
      {
         "columnNumber": 19,
         "fileName": "node:internal/modules/cjs/loader",
         "functionName": "Module.require",
         "lineNumber": 999,
         "methodName": "require",
         "native": false,
         "typeName": "Module"
      },
      {
         "columnNumber": 18,
         "fileName": "node:internal/modules/cjs/helpers",
         "functionName": "require",
         "lineNumber": 102,
         "methodName": null,
         "native": false,
         "typeName": null
      },
      {
         "columnNumber": 117,
         "fileName": "/app/medusa/node_modules/@medusajs/medusa/dist/loaders/index.js",
         "functionName": null,
         "lineNumber": 157,
         "methodName": null,
         "native": false,
         "typeName": null
      },
      {
         "columnNumber": 5,
         "fileName": "node:internal/process/task_queues",
         "functionName": "processTicksAndRejections",
         "lineNumber": 96,
         "methodName": null,
         "native": false,
         "typeName": null
      }
   ],
   "timestamp": "2024-05-14 15:20:51"
}

Error when trying to seed the database with dummy info

docker exec medusajs-server medusa seed -f ./data/seed.json 
TypeError: typeorm_1.DataSource is not a constructor
    at /app/medusa/node_modules/@medusajs/medusa/dist/commands/seed.js:137:34
    at step (/app/medusa/node_modules/@medusajs/medusa/dist/commands/seed.js:67:23)
    at Object.next (/app/medusa/node_modules/@medusajs/medusa/dist/commands/seed.js:48:53)
    at /app/medusa/node_modules/@medusajs/medusa/dist/commands/seed.js:42:71
    at new Promise (<anonymous>)
    at __awaiter (/app/medusa/node_modules/@medusajs/medusa/dist/commands/seed.js:38:12)
    at seed (/app/medusa/node_modules/@medusajs/medusa/dist/commands/seed.js:103:12)
    at /usr/local/share/.config/yarn/global/node_modules/@medusajs/medusa-cli/dist/create-cli.js:138:20
    at /usr/local/share/.config/yarn/global/node_modules/@medusajs/medusa-cli/dist/create-cli.js:48:30
    at Object.handler (/usr/local/share/.config/yarn/global/node_modules/@medusajs/medusa-cli/dist/create-cli.js:16:21)

docker-compose.yml snippet (ignore the labels unless you're running a similar setup; my own customizations)

  medusajs-admin:
    build:
      context: ${DOCKERCONFDIR}/medusajs/admin
      dockerfile: Dockerfile
    image: admin:latest
    container_name: medusajs-admin
    hostname: admin
    restart: always
    depends_on:
      - medusajs-backend
    environment:
      MEDUSA_BACKEND_URL: http://medusajs-backend:9000
      NODE_OPTIONS: --openssl-legacy-provider
    ports:
      - "7700:7700"
    labels:
      - swag=enable
      - swag_proto=http
      - swag_url=ecom.example.com
      - swag.uptime-kuma.enabled=true
      - swag.uptime-kuma.monitor.url=https://ecom.example.com
      - homepage.group=Professional Services
      - homepage.name=Medusa (Admin)
      - homepage.href=https://ecom.example.com
      - homepage.icon=/icons/medusajs.png
      - homepage.description=Medusa (Admin)
  medusajs-backend:
    build:
      dockerfile: Dockerfile
      context: ${DOCKERCONFDIR}/medusajs/backend
    image: backend:latest
    container_name: medusajs-server
    hostname: backend
    restart: always
    depends_on:
      - medusajs-pg
      - medusajs-redis
      - minio
    volumes:
      - ${DOCKERCONFDIR}/medusajs/backend:/app/medusa
      - medusajs_backend_node_modules:/app/medusa/node_modules
    environment:
      COOKIE_SECRET: ${MEDUSAJS_COOKIE_SECRET}
      DATABASE_URL: postgres://medusa:${MEDUSAJS_POSTGRES_PASSWORD}@medusajs-pg:5432/medusajs
      JWT_SECRET: ${MEDUSAJS_JWT_TOKEN}
      NODE_ENV: production
      REDIS_URL: redis://medusajs-redis
      MINIO_ENDPOINT: http://minio:9000
      MINIO_BUCKET: medusajs
      MINIO_ACCESS_KEY: ${MEDUSAJS_S3_ACCESS_KEY}
      MINIO_SECRET_KEY: ${MEDUSAJS_S3_SECRET_KEY}
    ports:
      - 9002:9000
  medusajs-pg:
    image: postgres:10.4-alpine
    container_name: medusajs-pg
    expose:
      - 5432
    restart: always
    healthcheck:
      test: [ "CMD-SHELL", "pg_isready -U postgres" ]
      interval: 5s
      timeout: 5s
      retries: 5
    environment:
      POSTGRES_USER: medusa
      POSTGRES_PASSWORD: ${MEDUSAJS_POSTGRES_PASSWORD}
      POSTGRES_DB: medusajs
    volumes:
      - medusajs_postgres_data:/var/lib/postgresql/data
  medusajs-redis:
    image: redis:7.0.7-alpine
    container_name: medusajs-redis
    hostname: cache
    restart: always
    expose:
      - 6379
    volumes:
      - medusajs_redis_data:/data
  medusajs-storefront:
    build:
      context: ${DOCKERCONFDIR}/medusajs/storefront
      dockerfile: Dockerfile
    image: storefront:latest
    container_name: medusa-storefront
    hostname: storefront
    restart: always
    depends_on:
      - medusajs-backend
    ports:
      - 8100:8100
    volumes:
      - ${DOCKERCONFDIR}/medusajs/storefront:/app/storefront
      - medusajs_storefront_node_modules:/app/storefront/node_modules
    labels:
      - swag=enable
      - swag_proto=http
      - swag_port=8100
      - swag_url=store.example.com
      - swag.uptime-kuma.enabled=true
      - swag.uptime-kuma.monitor.url=https://store.example.com
      - homepage.group=Professional Services
      - homepage.name=Medusa (Store)
      - homepage.href=https://store.example.com
      - homepage.icon=/icons/medusajs.png
      - homepage.description=Medusa (Storefront)
  minio:
    image: minio/minio
    hostname: minio
    container_name: minio
    command: 'server --console-address ":9090" /mnt/data'
    environment:
      - MINIO_ROOT_USER=minioadmin
      - MINIO_ROOT_PASSWORD=${MINIO_ROOT_PASSWORD}
      - MINIO_ACCESS_KEY=${MINIO_MIMIR_STORAGE_ACCESS_KEY}
      - MINIO_SECRET_KEY=${MINIO_MIMIR_STORAGE_SECRET_KEY}
    ports:
      - 9001:9000
      - 9092:9090
    volumes:
      - ${DOCKERCONFDIR}/minio/data:/mnt/data
      - ${DOCKERCONFDIR}/minio/minio:/etc/config.env
    restart: unless-stopped
    labels:
      - swag=enable
      - swag_proto=http
      - swag_port=9090
      - swag_url=s3.example.com
      - swag.uptime-kuma.enabled=true
      - swag.uptime-kuma.monitor.url=https://s3.example.com
      - homepage.group=System Administration
      - homepage.name=MinIO
      - homepage.href=https://s3.example.com
      - homepage.icon=minio.png
      - homepage.description=S3-compatible storage backend

volumes:
  medusajs_storefront_node_modules:
  medusajs_backend_node_modules:
  medusajs_postgres_data:
  medusajs_redis_data:
TrezOne commented 6 months ago

@liangjaden @Peter-Spi @Dalvae @SalcidoJesus @Ziance might be of some use to you lot 😊