matrixgpt / matrix-chatgpt-bot

Talk to ChatGPT via any Matrix client!
GNU Affero General Public License v3.0
234 stars 63 forks source link

Will the container work on 32-bit Raspberry Pi OS (armv7 not arm64)? #103

Closed bendschs closed 1 year ago

bendschs commented 1 year ago

would this be working on a raspberry pi?

docker run -it -v storage:/storage --env-file=./.env --name matrix-chatgpt-bot ghcr.io/matrixgpt/matrix-chatgpt-bot:latest
Unable to find image 'ghcr.io/matrixgpt/matrix-chatgpt-bot:latest' locally
latest: Pulling from matrixgpt/matrix-chatgpt-bot
docker: no matching manifest for linux/arm/v7 in the manifest list entries.
See 'docker run --help'.
N3oTraX commented 1 year ago

Not sure if there is an armv7 image builded. I think only amd64.

max298 commented 1 year ago

Yeah, I think we only build amd64 and arm64.

I am not sure if the matrix-bot-sdk library will compile using armv7, I found it to be a bit picky, but you can try to build your own image by running the commands below

git clone git@github.com:waylaidwanderer/node-chatgpt-api.git
cd node-chatgpt-api
docker build -t local/chatbot .

If it builds just run the container using the container tag local/chatbot.

@bendschs maybe you can report if it works and if it does, I'd look into it adding an arm image to the workflow.

bertybuttface commented 1 year ago

would this be working on a raspberry pi?

docker run -it -v storage:/storage --env-file=./.env --name matrix-chatgpt-bot ghcr.io/matrixgpt/matrix-chatgpt-bot:latest
Unable to find image 'ghcr.io/matrixgpt/matrix-chatgpt-bot:latest' locally
latest: Pulling from matrixgpt/matrix-chatgpt-bot
docker: no matching manifest for linux/arm/v7 in the manifest list entries.
See 'docker run --help'.

Yes I use it on a Raspberry Pi. The Raspberry Pi 4 is arm64.

If you are using an older Raspberry Pi (3 or earlier) then you will run into issues with armv7 as discussed above. It is likely still possible but you will be building your own images.

bendschs commented 1 year ago

i am using an RPi 4 in 32-bit mode.

bertybuttface commented 1 year ago

Ok well switch to 64 bit mode and you can use the prebuilt images and your life will be much easier.

I'm not sure how much RAM your Pi has but remember 32 bit operating systems can only address some of it.

The Raspberry Pi 4 has been able to access the full 8GB of its memory despite running on a 32-bit operating system since launch, using the Arm Large Physical Address Extension (LPAE), but processes are limited to a maximum of 3GB of memory. Raspberry Pi reserves the top 1GB of the virtual address for the kernel.

bendschs commented 1 year ago

still on debian 10 and dependent on the 32-bit version since a part of the software i use runs only on 32-bit. 64-bit version has been still in beta till early february, right?

bertybuttface commented 1 year ago

Then you will have to try following the steps given by max298 above, would you kindly report back whether you made it work or not so we know what to tell others in future.

bendschs commented 1 year ago

surprisingly that seems to work, but it keeps looking for the settings.js file even though it's present in the root folder. does it have to be placed somewhere else?

 docker run local/chatbot

> @waylaidwanderer/chatgpt-api@1.12.2 start
> node bin/server.js

Error: the settings.js file does not exist.
bertybuttface commented 1 year ago

Ok so the ChatGPT part works, lets see if the whole lot works with Matrix too:

git clone git@github.com:matrixgpt/matrix-chatgpt-bot.git
cd matrix-chatgpt-bot
docker build -t matrix-chatgpt-bot .
docker run -it -v storage:/storage --env-file=./.env --name matrix-chatgpt-bot matrix-chatgpt-bot
bendschs commented 1 year ago

tried that already, it fails as follows:

docker build -t matrix-chatgpt-bot .
Sending build context to Docker daemon   6.26MB
Step 1/11 : FROM node:19-slim
 ---> 21d0ef50c414
Step 2/11 : WORKDIR /usr/src/app
 ---> Using cache
 ---> 0f6bf61aa42b
Step 3/11 : COPY package.json ./
 ---> Using cache
 ---> bded39168364
Step 4/11 : COPY yarn.lock ./
 ---> Using cache
 ---> a3447709e57b
