Skip to content

Commit 347c097

Browse files
committed
feat: add nats-server
1 parent 2d6cb9c commit 347c097

File tree

11 files changed

+337
-2
lines changed

11 files changed

+337
-2
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
1-
# addon-nats-server
2-
Unofficial nats-server Home Assistant add-on repository
1+
<p align="center">
2+
<img src="nats-server/logo.png" width="300" alt="NATS Logo">
3+
</p>
4+
5+
Unofficial NATS Server Home Assistant add-on repository

nats-server/.dockerignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
*.yaml
2+
*.png
3+
*.md
4+
*.json

nats-server/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
## 2.10.14
2+
- First release [`2.10.14`](https://github.com/Cameri/addon-nats-server/releases/tag/2.10.14)

nats-server/Dockerfile

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
ARG BUILD_FROM=ghcr.io/hassio-addons/base/aarch64:15.0.8
2+
3+
FROM ${BUILD_FROM}
4+
5+
ARG NATS_SERVER_VERSION
6+
7+
RUN set -eux; \
8+
apkArch="$(apk --print-arch)"; \
9+
case "$apkArch" in \
10+
aarch64) natsArch='arm64'; sha256='57aa4464759d211df247b645dae6d0c0724d84aa2db3dc042cd2dc9fe8553302' ;; \
11+
armhf) natsArch='arm6'; sha256='125dba652ee7c4c60bf1af3ced1c590e7d32f7624e27364c278069da660f04ea' ;; \
12+
armv7) natsArch='arm7'; sha256='1215a787ac52d03bc2c43069ac4229b891be7dafeb2ea44f58dc5c854001629c' ;; \
13+
x86_64) natsArch='amd64'; sha256='8e1ba988220e7f3a0156c085b7c4fe47222ee8342cf1cfa7b364e30d9d6aa47d' ;; \
14+
x86) natsArch='386'; sha256='29b361db7d0ece5ba74ac6aa1911446573db3a4806c175df4bd37142bccf5e06' ;; \
15+
s390x) natsArch='s390x'; sha256='f9a3c2b1ca2d89bc865b08d37451e5c1949112e042c69fdb88bbb6938ad774a8' ;; \
16+
ppc64le) natsArch='ppc64le'; sha256='276f4f5d080a96c31c4e1a15e84aafefef5d82dd93c112ea659f17f068ab4b6a' ;; \
17+
*) echo >&2 "error: $apkArch is not supported!"; exit 1 ;; \
18+
esac; \
19+
\
20+
wget -O nats-server.tar.gz "https://github.com/nats-io/nats-server/releases/download/v${NATS_SERVER_VERSION}/nats-server-v${NATS_SERVER_VERSION}-linux-${natsArch}.tar.gz"; \
21+
echo "${sha256} *nats-server.tar.gz" | sha256sum -c -; \
22+
\
23+
apk add --no-cache ca-certificates tzdata gettext; \
24+
\
25+
tar -xf nats-server.tar.gz; \
26+
rm nats-server.tar.gz; \
27+
mv "nats-server-v${NATS_SERVER_VERSION}-linux-${natsArch}/nats-server" /usr/local/bin; \
28+
rm -rf "nats-server-v${NATS_SERVER_VERSION}-linux-${natsArch}";
29+
30+
COPY run.sh /usr/local/bin
31+
RUN mkdir -p /etc/nats
32+
33+
EXPOSE 4222 8222 6222 1883
34+
ENTRYPOINT ["run.sh"]
35+
CMD ["nats-server", "--config", "/etc/nats/nats-server.conf"]

nats-server/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Home Assistant Add-on: NATS Server
2+
3+
High-Performance server for NATS.io, the cloud and edge native messaging system.

