Luligu / matterbridge

Matterbridge plugin manager for Matter
https://github.com/Luligu/matterbridge/blob/main/README.md
Apache License 2.0
125 stars 13 forks source link

Configuration of globalModulesDirectory is not timed properly #37

Closed t0bst4r closed 1 month ago

t0bst4r commented 1 month ago

The matterbridge -add commands expects globalModulesDirectory to be already set when adding a new plugin. This blocks adding plugins before starting the bridge for the first time.

I am currently building an alpine docker image using my newly created matterbridge-home-assistant plugin. Therefore I want to install and add the plugin before starting the bridge.

At the moment I have two options to solve this:

  1. run timeout 5s matterbridge -bridge during the docker build process. This starts the bridge and creates all the storage files. After 5 seconds it gets killed. Then the globalModulesDirectory is available.

  2. Create the storage entry by hand using

    RUN mkdir -p /root/.matterbridge/storage/.matterbridge
    RUN echo '{"key":"globalModulesDirectory","value":"/usr/local/lib/node_modules"}' > /root/.matterbridge/storage/.matterbridge/d01917a070027b55bce538a96fa2004f061de6fe1644f402a321c6db8c71b9ba

Instead matterbridge should be able to add plugins before starting for the first time. This will probably implicitly work, when the globalModulesDirectory is determined correctly. For me it looks like having an await here could already fix the problem.

Luligu commented 1 month ago

Hi, is actually made on purpose to speed up the loading. It's clear that if you want to run matterbride building the docker image, it doesn't work for you. I could add some param like -build to solve it eventually... but there are other part of the startup where I intentionally don't await. I'm interested in the docker image with alpine. I tried a lot of time but the best I could make was: FROM alpine:3.18.4 as base

FROM alpine:latest as base not working

FROM node:20-alpine as base not working

Then actually takes 30 minutes to build on all the archs: linux/amd64,linux/arm64,linux/arm/v7 Also just have node 18 so ... not really the best. Were you been able to do better with alpine? Can you share the link of your Docker file if you made better ?

Luligu commented 1 month ago

I opened a discussion since is not an issue making a HA integration. https://github.com/Luligu/matterbridge/discussions/39

t0bst4r commented 1 month ago

Boot speed and storage init

Maybe we don’t need a -build option, but an -init option. That would be more understandable, isn’t it?

Alpine

Here is the dockerfile: https://github.com/t0bst4r/matterbridge-home-assistant-addon/blob/main/docker/Dockerfile

It’s still WIP, and as you see it’s also using node-18. I‘ve had the same issue and several other people, too.

Quote from Home Assistant:

Main reason for this, is because in Alpine 3.19 shipped with NodeJS v20, which, at the time of writing, could not be used on armv7 when building Docker images. This is caused by a QEMU bug, which has been known since 2020.

Luligu commented 1 month ago

Can we move on the discussion ?