Step 5/11 : RUN yarn install --frozen-lockfile --production && yarn cache clean
 ---> Running in 018d2a874b60
yarn install v1.22.19
[1/5] Validating package.json...
[2/5] Resolving packages...
[3/5] Fetching packages...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
[4/5] Linking dependencies...
[5/5] Building fresh packages...
error /usr/src/app/node_modules/sqlite3: Command failed.
Exit code: 1
Command: node-pre-gyp install --fallback-to-build
Arguments: 
Directory: /usr/src/app/node_modules/sqlite3
Output:
node-pre-gyp info it worked if it ends with ok
node-pre-gyp info using node-pre-gyp@1.0.10
node-pre-gyp info using node@19.6.0 | linux | arm
node-pre-gyp info check checked for "/usr/src/app/node_modules/sqlite3/lib/binding/napi-v6-linux-glibc-arm/node_sqlite3.node" (not found)
node-pre-gyp http GET https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.4/napi-v6-linux-glibc-arm.tar.gz
node-pre-gyp ERR! install response status 404 Not Found on https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.4/napi-v6-linux-glibc-arm.tar.gz 
node-pre-gyp WARN Pre-built binaries not installable for sqlite3@5.1.4 and node@19.6.0 (node-v111 ABI, glibc) (falling back to source compile with node-gyp) 
node-pre-gyp WARN Hit error response status 404 Not Found on https://github.com/TryGhost/node-sqlite3/releases/download/v5.1.4/napi-v6-linux-glibc-arm.tar.gz 
gyp info it worked if it ends with ok
gyp info using node-gyp@8.4.1
gyp info using node@19.6.0 | linux | arm
gyp info ok 
gyp info it worked if it ends with ok
gyp info using node-gyp@8.4.1
gyp info using node@19.6.0 | linux | arm
gyp ERR! find Python 
gyp ERR! find Python Python is not set from command line or npm configuration
gyp ERR! find Python Python is not set from environment variable PYTHON
gyp ERR! find Python checking if "python3" can be used
gyp ERR! find Python - "python3" is not in PATH or produced an error
gyp ERR! find Python checking if "python" can be used
gyp ERR! find Python - "python" is not in PATH or produced an error
gyp ERR! find Python 
gyp ERR! find Python **********************************************************
gyp ERR! find Python You need to install the latest version of Python.
gyp ERR! find Python Node-gyp should be able to find and use Python. If not,
gyp ERR! find Python you can try one of the following options:
gyp ERR! find Python - Use the switch --python="/path/to/pythonexecutable"
gyp ERR! find Python   (accepted by both node-gyp and npm)
gyp ERR! find Python - Set the environment variable PYTHON
gyp ERR! find Python - Set the npm configuration variable python:
gyp ERR! find Python   npm config set python "/path/to/pythonexecutable"
gyp ERR! find Python For more information consult the documentation at:
gyp ERR! find Python https://github.com/nodejs/node-gyp#installation
gyp ERR! find Python **********************************************************
gyp ERR! find Python 
gyp ERR! configure error 
gyp ERR! stack Error: Could not find any Python installation to use
gyp ERR! stack     at PythonFinder.fail (/usr/src/app/node_modules/node-gyp/lib/find-python.js:330:47)
gyp ERR! stack     at PythonFinder.runChecks (/usr/src/app/node_modules/node-gyp/lib/find-python.js:159:21)
gyp ERR! stack     at PythonFinder.<anonymous> (/usr/src/app/node_modules/node-gyp/lib/find-python.js:202:16)
gyp ERR! stack     at PythonFinder.execFileCallback (/usr/src/app/node_modules/node-gyp/lib/find-python.js:294:16)
gyp ERR! stack     at exithandler (node:child_process:427:5)
gyp ERR! stack     at ChildProcess.errorhandler (node:child_process:439:5)
gyp ERR! stack     at ChildProcess.emit (node:events:512:28)
gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:291:12)
gyp ERR! stack     at onErrorNT (node:internal/child_process:483:16)
gyp ERR! stack     at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
gyp ERR! System Linux 5.10.103-v7l+
gyp ERR! command "/usr/local/bin/node" "/usr/src/app/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/usr/src/app/node_modules/sqlite3/lib/binding/napi-v6-linux-glibc-arm/node_sqlite3.node" "--module_name=node_sqlite3" "--module_path=/usr/src/app/node_modules/sqlite3/lib/binding/napi-v6-linux-glibc-arm" "--napi_version=8" "--node_abi_napi=napi" "--napi_build_version=6" "--node_napi_label=napi-v6"
gyp ERR! cwd /usr/src/app/node_modules/sqlite3
gyp ERR! node -v v19.6.0
gyp ERR! node-gyp -v v8.4.1
gyp ERR! not ok 
node-pre-gyp ERR! build error 
node-pre-gyp ERR! stack Error: Failed to execute '/usr/local/bin/node /usr/src/app/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/src/app/node_modules/sqlite3/lib/binding/napi-v6-linux-glibc-arm/node_sqlite3.node --module_name=node_sqlite3 --module_path=/usr/src/app/node_modules/sqlite3/lib/binding/napi-v6-linux-glibc-arm --napi_version=8 --node_abi_napi=napi --napi_build_version=6 --node_napi_label=napi-v6' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/usr/src/app/node_modules/@mapbox/node-pre-gyp/lib/util/compile.js:89:23)
node-pre-gyp ERR! stack     at ChildProcess.emit (node:events:512:28)
node-pre-gyp ERR! stack     at maybeClose (node:internal/child_process:1098:16)
node-pre-gyp ERR! stack     at ChildProcess._handle.onexit (node:internal/child_process:304:5)
node-pre-gyp ERR! System Linux 5.10.103-v7l+
node-pre-gyp ERR! command "/usr/local/bin/node" "/usr/src/app/node_modules/sqlite3/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /usr/src/app/node_modules/sqlite3
node-pre-gyp ERR! node -v v19.6.0
node-pre-gyp ERR! node-pre-gyp -v v1.0.10
node-pre-gyp ERR! not ok 
Failed to execute '/usr/local/bin/node /usr/src/app/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/usr/src/app/node_modules/sqlite3/lib/binding/napi-v6-linux-glibc-arm/node_sqlite3.node --module_name=node_sqlite3 --module_path=/usr/src/app/node_modules/sqlite3/lib/binding/napi-v6-linux-glibc-arm --napi_version=8 --node_abi_napi=napi --napi_build_version=6 --node_napi_label=napi-v6' (1)
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
The command '/bin/sh -c yarn install --frozen-lockfile --production && yarn cache clean' returned a non-zero code: 1
bertybuttface commented 1 year ago

