julianpoy/RecipeSage-selfhost

TypeError: Cannot read properties of undefined (reading 'indexRecipes')

Closed this issue · 4 comments

Hello, I have the following error when running the api container, it runs for a fews seconds, spits out this error multiple times and restarts and errors again and so on:

TypeError: Cannot read properties of undefined (reading 'indexRecipes')
    at Object.<anonymous> (/app/packages/trpc/src/services/search/index.ts:28:44)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module.m._compile (/app/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Object.require.extensions.<computed> [as .ts] (/app/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Function.Module._load (node:internal/modules/cjs/loader:958:12)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (/app/packages/trpc/src/procedures/recipes/searchRecipes.ts:12:17)
/app/packages/trpc/src/services/search/index.ts:28
export const indexRecipes = searchProvider.indexRecipes;
                                           ^
TypeError: Cannot read properties of undefined (reading 'indexRecipes')
    at Object.<anonymous> (/app/packages/trpc/src/services/search/index.ts:28:44)
    at Module._compile (node:internal/modules/cjs/loader:1254:14)
    at Module.m._compile (/app/node_modules/ts-node/src/index.ts:1618:23)
    at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
    at Object.require.extensions.<computed> [as .ts] (/app/node_modules/ts-node/src/index.ts:1621:12)
    at Module.load (node:internal/modules/cjs/loader:1117:32)
    at Function.Module._load (node:internal/modules/cjs/loader:958:12)
    at Module.require (node:internal/modules/cjs/loader:1141:19)
    at require (node:internal/modules/cjs/helpers:110:18)
    at Object.<anonymous> (/app/packages/trpc/src/procedures/recipes/searchRecipes.ts:12:17)

I don't exactly run docker compose, I use just to run podman commands instead but I tried to make it equivalent. I also changed the container names and updated their names in the configurations.

set dotenv-load

all: rm network static typesense pushpin postgres browserless api proxy

rm:
    podman rm -f recipesage-api
    podman rm -f recipesage-proxy
    podman rm -f recipesage-browserless
    podman rm -f recipesage-postgres
    podman rm -f recipesage-pushpin
    podman rm -f recipesage-typesense
    podman rm -f recipesage-static

migrate:
    podman exec recipesage-api tsx packages/backend/src/migrate

network:
    podman network create --ignore recipesage
    podman network create --ignore recipesage-proxy

proxy:
    podman run -d --replace --tz local --pull newer \
        --name recipesage-proxy \
        --restart unless-stopped \
        --network recipesage-proxy \
        --network recipesage \
        -v ./nginx.conf:/etc/nginx/conf.d/default.conf:z \
        docker.io/nginx:1.25.2-alpine3.18-slim

static:
    podman run -d --replace --tz local --pull newer \
        --name recipesage-static \
        --restart unless-stopped \
        --network recipesage \
        -e API_BASE_OVERRIDE=null \
        -v ./static.entrypoint.sh:/docker-entrypoint.d/static.entrypoint.sh:z \
        docker.io/julianpoy/recipesage-selfhost:static-v2.11.5

typesense:
    podman run -d --replace --tz local --pull newer \
        --name recipesage-typesense \
        --restart unless-stopped \
        --network recipesage \
        -v ./typesensedata:/data:z \
        docker.io/typesense/typesense:0.24.1 --data-dir /data --api-key=recipesage_selfhost --enable-cors

pushpin:
    podman run -d --replace --tz local --pull newer \
        --name recipesage-pushpin \
        --restart unless-stopped \
        --network recipesage \
        -e target=api:3000 \
        docker.io/julianpoy/pushpin:2023-09-17

postgres:
    podman run -d --replace --tz local --pull newer \
        --name recipesage-postgres \
        --restart unless-stopped \
        --network recipesage \
        -e POSTGRES_DB=recipesage_selfhost \
        -e POSTGRES_USER=recipesage_selfhost \
        -e POSTGRES_PASSWORD=recipesage_selfhost \
        -v ./postgresdata:/var/lib/postgresql/data:z \
        docker.io/postgres:16

browserless:
    podman run -d --replace --tz local --pull newer \
        --name recipesage-browserless \
        --restart unless-stopped \
        --network recipesage \
        -e MAX_CONCURRENT_SESSIONS=3 \
        -e MAX_QUEUE_LENGTH=10 \
        docker.io/browserless/chrome:1.57-puppeteer-19.2.2

classifier:
    podman run -d --replace --tz local --pull newer \
        --name recipesage-classifier \
        --restart unless-stopped \
        --network recipesage \
        -e SENTENCE_EMBEDDING_BATCH_SIZE=200 \
        -e PREDICTION_CONCURRENCY=4 \
        docker.io/julianpoy/ingredient-instruction-classifier:1.4.9

api:
    podman run -d --replace --tz local --pull newer \
        --name recipesage-api \
        --restart unless-stopped \
        --network recipesage \
        --requires recipesage-postgres \
        --requires recipesage-typesense \
        --requires recipesage-pushpin \
        --requires recipesage-browserless \
        -e STORAGE_TYPE=filesystem \
        -e FILESYSTEM_STORAGE_PATH=/rs-media \
        -e NODE_ENV=selfhost \
        -e VERBOSE=false \
        -e VERSION=selfhost \
        -e POSTGRES_DB=recipesage_selfhost \
        -e POSTGRES_USER=recipesage_selfhost \
        -e POSTGRES_PASSWORD=recipesage_selfhost \
        -e POSTGRES_PORT=5432 \
        -e POSTGRES_HOST=recipesage-postgres \
        -e POSTGRES_SSL=false \
        -e POSTGRES_LOGGING=false \
        -e DATABASE_URL=postgresql://recipesage_selfhost:recipesage_selfhost@postgres:5432/recipesage_selfhost \
        -e GCM_KEYPAIR \
        -e SENTRY_DSN \
        -e GRIP_URL=http://recipesage-pushpin:5561/ \
        -e GRIP_KEY=390thgnroiepfh2g9ube2g9ru0eifgb29ryveu01bv9e0cn \
        -e SEARCH_PROVIDER=recipesage-typesense \
        -e 'TYPESENSE_NODES=[{"host": "recipesage-typesense", "port": 8108, "protocol": "http"}]' \
        -e TYPESENSE_API_KEY=recipesage_selfhost \
        -e STRIPE_SK \
        -e STRIPE_WEBHOOK_SECRET \
        -e BROWSERLESS_HOST=recipesage-browserless \
        -e BROWSERLESS_PORT=3000 \
        -e INGREDIENT_INSTRUCTION_CLASSIFIER_URL=http://recipesage-classifier:3000/ \
        -v ./apimedia:/rs-media:z \
        docker.io/julianpoy/recipesage-selfhost:api-v2.11.5 \
        npx ts-node --swc --project packages/backend/tsconfig.json packages/backend/src/bin/www

nginx.conf :

server {
  client_max_body_size 1G;

	listen 80;

	server_name localhost;

  location /grip/ws {
    resolver 127.0.0.11 valid=30s;

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_connect_timeout 1h;
    proxy_send_timeout 1h;
    proxy_read_timeout 1h;
    proxy_pass http://recipesage-pushpin:7999/ws;
  }

  location /api/ {
    resolver 127.0.0.11 valid=30s;
    proxy_pass http://recipesage-api:3000/;
  }

  location / {
  resolver 127.0.0.11 valid=30s;
  proxy_pass http://recipesage-static:80/;
  }
}

I feel like I'll have to actually attempt to reproduce this in podman (I'm not very familiar with it) but from a short glance, it almost looks like the container didn't mount the file system. If I have time in the next day or so I'll look to getting podman running in a dev box and see if your config works (or doesn't) for me.
One question though: are you hosting on x86_64, ARM, or something else?

This is on x86_64, I will look into the file mounting issue. Also I am running podman as rootless and it's quite common to run into permission issues when a container is expected to be rootful (most cases for docker). If a container uses a $USER different than root (which maps to my own $USER on the host system) then the container might not be able to write to the shared container.
I tried not mounting the containers, mounting them to virtual volumes or change the permission to the mounted volumes but it still didn't work. If you have suggestions to debug this situation I could try them.

Hey there! The environment variable SEARCH_PROVIDER must be set to one of elasticsearch, meilisearch, typesense, or none. I see in your configs posted above it's set to recipesage-typesense.

Ah yes, that works! I was confused and thought I had to put the typesense host. Thanks.