FROM ghcr.io/home-assistant/armhf-base-raspbian:bullseye
# Install requirements for add-on
RUN apt-get update && apt-get install -y \
nodejs \
npm \
liblivemedia-dev \
liblivemedia-dev \
liblog4cpp5-dev \
cmake \
libasound2-dev \
v4l-utils
# So let's set it to our add-on persistent data directory.
WORKDIR /data
# install onvif server
# install npm and node.js (latest 17 in 26.3.22)
RUN npm install -g n \
&& n install 17
RUN git clone https://github.com/BreeeZe/rpos.git \
&& cd rpos \
&& npm install
# So let's set it to our add-on persistent data/rpos directory.
WORKDIR /data/rpos
RUN npx gulp
#RUN npm install -g gulp
#RUN npm install gulp
# && sh setup_v4l2rtspserver.sh
# instal v4l2rtspserver
RUN git clone https://github.com/mpromonet/v4l2rtspserver.git \
&& cd v4l2rtspserver/ \
&& cmake . \
&& make \
&& make install
# Copy data for add-on
COPY rposConfig.json /data/rpos/
COPY run.sh /
RUN chmod a+x /run.sh
CMD ["/bin/sh","/run.sh"]
run.sh file:
#!/usr/bin/with-contenv bashio
echo "ONVIF server started"
cd /data/rpos
echo "go to directory /data/rpos"
/usr/local/bin/node /data/rpos/rpos.js
ERROR:
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module '/data/rpos/rpos.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v17.8.0
When I run image mannualy using command: docker run --rm -it --device /dev/video0 -p 8554:8554 --entrypoint bash image-name
and run command, rpos starts normaly without error: /bin/sh /run.sh
It actually doesnāt matter what the shebang line is, since you use the script as an argument of /bin/sh.
When you run your āmanualā command, you change the entrypoint so you are no longer in the context of s6 init. which is the original entrypoint. So when you use docker run without changing the entrypoint, your script is the parameter of /init, but when you overwrite the entrypoint, you just run the script in the shell.
Well spotted! The image also contains bashio (never heard of it before).
Since the image uses s6-overlay, you need to follow s6 convention.
If your service is not a āmain serviceā, you can put your script in \etc\cont-init.d\ as is.
If it is the main service, you will need to create two files to declare a service:
The file \etc\services.d\rpos\run could look smth like this (assuming your command creates a foreground process:
#!/usr/bin/with-contenv bashio
echo "$( date +'%Y/%m/%d %H:%M:%S' ) Starting Rpos"
cd /data/rpos
exec /usr/local/bin/node /data/rpos/rpos.js
and \etc\services.d\rpos\finish:
#!/usr/bin/execlineb -S1
if { s6-test ${1} -ne 0 }
if { s6-test ${1} -ne 256 }
s6-svscanctl -t /var/run/s6/services
Does rpos realy depend on Home Assistent or was it just a coincidental choice to use it as base image? If itās the second you might be better of to use a slimer base imageā¦
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
2022/03/28 21:13:25 Starting Rpos
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module '/data/rpos/rpos.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v17.8.0
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.
Here is latest docker file:
FROM ghcr.io/home-assistant/armhf-base-raspbian:bullseye
# Install requirements for add-on
RUN apt-get update && apt-get install -y \
nodejs \
npm \
liblivemedia-dev \
liblivemedia-dev \
liblog4cpp5-dev \
cmake \
libasound2-dev \
v4l-utils
# So let's set it to our add-on persistent data directory.
WORKDIR /data
# install onvif server
# install npm and node.js (latest 17 in 26.3.22)
RUN npm install -g n \
&& n install 17
RUN git clone https://github.com/BreeeZe/rpos.git \
&& cd rpos \
&& npm install
# So let's set it to our add-on persistent data/rpos directory.
WORKDIR /data/rpos
RUN npx gulp
# instal v4l2rtspserver
RUN git clone https://github.com/mpromonet/v4l2rtspserver.git \
&& cd v4l2rtspserver/ \
&& cmake . \
&& make \
&& make install
# Copy data for add-on
COPY run /etc/services.d/rpos/run
COPY finish /etc/services.d/rpos/finish
I try to manualy run command like this, and is working: docker run --rm -it --device /dev/video0 -p 8554:8554 --entrypoint /init f8a8ee9636e3
When I run as home assistant addona I get error:
[s6-init] making user provided files available at /var/run/s6/etc...exited 0.
[s6-init] ensuring user provided files have correct perms...exited 0.
[fix-attrs.d] applying ownership & permissions fixes...
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts...
[cont-init.d] done.
[services.d] starting services
[services.d] done.
2022/03/30 14:17:16 Starting Rpos
node:internal/modules/cjs/loader:936
throw err;
^
Error: Cannot find module '/data/rpos/rpos.js'
at Function.Module._resolveFilename (node:internal/modules/cjs/loader:933:15)
at Function.Module._load (node:internal/modules/cjs/loader:778:27)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
Node.js v17.8.0
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
[s6-finish] waiting for services.
[s6-finish] sending all processes the TERM signal.
Only difference is that I have in home assistant config.yaml file:
name: "Raspberry camera ONVIF server add-on"
description: "ONVIF server from raspberry pi camera"
version: "0.0.1a"
slug: "rpi-camera-rtsp-server-onvif"
arch:
- armhf
- armv7
ports:
8554/tcp: 8554
ports_description:
8554/tcp: Web interface (Not required for Ingress)
video: true
I canāt realy help you with homeassitent, rpos or nodejs in generall.
With the run and finish scripts you do follow the s6 overlay conventions and it should work if the commands in the run script are correct.
That is very interesting. Were you able to find out why that name was incompatible with your application? Is it possible that you had some non-printable character in the folder name or in the file path that you used in the Dockerfile so when you changed it, that character was also removed? Have you tried to change the name back manually without using any rollback functionality?
Since you solved it, itās fine if you donāt want to test it I just like to understand why things happen.