binsentsu / am43-ctrl

Node Util for controlling an AM43 Blinds Drive Cover, either over MQTT or via a HTTP API
44 stars 25 forks source link

Docker? Anyone? #26

Open arthurd2 opened 3 years ago

arthurd2 commented 3 years ago

Hey guys, first of all: THANK YOU! Amazing job you did there.

Second: did you guys try to pack everything inside a Docker image? I've try with the node7 image but I had some problems with libusb... I'm still trying though....

arthurd2 commented 3 years ago

Oops, just did! It's not an optimal solution, but it works:

FROM node:12.20.1-stretch
ENV MAC=XXXXX
ENTRYPOINT  ./am43ctrl $MAC -l 3000
EXPOSE 3000

WORKDIR /app
RUN npm  install https://github.com/binsentsu/am43-ctrl
WORKDIR /app/node_modules/.bin/

Running commandi would be: docker run -ti --net=host --privileged -p 3000 -e MAC=YYYY am43

bjoernwolter commented 3 years ago

Here is my solution with docker You have to provide the different "ENV" via -e params


FROM node:12-alpine
ENV LANG C.UTF-8
ENV NODE_ENV production`

RUN apk add --no-cache git npm python3 linux-headers eudev-dev make libusb-dev gcc g++ bash
RUN npm install https://github.com/binsentsu/am43-ctrl
RUN apk del make libusb-dev python3 gcc g++ git linux-headers eudev-dev
RUN rm -r /root/.npm

WORKDIR node_modules/.bin/

ENV URL=""
ENV MAC1=""
ENV MQTTUSER=""
ENV MQTTPWD=""
ENTRYPOINT ./am43ctrl ${MAC1} --url ${URL} -u ${MQTTUSER} -p ${MQTTPWD}´´´
arthurd2 commented 3 years ago

Great one, the image shrank from 900MB to 440MB. I took your example and added a PORT ENV, changed the ENTRYPOINT and merged the RUN commands. After merging the RUNs the image shrank to 150MB. =D


FROM node:12-alpine
ENV LANG C.UTF-8
ENV NODE_ENV production`
ENV URL="mqtt://192.168.0.2"
ENV MAC1="XXXXXXXXXX"
ENV MQTTUSER="mqtt"
ENV PORT="3000"
ENV MQTTPWD="mqttpass"

ENTRYPOINT ./am43ctrl ${MAC1} --url ${URL} -l ${PORT} -u ${MQTTUSER} -p ${MQTTPWD}

RUN apk add --no-cache git npm python3 linux-headers eudev-dev make libusb-dev gcc g++ bash ;\
    npm install https://github.com/binsentsu/am43-ctrl ;\
    apk del make libusb-dev python3 gcc g++ git linux-headers eudev-dev ;\
    rm -r /root/.npm

WORKDIR node_modules/.bin/
JochenKlenk commented 3 years ago

If I set up a docke rwith above command I just get

/node_modules/@abandonware/noble/lib/hci-socket/hci.js:80 this._socket = new BluetoothHciSocket(); ^ Error: EAFNOSUPPORT, Address family not supported by protocol at new Hci (/node_modules/@abandonware/noble/lib/hci-socket/hci.js:80:18) at new NobleBindings (/node_modules/@abandonware/noble/lib/hci-socket/bindings.js:25:15) at module.exports (/node_modules/@abandonware/noble/lib/resolve-bindings.js:13:12) at Object. (/node_modules/@abandonware/noble/index.js:2:51) at Module._compile (internal/modules/cjs/loader.js:999:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10) at Module.load (internal/modules/cjs/loader.js:863:32) at Function.Module._load (internal/modules/cjs/loader.js:708:14) at Module.require (internal/modules/cjs/loader.js:887:19) at require (internal/modules/cjs/helpers.js:74:18) {  errno: 97, code: 'EAFNOSUPPORT', syscall: 'socket' }

Can Someone help here.

Thanks

arthurd2 commented 3 years ago

I had the same problem. But I don't remember if I fixed it by enabling the bluetooth (it was down, in airplane mode) or I've installed the bluez package.