That's an issue with persistence not installing properly, you can try ripping out some of the Keyv persistence adapters (see package.json, make sure to regenerate yarn.lock when done). They aren't used by default.

bendschs commented 1 year ago

hm, that would be a bit of a stupid try and error since i have absolutely no idea which dependencies are needed and which not necessarily. i would rather wait for an arm 32-bit container or till i upgrade my system :).

anyway, thanx for you help!

mrPjer commented 1 year ago

Adding Python and build-essential (for make, and probably other things) to the container works.

# git diff
diff --git a/Dockerfile b/Dockerfile
index 7121075..278eee4 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -4,6 +4,7 @@ WORKDIR /usr/src/app

 COPY package.json ./
 COPY yarn.lock ./
+RUN apt-get update && apt-get install build-essential python3 -y
 RUN yarn install --frozen-lockfile --production && yarn cache clean

 COPY ./tsconfig.json ./tsconfig.json

Some dependencies need to be built for armv7, so these tools are necessary. Having a multi-step build would probably be the cleanest fix for this. Tested and working on armv7l.

Helikoptermann2 commented 1 year ago

hm, that would be a bit of a stupid try and error since i have absolutely no idea which dependencies are needed and which not necessarily. i would rather wait for an arm 32-bit container or till i upgrade my system :).

anyway, thanx for you help!

It's a bit unrelated but debian supports multiarch. so you can have a 32bit software running on the rpi4 64bit system. You only need to run dpkg --add-architecture armhf and then you can install 32bit software. Maybe this makes it easier to migrate to 64bit system :)

bendschs commented 1 year ago

hm, that would be a bit of a stupid try and error since i have absolutely no idea which dependencies are needed and which not necessarily. i would rather wait for an arm 32-bit container or till i upgrade my system :). anyway, thanx for you help!

It's a bit unrelated but debian supports multiarch. so you can have a 32bit software running on the rpi4 64bit system. You only need to run dpkg --add-architecture armhf and then you can install 32bit software. Maybe this makes it easier to migrate to 64bit system :)

thats good to know though, thank you!