Skip to content
This repository has been archived by the owner on Feb 24, 2021. It is now read-only.

Commit

Permalink
move docker build to this repo (#473)
Browse files Browse the repository at this point in the history
* dockerfile

* docker build workflow

* dev is built from master latest is from most recent tag

* reduced platform builds

* tags are prefixed with 'v'

* combine latest and tag steps

* move docker-compose file over

* add k8s resources

* mount the ozw database in k8s

* update readme

* hardcode the docker repo to avoid ambiguity
  • Loading branch information
chrisns authored May 15, 2020
1 parent f750ca6 commit 4cab516
Show file tree
Hide file tree
Showing 10 changed files with 283 additions and 15 deletions.
9 changes: 9 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.git
.github
*.md
docs
.vscode
.nyc_output
.coverage
pkg
test
52 changes: 43 additions & 9 deletions .github/workflows/dockerbuild.yml
Original file line number Diff line number Diff line change
@@ -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 \
.
66 changes: 66 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
41 changes: 35 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<a href="https://www.buymeacoffee.com/MVg9wc2HE" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>

[![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**
Expand All @@ -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)
Expand Down Expand Up @@ -86,25 +87,53 @@ 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
```

> Replace `/dev/ttyACM0` with your serial device
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.
Expand Down
22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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

71 changes: 71 additions & 0 deletions kubernetes/deployment.yaml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions kubernetes/ingress.yaml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions kubernetes/namespace.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: Namespace
metadata:
name: zwave
11 changes: 11 additions & 0 deletions kubernetes/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: zwave
spec:
ports:
- name: http
port: 80
targetPort: http
selector:
name: zwave
10 changes: 10 additions & 0 deletions kustomization.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4cab516

Please sign in to comment.