Repository: promptfoo/promptfoo
Issue: Not able to run eval locally using docker
Root cause: External Dependency Breakage

**Describe the bug**
A clear and concise description of what the bug is.

**To Reproduce**
Steps to reproduce the behavior, including example Promptfoo configurations if applicable:

Running in local using docker.
```
docker run -d --name promptfoo_container -p 3000:3000 -v /add_bins/promptfoo:/root/.promptfoo -e OPENAI_API_KEY=sk-xxxxxx -e PROMPTFOO_CONFIG_DIR=~/.promptfoo promptfoo-ui
```

**Expected behavior**
A clear and concise description of what you expected to happen.

**Screenshots**
```
Writing environment variables to .env file...
2024-07-30 23:49:09 Loaded environment variables:
2024-07-30 23:49:09 NODE_VERSION=20.16.0
2024-07-30 23:49:09 HOSTNAME=0.0.0.0
2024-07-30 23:49:09 YARN_VERSION=1.22.22
2024-07-30 23:49:09 SHLVL=2
2024-07-30 23:49:09 PORT=3000
2024-07-30 23:49:09 HOME=/home/nextjs
2024-07-30 23:49:09 OPENAI_API_KEY=sk-xxxxx
2024-07-30 23:49:09 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
2024-07-30 23:49:09 NEXT_TELEMETRY_DISABLED=1
2024-07-30 23:49:09 PROMPTFOO_CONFIG_DIR=~/.promptfoo
2024-07-30 23:49:09 PWD=/app
2024-07-30 23:49:09 Starting server...
2024-07-30 23:49:09 - ready started server on 0.0.0.0:3000, url: http://localhost:3000
2024-07-30 23:49:09 - info Loaded env from /app/src/web/nextui/.env
2024-07-30 23:49:09 - info Loaded env from /app/src/web/nextui/.env
2024-07-30 23:49:09 Listening on port 3000 url: http://0.0.0.0:3000
2024-07-30 23:49:33 Anonymous telemetry is enabled. For more info, see https://www.promptfoo.dev/docs/configuration/telemetry
2024-07-30 23:49:33 Creating cache folder at ~/.promptfoo/cache.
2024-07-30 23:50:53 [45f965da-704c-4131-98d2-b2b0c8a7eda4] 1/6
2024-07-30 23:50:56 [45f965da-704c-4131-98d2-b2b0c8a7eda4] 2/6
2024-07-30 23:50:59 [45f965da-704c-4131-98d2-b2b0c8a7eda4] 3/6
2024-07-30 23:51:00 [45f965da-704c-4131-98d2-b2b0c8a7eda4] 4/6
2024-07-30 23:52:16 [45f965da-704c-4131-98d2-b2b0c8a7eda4] 5/6
2024-07-30 23:52:18 [45f965da-704c-4131-98d2-b2b0c8a7eda4] 6/6
2024-07-30 23:52:18 Error running database migrations: Error relocating /app/node_modules/better-sqlite3/build/Release/better_sqlite3.node: unsupported relocation type 7
2024-07-30 23:52:18 Error: Error relocating /app/node_modules/better-sqlite3/build/Release/better_sqlite3.node: unsupported relocation type 7
2024-07-30 23:52:18     at Module._extensions..node (node:internal/modules/cjs/loader:1454:18)
2024-07-30 23:52:18     at Module.load (node:internal/modules/cjs/loader:1208:32)
2024-07-30 23:52:18     at Module._load (node:internal/modules/cjs/loader:1024:12)
2024-07-30 23:52:18     at Module.require (node:internal/modules/cjs/loader:1233:19)
2024-07-30 23:52:18     at require (node:internal/modules/helpers:179:18)
2024-07-30 23:52:18     at bindings (/app/node_modules/bindings/bindings.js:112:48)
2024-07-30 23:52:18     at new Database (/app/node_modules/better-sqlite3/lib/database.js:48:64)
2024-07-30 23:52:18     at getDb (/app/src/web/nextui/.next/server/chunks/6423.js:67:24)
2024-07-30 23:52:18     at writeResultsToDatabase (/app/src/web/nextui/.next/server/chunks/6423.js:1615:42)
2024-07-30 23:52:18     at Object.index_evaluate [as evaluate] (/app/src/web/nextui/.next/server/app/api/eval/job/route.js:10279:63) {
2024-07-30 23:52:18   code: 'ERR_DLOPEN_FAILED'
2024-07-30 23:52:18 }

```

