Skip to content

Commit

Permalink
Merge pull request #479 from OpenHausIO/dev
Browse files Browse the repository at this point in the history
v3.0.0 release
  • Loading branch information
mStirner authored Jun 16, 2024
2 parents 90d39db + fb865c7 commit faf5568
Show file tree
Hide file tree
Showing 119 changed files with 9,146 additions and 4,645 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/docker-nightly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Publish Docker nightly image

on:
pull_request:
types:
- closed
branches:
- dev

jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
if: github.repository == 'OpenHausIO/backend' && github.event.pull_request.merged == true
steps:
- name: Check out the repo
uses: actions/checkout@v4

- name: Use Node.js 18.x
uses: actions/setup-node@v4
with:
node-version: 18.x
- run: npm ci
- run: npm run build

- name: Log in to Docker Hub
uses: docker/login-action@v3.0.0
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5.5.0
with:
images: openhaus/backend

- name: Build and push Docker image
uses: docker/build-push-action@v5.1.0
with:
context: .
file: ./Dockerfile
push: true
tags: openhaus/backend:nightly
labels: ${{ steps.meta.outputs.labels }}
6 changes: 3 additions & 3 deletions .github/workflows/node-js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
node-version: [16.x, 17.x, 18.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
node-version: [16.x, 18.x, 20.x] # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
mongodb-version: ["4.2", "4.4", "5.0"]

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

# mongodb setup
- name: Start MongoDB
Expand All @@ -41,7 +41,7 @@ jobs:

# node.js setup
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
cache: "npm"
Expand Down
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

npm run lint
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# https://medium.com/@kahana.hagai/docker-compose-with-node-js-and-mongodb-dbdadab5ce0a

# The instructions for the first stage
FROM node:16-alpine as builder
FROM node:20-alpine as builder

ARG NODE_ENV=production
ENV NODE_ENV=${NODE_ENV}
Expand All @@ -22,7 +22,7 @@ RUN npm install


# The instructions for second stage
FROM node:16-alpine
FROM node:20-alpine

WORKDIR /opt/OpenHaus/backend
COPY --from=builder node_modules node_modules
Expand Down
11 changes: 10 additions & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ module.exports = function (grunt) {
options: {
mangle: {
toplevel: true
}
},
//banner: fs.readFileSync(path.join(process.cwd(), "docs/banner.txt"), "utf8")
},
build: {
files: [{
Expand Down Expand Up @@ -99,10 +100,18 @@ module.exports = function (grunt) {
stdio: "inherit"
});

// remove build, use taggin. see: #451
/*
cp.execSync(`docker build . -t openhaus/${pkg.name}:latest ${buildArgs}`, {
env: process.env,
stdio: "inherit"
});
*/

cp.execSync(`docker image tag openhaus/${pkg.name}:${pkg.version} openhaus/${pkg.name}:latest`, {
env: process.env,
stdio: "inherit"
});

});

Expand Down
38 changes: 38 additions & 0 deletions ISSUES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
```systemd
[Unit]
Description=firewalld - dynamic firewall daemon
Before=network-pre.target
Wants=network-pre.target
After=dbus.service
After=polkit.service
Conflicts=iptables.service ip6tables.service ebtables.service ipset.service nftables.service
Documentation=man:firewalld(1)
[Service]
EnvironmentFile=-/etc/sysconfig/firewalld
ExecStart=/usr/sbin/firewalld --nofork --nopid $FIREWALLD_ARGS
ExecReload=/bin/kill -HUP $MAINPID
# supress to log debug and error output also to /var/log/messages
StandardOutput=null
StandardError=null
Type=dbus
BusName=org.fedoraproject.FirewallD1
KillMode=mixed
[Install]
WantedBy=multi-user.target
Alias=dbus-org.fedoraproject.FirewallD1.service
```

https://systemd-devel.freedesktop.narkive.com/dpY7US7K/a-little-help-with-mainpid-please


OpenHaus relevant/verbesserung?!


----------------

Use husky for git hooks?

https://www.npmjs.com/package/husky
https://typicode.github.io/husky/
3 changes: 2 additions & 1 deletion adapter/eol.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = (options = {}) => {
// https://github.com/OpenHausIO/backend/issues/315
let cr = Buffer.from("\r");
let lf = Buffer.from("\n");
//let eol = Buffer.from("\x1A");
//let eof = Buffer.from("\x1A");
let nl = Buffer.concat([
cr,
lf
Expand All @@ -25,6 +25,7 @@ module.exports = (options = {}) => {
let decode = new Transform({
transform(chunk, encoding, cb) {
log.trace("[encode] (%s) %j", encoding, chunk);
// NOTE (mstirner) is this right?
cb(null, chunk.subarray(0, nl.length));
},
...options
Expand Down
13 changes: 8 additions & 5 deletions backend.service
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
[Unit]
Description=OpenHaus Backend
Documentation=https://docs.open-haus.io
Wants=network-online.target
After=network-online.target

[Service]
ExecStart=/usr/bin/node /opt/OpenHaus/backend/index.js
WorkingDirectory=/opt/OpenHaus/backend
Restart=always
EnvironmentFile=/opt/OpenHaus/backend/.env
Restart=on-failure
RestartSec=10
Environment=NODE_ENV=production
Environment=VAULT_MASTER_PASSWORD=Pa$$w0rd
Environment=USERS_JWT_SECRET=Pa$$w0rd
Environment=UUID=00000000-0000-0000-0000-000000000000
Type=simple
#Environment=NODE_ENV=production
#Environment=VAULT_MASTER_PASSWORD=Pa$$w0rd
#Environment=USERS_JWT_SECRET=Pa$$w0rd
#Environment=UUID=00000000-0000-0000-0000-000000000000

[Install]
WantedBy=multi-user.target
63 changes: 59 additions & 4 deletions components/devices/class.device.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
const Joi = require("joi");
const mongodb = require("mongodb");

const InterfaceStream = require("./class.interfaceStream.js");
const Interface = require("./class.interface.js");
const Item = require("../../system/component/class.item.js");

const mixins = require("../../helper/mixins.js");
const injectMethod = require("../../helper/injectMethod.js");

//const { parse, calculateChecksum } = require("./net-helper.js");

/**
* @description
Expand All @@ -20,17 +27,25 @@ const mixins = require("../../helper/mixins.js");
* @see interface components/devices/class.interface.js
* @see interfaceStream components/devices/class.interfaceStream.js
*/
module.exports = class Device {
constructor(props) {
module.exports = class Device extends Item {
constructor(props, scope) {

super(props);

// removed for #356
// set properties from db
Object.assign(this, props);
this._id = String(props._id);
//Object.assign(this, props);
//this._id = String(props._id);

// create for each interface a interface class instance
// for each interface class, create a interface stream
this.interfaces = props.interfaces.map((obj) => {


// NOTE: refactor interfaceStream in v4
// move .bridge method there and pass device instance?
// > Would this also create a ciruclar reference in Interface class
// > since its stored via `Object.defineProperty(this, "stream",...);`
let stream = new InterfaceStream({
// duplex stream options
emitClose: false
Expand All @@ -43,6 +58,21 @@ module.exports = class Device {
let iface = new Interface(obj, stream);


// inject bridge method into interface instance
// passing deivce instance into Interface class, creates a ciruclar reference
// TODO: Move this into "interfaceStream" (needs to be refactored)
// NOTE: remove "device" for bridging requests (only needed in connector)?
// > See: https://github.com/OpenHausIO/connector/issues/54
// > When done, "device" property can be removed, and the `.bridge()` method can be moved into Interface class
injectMethod(iface, "bridge", (cb) => {
return Interface._bridge({
events: scope.events,
interface: iface,
device: this._id
}, cb);
});


// "hide" stream behind iface object
// so we can use the interface object
// as duplex stream
Expand All @@ -61,4 +91,29 @@ module.exports = class Device {
});

}

static schema() {
return Joi.object({
_id: Joi.string().pattern(/^[0-9a-fA-F]{24}$/).default(() => {
return String(new mongodb.ObjectId());
}),
name: Joi.string().required(),
room: Joi.string().pattern(/^[0-9a-fA-F]{24}$/).allow(null).default(null),
enabled: Joi.boolean().default(true),
//interfaces: Joi.array().items(Interface.schema()).min(1).required()
interfaces: Joi.array().items(Interface.schema()).default([]),
meta: {
manufacturer: Joi.string().allow(null).default(null),
model: Joi.string().allow(null).default(null),
revision: Joi.number().allow(null).default(null),
serial: Joi.string().allow(null).default(null)
},
icon: Joi.string().allow(null).default(null)
});
}

static validate(data) {
return Device.schema().validate(data);
}

};
Loading

0 comments on commit faf5568

Please sign in to comment.