nats-server/build.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
build_from:
3+
aarch64: ghcr.io/hassio-addons/base/aarch64:15.0.8
4+
amd64: ghcr.io/hassio-addons/base/amd64:15.0.8
5+
armhf: ghcr.io/hassio-addons/base/armhf:15.0.8
6+
armv7: ghcr.io/hassio-addons/base/armv7:15.0.8
7+
i386: ghcr.io/hassio-addons/base/i386:15.0.8
8+
args:
9+
NATS_SERVER_VERSION: 2.10.14

nats-server/config.json

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
{
2+
"name": "NATS Server",
3+
"version": "2.10.14",
4+
"slug": "nats-server",
5+
"description": "High-Performance server for NATS.io, the cloud and edge native messaging system.",
6+
"url": "https://github.com/Cameri/addon-nats-server/tree/master/nats-server",
7+
"startup": "system",
8+
"services": [],
9+
"discovery": [
10+
"mqtt"
11+
],
12+
"arch": [
13+
"aarch64",
14+
"amd64",
15+
"armv7"
16+
],
17+
"boot": "auto",
18+
"init": false,
19+
"ingress": true,
20+
"timeout": 10,
21+
"panel_icon": "mdi:message-reply-outline",
22+
"map": [
23+
"ssl"
24+
],
25+
"webui": "http://[HOST]:[PORT:8222]/varz",
26+
"watchdog": "tcp://[HOST]:4222",
27+
"ports": {
28+
"4222/tcp": 4222,
29+
"6222/tcp": 6222,
30+
"8222/tcp": 8222,
31+
"1883/tcp": 1883
32+
},
33+
"ports_description": {
34+
"4222/tcp": "TCP listening port for NATS clients",
35+
"6222/tcp": "Routing port for clustering",
36+
"8222/tcp": "HTTP management port",
37+
"1883/tcp": "MQTT listening port"
38+
},
39+
"options": {
40+
"jetstream": {
41+
"enabled": false
42+
},
43+
"mqtt": {
44+
"enabled": true,
45+
"username": "nats-mqtt",
46+
"timeout": 2
47+
},
48+
"cluster": {
49+
"enabled": false,
50+
"name": "ha-cluster",
51+
"timeout": 2,
52+
"routes": []
53+
}
54+
},
55+
"schema": {
56+
"server_name": "str?",
57+
"jetstream": {
58+
"enabled": "bool",
59+
"max_mem": "str?",
60+
"max_file": "str?",
61+
"cipher": "list(chachapoly|aes)?",
62+
"key": "str?"
63+
},
64+
"mqtt": {
65+
"enabled": "bool",
66+
"username": "str?",
67+
"password": "str?",
68+
"timeout": "int?",
69+
"tls": "bool?",
70+
"tls_cert_file": "str?",
71+
"tls_key_file": "str?",
72+
"tls_ca_file": "str?",
73+
"tls_verify": "bool?",
74+
"tls_timeout": "int?",
75+
"tls_verify_and_map": "bool?",
76+
"no_auth_user": "str?",
77+
"ack_wait": "str?",
78+
"max_ack_pending": "int?"
79+
},
80+
"cluster": {
81+
"enabled": "bool",
82+
"name": "str?",
83+
"host": "str?",
84+
"username": "str?",
85+
"password": "str?",
86+
"timeout": "int?",
87+
"routes": [
88+
"str"
89+
],
90+
"tls": "bool?",
91+
"tls_cert_file": "str?",
92+
"tls_key_file": "str?",
93+
"tls_ca_file": "str?",
94+
"tls_verify": "bool?",
95+
"tls_timeout": "int?",
96+
"tls_verify_and_map": "bool?"
97+
},
98+
"debug": "bool?",
99+
"trace": "bool?",
100+
"logtime": "bool?",
101+
"logfile_size_limit": "str?",
102+
"log_file": "str?"
103+
}
104+
}

nats-server/icon.png

17.4 KB
Loading

nats-server/logo.png

21.4 KB
Loading

nats-server/run.sh