**System information (please complete the following information):**

- Promptfoo version: latest 

**Additional context**
Add any other context about the problem here.


promptfooconfig.yaml
```
# Learn more about building a configuration: https://promptfoo.dev/docs/configuration/guide
description: "My eval"

prompts:
  - "Write a tweet about {{topic}}"
  - "Write a concise, funny tweet about {{topic}}"


providers:
  - "openai:gpt-3.5-turbo"
  - "openai:gpt-4o"


tests:
  - vars:
      topic: bananas

  - vars:
      topic: avocado toast
    assert:
      # For more information on assertions, see https://promptfoo.dev/docs/configuration/expected-outputs

      # Make sure output contains the word "avocado"
      - type: icontains
        value: avocado

      # Prefer shorter outputs
      - type: javascript
        value: 1 / (output.length + 1)

  - vars:
      topic: new york city
    assert:
      # For more information on model-graded evals, see https://promptfoo.dev/docs/configuration/expected-outputs/model-graded
      - type: llm-rubric
        value: ensure that the output is funny
```


@dmockingbird551 Could you provide a commit hash of your current prompt foo repo via `git rev-parse --short HEAD` and the command you are using to build the container?

@cmrfrd I can reproduce this behavior on the main branch (on an M1 Mac). It seems like it might be related to the system architecture (arm64 vs. amd64). I would love help if you have time to debug this. Thank you! 

@cmrfrd I used the main branch on M1 mac as pointed out by @mldangelo 
`docker build --build-arg NEXT_PUBLIC_PROMPTFOO_BASE_URL=http://localhost:3000 -t promptfoo-ui .`

@mldangelo  I'll try to take a look.

> @cmrfrd I used the main branch on M1 mac as pointed out by @mldangelo `docker build --build-arg NEXT_PUBLIC_PROMPTFOO_BASE_URL=http://localhost:3000 -t promptfoo-ui .`
> 
> @mldangelo I'll try to take a look.

Interesting, yea I was not able to reproduce this on my linux amd64 machine. I will try on mac.

> > @cmrfrd I used the main branch on M1 mac as pointed out by @mldangelo `docker build --build-arg NEXT_PUBLIC_PROMPTFOO_BASE_URL=http://localhost:3000 -t promptfoo-ui .`
> > @mldangelo I'll try to take a look.
> 
> Interesting, yea I was not able to reproduce this on my linux amd64 machine. I will try on mac.

I was able to reproduce the problem on mac, and traced upstream a similarly reported problem in `better-sqlite` here:

https://github.com/WiseLibs/better-sqlite3/issues/146#issuecomment-1907490076

following their solution and running `npm run build-release` in `node_modules/better-sqlite` fixed the problem for me, however I effectively had to recompile the bindings which is a pretty big kludge to include in the dockerfile as I doubt it's a stable fix.

@mldangelo I see a few ways forward:
1. Include the kludge (build better-sqlite in the Dockerfile) and make it as stable as possible.
2. Use an alternative to `better-sqlite`.
3. Fix `better-sqlite` upstream.

what do you think?

Hi @cmrfrd! Thanks so much for investigating this issue and finding a workaround. I agree with your assessment—let's implement solution 1 for now to ensure we can release promptly. Hopefully, the maintainers will address the root cause (solution 3), or we can explore alternative solutions like switching from better-sqlite.

Would you mind adding those four lines to the Dockerfile and opening a PR? Thanks again for your help!

@mldangelo #1344 . Few more then four lines 😉 

Thank you so much @cmrfrd!!! 🎆 🎉 💯 🥇