diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 00000000..d0b39dcc --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.git +.github +*.md +docs +.vscode +.nyc_output +.coverage +pkg +test \ No newline at end of file diff --git a/.github/workflows/dockerbuild.yml b/.github/workflows/dockerbuild.yml index ddd2754f..be4c3d7e 100644 --- a/.github/workflows/dockerbuild.yml +++ b/.github/workflows/dockerbuild.yml @@ -1,16 +1,50 @@ -name: Trigger Docker Build +name: Docker Build on: push: - branches: - - 'master' + branches: + - master + pull_request: + release: + types: + - created + jobs: build: runs-on: ubuntu-latest steps: - - name: Repository Dispatch - uses: peter-evans/repository-dispatch@v1 - with: - token: ${{ secrets.DOCKER_REPO_TOKEN }} - repository: robertsLando/Zwave2Mqtt-docker - event-type: build + - uses: actions/checkout@v2 + + - name: Just build on PR + if: ${{ github.event_name == 'pull_request' }} + run: docker build . + + - name: Login to dockerhub + if: ${{ github.event_name != 'pull_request' }} + run: | + docker login --username $DOCKER_USERNAME --password $DOCKER_PASSWORD + env: + DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }} + DOCKER_PASSWORD: ${{ secrets.DOCKER_PASSWORD }} + + - uses: crazy-max/ghaction-docker-buildx@v1 + if: ${{ github.event_name != 'pull_request' }} + + - name: Dev + if: ${{ github.ref == 'git/refs/heads/master'}} + run: | + docker buildx build \ + --platform linux/arm64/v8,linux/amd64,linux/arm/v6,linux/arm/v7,linux/386 \ + -t openzwave/zwave2mqtt:latest \ + --push \ + . + + - name: Latest & tag + if: ${{ github.event_name == 'release' }} + run: | + docker buildx build \ + --platform linux/arm64/v8,linux/amd64,linux/arm/v6,linux/arm/v7,linux/386 \ + -t openzwave/zwave2mqtt:$(echo ${GITHUB_REF} | sed "s/git\/refs\/tags\/v//") \ + -t openzwave/zwave2mqtt:latest \ + --push \ + . diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..48024e73 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,66 @@ +# ---------------- +# STEP 1: +FROM node:erbium-alpine AS build + +ARG OPENZWAVE_GIT_SHA1=master + +# Install required dependencies +RUN apk --no-cache add \ + eudev-dev \ + coreutils \ + linux-headers \ + alpine-sdk \ + python \ + openssl + +WORKDIR /root + +# need to get the full repo so that the build can reference git sha etc +RUN git clone https://github.com/OpenZWave/open-zwave.git + +WORKDIR /root/open-zwave +RUN git checkout ${OPENZWAVE_GIT_SHA1} +RUN make install + +WORKDIR /root/Zwave2Mqtt +COPY . . +RUN npm config set unsafe-perm true +RUN npm install +RUN npm run build +RUN npm prune --production +RUN rm -rf \ + build \ + index.html \ + package-lock.json \ + package.sh \ + src \ + static \ + stylesheets \ + views + +# ---------------- +# STEP 2: +FROM node:erbium-alpine + +LABEL maintainer="robertsLando" + +RUN apk add --no-cache \ + libstdc++ \ + libgcc \ + libusb \ + tzdata \ + eudev + +# Copy files from previous build stage +COPY --from=build /root/open-zwave/libopenzwave.so* /lib/ +COPY --from=build /root/open-zwave/config /usr/local/etc/openzwave +COPY --from=build /root/Zwave2Mqtt /usr/src/app + +# Set enviroment +ENV LD_LIBRARY_PATH /lib + +WORKDIR /usr/src/app + +EXPOSE 8091 + +CMD ["node", "bin/www"] diff --git a/README.md b/README.md index 32caeba2..894f72ff 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ Buy Me A Coffee -[![dockeri.co](https://dockeri.co/image/robertslando/zwave2mqtt)](https://hub.docker.com/r/robertslando/zwave2mqtt) +[![dockeri.co](https://dockeri.co/image/openzwave/zwave2mqtt)](https://hub.docker.com/r/openzwave/zwave2mqtt) ![OpenZWave](docs/OZW_Logo.png) **TO** @@ -38,6 +38,7 @@ After a [discussion](https://github.com/OpenZWave/Zwave2Mqtt/issues/201) with Op - [📖 Table of contents](#%f0%9f%93%96-table-of-contents) - [:electric_plug: Installation](#electricplug-installation) - [DOCKER :tada: way](#docker-tada-way) + - [Kubernetes way](#kubernetes-way) - [NodeJS or PKG version](#nodejs-or-pkg-version) - [:nerd_face: Development](#nerdface-development) - [:wrench: Usage](#wrench-usage) @@ -86,18 +87,16 @@ After a [discussion](https://github.com/OpenZWave/Zwave2Mqtt/issues/201) with Op ### DOCKER :tada: way -Check [docker repo](https://github.com/robertsLando/Zwave2Mqtt-docker#install) for more info - ```bash # Using volumes as persistence -docker run --rm -it -p 8091:8091 --device=/dev/ttyACM0 --mount source=zwave2mqtt,target=/usr/src/app/store robertslando/zwave2mqtt:latest +docker run --rm -it -p 8091:8091 --device=/dev/ttyACM0 --mount source=zwave2mqtt,target=/usr/src/app/store openzwave/zwave2mqtt:latest # Using local folder as persistence mkdir store -docker run --rm -it -p 8091:8091 --device=/dev/ttyACM0 -v $(pwd)/store:/usr/src/app/store robertslando/zwave2mqtt:latest +docker run --rm -it -p 8091:8091 --device=/dev/ttyACM0 -v $(pwd)/store:/usr/src/app/store openzwave/zwave2mqtt:latest # As a service -wget https://raw.githubusercontent.com/robertsLando/Zwave2Mqtt-docker/master/compose/docker-compose.yml +wget https://raw.githubusercontent.com/openzwave/zwave2mqtt/master/docker-compose.yml docker-compose up ``` @@ -105,6 +104,36 @@ docker-compose up Enjoy :smile: +#### Auto Update OZW device database + +If you would like to enable this feature of OZW you need to keep the device database inside a volume or a local folder and map it inside the container. To do this follow this steps: + +```sh +APP=$(docker run --rm -it -d robertslando/zwave2mqtt:latest) +docker cp $APP:/usr/local/etc/openzwave ./ +docker kill $APP +``` + +With this command you should have copied all your container device db in a local folder named `openzwave`. Now you should map this folder inside your container: + +By adding an option: + +`-v $(pwd)/openzwave:/usr/local/etc/openzwave` + +Or in docker-compose file: + +```yml +volumes: + - ./openzwave:/usr/local/etc/openzwave +``` + +### Kubernetes way + +```bash +kubectl apply -k https://raw.githubusercontent.com/openzwave/zwave2mqtt/master/kustomize.yml +``` +> You will almost certainly need to instead use this as a base, and then layer on top patches or resource customizations to your needs or just copy all the resources from the [kubernetes resources](./kubernetes) directory of this repo + ### NodeJS or PKG version 1. Firstly you need to install [Open-Zwave](https://github.com/OpenZWave/open-zwave) library on your system. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..3d9aa2d8 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,22 @@ +version: "3.7" +services: + zwave2mqtt: + container_name: zwave2mqtt + image: openzwave/zwave2mqtt:latest + restart: always + tty: true + stop_signal: SIGINT + networks: + - zwave + devices: + - "/dev/ttyACM0:/dev/ttyACM0" + volumes: + - ./store:/usr/src/app/store + ports: + - "8091:8091" +networks: + zwave: +# volumes: +# zwave2mqtt: +# name: zwave2mqtt + diff --git a/kubernetes/deployment.yaml b/kubernetes/deployment.yaml new file mode 100644 index 00000000..d47e1b72 --- /dev/null +++ b/kubernetes/deployment.yaml @@ -0,0 +1,71 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: zwave +spec: + replicas: 1 + selector: + matchLabels: + name: zwave + template: + metadata: + labels: + name: zwave + spec: + containers: + - name: zwave + image: openzwave/zwave2mqtt:latest + livenessProbe: + failureThreshold: 12 + httpGet: + httpHeaders: + - name: Accept + value: text/plain + path: /health + port: http + initialDelaySeconds: 30 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 2 + ports: + - containerPort: 8091 + name: http + protocol: TCP + resources: + limits: + cpu: "1" + memory: 512Mi + requests: + cpu: "1" + memory: 400Mi + securityContext: + allowPrivilegeEscalation: true + privileged: true + volumeMounts: + - mountPath: /dev/ttyUSB1 + name: zwavestick + - mountPath: /usr/src/app/store + name: data + # - mountPath: /usr/local/etc/openzwave + # name: ozwdatabase + # - mountPath: /usr/src/app/store/settings.json <-- if putting your settings.json in a secret + # name: config + # readOnly: true + # subPath: settings.json + # nodeSelector: + # kubernetes.io/hostname: stick1 #<--- the name of your cluster node that the zwave usb stick in + volumes: + # - name: config <-- if putting your settings.json in a secret + # secret: + # defaultMode: 420 + # secretName: zwave2mqtt + - name: zwavestick + hostPath: + path: /dev/ttyACM0 + type: File + - name: data + hostPath: + path: /zwave/data + # - name: ozwdatabase + # hostPath: + # path: /zwave/database diff --git a/kubernetes/ingress.yaml b/kubernetes/ingress.yaml new file mode 100644 index 00000000..edbc8a68 --- /dev/null +++ b/kubernetes/ingress.yaml @@ -0,0 +1,12 @@ +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: zwave +spec: + rules: + - host: zwave.example.com + http: + paths: + - backend: + serviceName: zwave + servicePort: http diff --git a/kubernetes/namespace.yaml b/kubernetes/namespace.yaml new file mode 100644 index 00000000..c0a4b670 --- /dev/null +++ b/kubernetes/namespace.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: zwave diff --git a/kubernetes/service.yaml b/kubernetes/service.yaml new file mode 100644 index 00000000..c4959d36 --- /dev/null +++ b/kubernetes/service.yaml @@ -0,0 +1,11 @@ +apiVersion: v1 +kind: Service +metadata: + name: zwave +spec: + ports: + - name: http + port: 80 + targetPort: http + selector: + name: zwave diff --git a/kustomization.yaml b/kustomization.yaml new file mode 100644 index 00000000..177b8832 --- /dev/null +++ b/kustomization.yaml @@ -0,0 +1,10 @@ +apiVersion: kustomize.config.k8s.io/v1beta1 +kind: Kustomization + +resources: + - kubernetes/namespace.yaml + - kubernetes/deployment.yaml + - kubernetes/service.yaml + - kubernetes/ingress.yaml + +namespace: zwave