Skip to content

Commit 69ec899

Browse files
committed
fix: add linker to be able to use .node module
Signed-off-by: wilmardo <[email protected]>
1 parent 810e456 commit 69ec899

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

DEV_NOTES.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
```
2+
# Static compile bindings
3+
WORKDIR /zigbee2mqtt/node_modules/zigbee-herdsman/node_modules/@serialport/bindings
4+
RUN sed -i "s/'target_name': 'bindings',/&\n 'type': 'static_library',/" binding.gyp && \
5+
node-gyp clean && \
6+
node-gyp configure && \
7+
node-gyp build
8+
```
9+
Results in a nice static /zigbee2mqtt/node_modules/zigbee-herdsman/node_modules/@serialport/bindings/build/Release/bindings.a

Dockerfile

+7-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ RUN CORES=$(grep -c '^processor' /proc/cpuinfo); \
3535
export MAKEFLAGS="-j$((CORES+1)) -l${CORES}"; \
3636
npm install --unsafe-perm
3737

38+
WORKDIR /zigbee2mqtt
3839
RUN nexe --build --target alpine --output zigbee2mqtt
3940

4041
FROM scratch
@@ -48,11 +49,15 @@ COPY --from=builder /etc_passwd /etc/passwd
4849
# Serialport is using the udevadm binary
4950
COPY --from=builder /bin/udevadm /bin/udevadm
5051

51-
# Copy needed libs for nodejs since it is partially static
52+
# Copy needed libs(libstdc++.so, libgcc_s.so) for nodejs since it is partially static
53+
# Copy linker to be able to use them (lib/ld-musl)
54+
# Can't be fullly static since @serialport uses a C++ node addon
55+
# https://github.com/serialport/node-serialport/blob/master/packages/bindings/lib/linux.js#L2
5256
COPY --from=builder \
57+
/lib/ld-musl-*.so.* \
5358
/usr/lib/libstdc++.so.* \
5459
/usr/lib/libgcc_s.so.* \
55-
/usr/lib/
60+
/lib/
5661

5762
# Copy zigbee2mqtt binary
5863
COPY --from=builder /zigbee2mqtt/zigbee2mqtt /zigbee2mqtt/zigbee2mqtt

0 commit comments

Comments
 (0)