33# ######################################################################################################################
44FROM lansible/nexe:4.0.0-beta.19 as builder
55
6- ENV VERSION=v6.6.2
6+ # https://github.com/docker/buildx#building-multi-platform-images
7+ ARG TARGETPLATFORM
8+ ENV VERSION=v6.7.1
79
810# Add unprivileged user
911RUN echo "zwavejs2mqtt:x:1000:1000:zwavejs2mqtt:/:" > /etc_passwd
@@ -27,10 +29,19 @@ RUN git apply stateless.patch
2729# Run build to make all html files
2830RUN CORES=$(grep -c '^processor' /proc/cpuinfo); \
2931 export MAKEFLAGS="-j$((CORES+1)) -l${CORES}" ; \
30- npm install --legacy-peer-deps && \
32+ npm install && \
3133 npm run build && \
3234 npm prune --production
3335
36+ # Remove all unneeded prebuilds
37+ RUN if [ "$TARGETPLATFORM" = "linux/amd64" ]; then \
38+ export TARGETPLATFORM="linux/x64" ; \
39+ fi && \
40+ export PLATFORM=${TARGETPLATFORM/\/ /-}; \
41+ echo ${PLATFORM} > platform; \
42+ find . -name *.node -path *prebuilds/* -not -path *${PLATFORM}* -name *.node -delete && \
43+ find . -name *.glibc.node -path *prebuilds/* -delete
44+
3445WORKDIR /zwavejs2mqtt/server
3546
3647# See: https://github.com/nexe/nexe/issues/441#issuecomment-359654690
@@ -58,9 +69,12 @@ LABEL org.label-schema.description="Zwavejs2mqtt as single binary in a scratch c
5869# Set env vars for persistance
5970# https://github.com/zwave-js/zwavejs2mqtt/blob/master/docs/guide/env-vars.md
6071# SETTINGS_FILE is from the stateless.patch
72+ # LIBC is set for prebuilify (node-gyp-build) to pickup the bindings file from serialport:
73+ # https://github.com/prebuild/node-gyp-build/blob/2e982977240368f8baed3975a0f3b048999af40e/index.js#L15
6174ENV STORE_DIR=/data/ \
6275 ZWAVEJS_EXTERNAL_CONFIG=/data/zwavejs \
63- SETTINGS_FILE=/config/settings.json
76+ SETTINGS_FILE=/config/settings.json \
77+ LIBC=musl
6478
6579# Copy the unprivileged user
6680COPY --from=builder /etc_passwd /etc/passwd
@@ -84,18 +98,8 @@ COPY --from=builder /zwavejs2mqtt/server/zwavejs2mqtt /zwavejs2mqtt/bin/zwavejs2
8498
8599# Add bindings.node for serialport
86100COPY --from=builder \
87- /zwavejs2mqtt/node_modules/@serialport/bindings/build/Release/bindings.node \
88- /zwavejs2mqtt/build/bindings.node
89-
90- # Add files needed, doesn't work as --resource
91- COPY --from=builder \
92- /zwavejs2mqtt/node_modules/@serialport/bindings/lib/linux.js \
93- /zwavejs2mqtt/node_modules/@serialport/bindings/lib/linux.js
94-
95- # https://github.com/zwave-js/node-zwave-js/tree/master/packages/config/config
96- COPY --from=builder \
97- /zwavejs2mqtt/node_modules/@zwave-js/config/config/ \
98- /zwavejs2mqtt/node_modules/@zwave-js/config/config/
101+ /zwavejs2mqtt/node_modules/@serialport/bindings-cpp/prebuilds/ \
102+ /zwavejs2mqtt/node_modules/@serialport/bindings-cpp/prebuilds/
99103
100104# After troubleshooting this somehow can't be packed
101105COPY --from=builder \
0 commit comments