Lines changed: 170 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,170 @@
1+
#!/usr/bin/env bashio
2+
3+
#set -euxo pipefail
4+
set -euo pipefail
5+
# source: https://gist.github.com/mohanpedala/1e2ff5661761d3abd0385e8223e16425
6+
7+
CONFIG="/etc/nats/nats-server.conf"
8+
9+
# Root
10+
{
11+
echo "port: 4222"
12+
echo "monitor_port: 8222"
13+
14+
SERVER_NAME=$(bashio::config 'server_name' '143ce9cf-nats-server')
15+
echo "server_name: \"${SERVER_NAME}\""
16+
17+
# JetStream
18+
# source: https://docs.nats.io/running-a-nats-service/configuration/resource_management
19+
if bashio::config.true 'jetstream.enabled'; then
20+
echo "jetstream {"
21+
echo " store_dir: /data/storage"
22+
if bashio::config.exists 'jetstream.max_mem'; then
23+
echo " max_mem: $(bashio::config 'jetstream.max_mem')"
24+
fi
25+
if bashio::config.exists 'jetstream.max_file'; then
26+
echo " max_file: $(bashio::config 'jetstream.max_file')"
27+
fi
28+
if bashio::config.exists 'jetstream.chiper'; then
29+
echo " chiper: $(bashio::config 'jetstream.chiper')"
30+
fi
31+
if bashio::config.exists 'jetstream.key'; then
32+
echo " key: $(bashio::config 'jetstream.key')"
33+
fi
34+
echo "}"
35+
fi
36+
37+
# MQTT
38+
# source: https://docs.nats.io/running-a-nats-service/configuration/mqtt/mqtt_config
39+
if bashio::config.true 'mqtt.enabled'; then
40+
echo "mqtt {"
41+
echo " port: 1883"
42+
if bashio::config.exists 'mqtt.username' || bashio::config.exists 'mqtt.password'; then
43+
echo " authorization {"
44+
echo " username: \"$(bashio::config 'mqtt.username' '')\""
45+
echo " password: \"$(bashio::config 'mqtt.password' '')\""
46+
if bashio::config.exists 'mqtt.timeout'; then
47+
echo " timeout: $(bashio::config 'mqtt.timeout')"
48+
fi
49+
echo " }"
50+
fi
51+
52+
if bashio::config.true 'cluster.tls'; then
53+
echo " tls {"
54+
if bashio::config.exists 'cluster.tls_cert_file'; then
55+
echo " cert_file: \"$(bashio::config 'cluster.tls_cert_file')\""
56+
fi
57+
if bashio::config.exists 'cluster.tls_key_file'; then
58+
echo " key_file: \"$(bashio::config 'cluster.tls_key_file')\""
59+
fi
60+
if bashio::config.exists 'cluster.tls_ca_file'; then
61+
echo " ca_file: \"$(bashio::config 'cluster.tls_ca_file')\""
62+
fi
63+
if bashio::config.exists 'cluster.tls_verify'; then
64+
echo " verify: $(bashio::config 'cluster.tls_verify')"
65+
fi
66+
if bashio::config.exists 'cluster.tls_timeout'; then
67+
echo " timeout: \"$(bashio::config 'cluster.tls_timeout')\""
68+
fi
69+
if bashio::config.exists 'cluster.tls_verify_and_map'; then
70+
echo " verify_and_map: $(bashio::config 'cluster.tls_verify_and_map')"
71+
fi
72+
echo " }" # tls
73+
fi
74+
echo "}"
75+
fi
76+
77+
# Clustering
78+
# source: https://docs.nats.io/running-a-nats-service/configuration/clustering/cluster_config
79+
if bashio::config.true 'cluster.enabled'; then
80+
echo "cluster {"
81+
echo " port: 6222"
82+
83+
if bashio::config.exists 'cluster.name'; then
84+
echo " name: \"$(bashio::config 'cluster.name')\""
85+
fi
86+
if bashio::config.exists 'cluster.host'; then
87+
echo " host: \"$(bashio::config 'cluster.host')\""
88+
fi
89+
90+
if bashio::config.exists 'cluster.username' || bashio::config.exists 'cluster.password'; then
91+
echo " authorization {"
92+
echo " username: \"$(bashio::config 'cluster.username')\""
93+
echo " password: \"$(bashio::config 'cluster.password')\""
94+
if bashio::config.exists 'cluster.timeout'; then
95+
echo " timeout: $(bashio::config 'cluster.timeout')"
96+
fi
97+
echo " }"
98+
fi
99+
100+
# Routes
101+
echo " routes = ["
102+
for route in $(bashio::config 'cluster.routes')
103+
do
104+
echo " $route"
105+
done
106+
echo " ]"
107+
108+
109+
if bashio::config.true 'mqtt.tls'; then
110+
echo " tls {"
111+
if bashio::config.exists 'mqtt.tls_cert_file'; then
112+
echo " cert_file: \"$(bashio::config 'mqtt.tls_cert_file')\""
113+
fi
114+
if bashio::config.exists 'mqtt.tls_key_file'; then
115+
echo " key_file: \"$(bashio::config 'mqtt.tls_key_file')\""
116+
fi
117+
if bashio::config.exists 'mqtt.tls_ca_file'; then
118+
echo " ca_file: \"$(bashio::config 'mqtt.tls_ca_file')\""
119+
fi
120+
if bashio::config.exists 'mqtt.tls_verify'; then
121+
echo " verify: $(bashio::config 'mqtt.tls_verify')"
122+
fi
123+
if bashio::config.exists 'mqtt.tls_timeout'; then
124+
echo " timeout: \"$(bashio::config 'mqtt.tls_timeout')\""
125+
fi
126+
if bashio::config.exists 'mqtt.tls_verify_and_map'; then
127+
echo " verify_and_map: $(bashio::config 'mqtt.tls_verify_and_map')"
128+
fi
129+
echo " }" # tls
130+
if bashio::config.exists 'mqtt.no_auth_user'; then
131+
echo " no_auth_user: \"$(bashio::config 'mqtt.no_auth_user')\""
132+
fi
133+
if bashio::config.exists 'mqtt.ack_wait'; then
134+
echo " ack_wait: \"$(bashio::config 'mqtt.ack_wait')\""
135+
fi
136+
if bashio::config.exists 'mqtt.max_ack_pending'; then
137+
echo " max_ack_pending: $(bashio::config 'mqtt.max_ack_pending')"
138+
fi
139+
fi
140+
fi
141+
142+
echo "}"
143+
144+
# Logging
145+
# source: https://docs.nats.io/running-a-nats-service/configuration/logging
146+
if bashio::config.exists 'debug'; then
147+
echo "debug: $(bashio::config 'debug')"
148+
fi
149+
if bashio::config.exists 'trace'; then
150+
echo "trace: $(bashio::config 'trace')"
151+
fi
152+
if bashio::config.exists 'logtime'; then
153+
echo "logtime: $(bashio::config 'logtime')"
154+
fi
155+
if bashio::config.exists 'logfile_size_limit'; then
156+
echo "logfile_size_limit: $(bashio::config 'logfile_size_limit')"
157+
fi
158+
if bashio::config.exists 'log_file'; then
159+
echo "log_file: $(bashio::config 'log_file')"
160+
fi
161+
} > "$CONFIG"
162+
163+
# this if will check if the first argument is a flag
164+
# but only works if all arguments require a hyphenated flag
165+
# -v; -SL; -f arg; etc will work, but not arg1 arg2
166+
if [ "$#" -eq 0 ] || [ "${1#-}" != "$1" ]; then
167+
set -- nats-server "$@"
168+
fi
169+
# else default to run whatever the user wanted like "bash" or "sh"
170+
exec "$@"

0 commit comments

Comments
 (0)