Merge pull request #9 from home-assistant/build

Add mosquitto & fix letsencrypt bug
This commit is contained in:
Pascal Vizeli
2017-04-29 23:51:39 +02:00
committed by GitHub
7 changed files with 136 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
{
"name": "Let's Encrypt",
"version": "0.1",
"version": "0.2",
"slug": "letsencrypt",
"description": "Manage let's encrypt certificate",
"startup": "once",

View File

@@ -1,5 +1,4 @@
#!/bin/bash
set -e
CERT_DIR=/data/letsencrypt
@@ -23,17 +22,17 @@ if [ -d $CERT_DIR ]; then
/data/certbot-auto renew --non-interactive --config-dir $CERT_DIR --work-dir $WORK_DIR
else
# generate domains
while IFS=$'\n' read -r line; do
for line in $DOMAINS; do
if [ -z "$DOMAIN_ARG" ]; then
DOMAIN_ARG="-d $line"
else
DOMAIN_ARG="$DOMAIN_ARG -d $line"
fi
done <<< "$DOMAINS"
done
/data/certbot-auto certonly --non-interactive --standalone --email $EMAIL --config-dir $CERT_DIR --work-dir "$DOMAIN_ARG"
/data/certbot-auto certonly --non-interactive --standalone --email "$EMAIL" --config-dir $CERT_DIR --work-dir "$DOMAIN_ARG"
fi
# copy certs to store
cp /data/letsencrypt/live/*/privkey.pem /ssl/KEYFILE
cp /data/letsencrypt/live/*/fullchain.pem /ssl/CERTFILE
cp /data/letsencrypt/live/*/privkey.pem "/ssl/$KEYFILE"
cp /data/letsencrypt/live/*/fullchain.pem "/ssl/$CERTFILE"

16
mosquitto/Dockerfile Normal file
View File

@@ -0,0 +1,16 @@
FROM %%BASE_IMAGE%%
# Add version
ENV VERSION %%VERSION%%
ENV LANG C.UTF-8
# Setup base
RUN apk add --no-cache jq mosquitto
# Copy data
COPY run.sh /
COPY mosquitto.conf /etc/
RUN chmod a+x /run.sh
CMD [ "/run.sh" ]

12
mosquitto/README.md Normal file
View File

@@ -0,0 +1,12 @@
# Mosquitto
MQTT broker for HomeAssistant and HassIO addons.
## Options
- `plain`:
- `ssl`:
- `ssl`:
- `anonymous`:
- `logins`:
- `certfile`:
- `keyfile`:

31
mosquitto/config.json Normal file
View File

@@ -0,0 +1,31 @@
{
"name": "Mosquitto broker",
"version": "0.1",
"slug": "mosquitto",
"description": "An Open Source MQTT broker",
"startup": "before",
"boot": "auto",
"ports": {
"1883/tcp": 1883,
"8883/tcp": 8883
},
"map": ["ssl"],
"options": {
"plain": true,
"ssl": false,
"anonymous": true,
"logins": [],
"certfile": "fullchain.pem",
"keyfile": "privkey.pem"
},
"schema": {
"plain": "bool",
"ssl": "bool",
"anonymous": "bool",
"logins": [
{"username": "str", "password": "str"}
],
"certfile": "str",
"keyfile": "str"
}
}

17
mosquitto/mosquitto.conf Normal file
View File

@@ -0,0 +1,17 @@
##
# defaults
protocol mqtt
##
# logging
log_dest stdout
##
# datastore
persistence true
persistence_location /data/
##
# User settings
#password_file /data/users.db
#allow_anonymous true

54
mosquitto/run.sh Normal file
View File

@@ -0,0 +1,54 @@
#!/bin/bash
set -e
CONFIG_PATH=/data/options.json
PLAIN=$(jq --raw-output ".plain" $CONFIG_PATH)
SSL=$(jq --raw-output ".ssl" $CONFIG_PATH)
LOGINS=$(jq --raw-output ".logins | length" $CONFIG_PATH)
ANONYMOUS=$(jq --raw-output ".anonymous" $CONFIG_PATH)
KEYFILE=$(jq --raw-output ".keyfile" $CONFIG_PATH)
CERTFILE=$(jq --raw-output ".certfile" $CONFIG_PATH)
PLAIN_CONFIG="
listener 1883
"
SSL_CONFIG="
port 8883
listener 8883
cafile /ssl/$CERTFILE
certfile /ssl/$CERTFILE
keyfile /ssl/$KEYFILE
"
# Add plain configs
if [ "$PLAIN" == "true" ]; then
echo "$PLAIN_CONFIG" >> /etc/mosquitto.conf
fi
# Add ssl configs
if [ "$SSL" == "true" ]; then
echo "$SSL_CONFIG" >> /etc/mosquitto.conf
fi
# Allow anonymous connections
if [ "$ANONYMOUS" == "true" ]; then
sed -i "s/#allow_anonymous/allow_anonymous/g" /etc/mosquitto.conf
fi
# Generate user data
if [ "$LOGINS" -gt "0" ]; then
sed -i "s/#password_file/password_file/g" /etc/mosquitto.conf
rm -f /data/users.db || true
for (( i=0; i < "$LOGINS"; i++ )); do
USERNAME=$(jq --raw-output ".logins[$i].username" $CONFIG_PATH)
PASSWORD=$(jq --raw-output ".logins[$i].password" $CONFIG_PATH)
mosquitto_passwd -b /data/users.db "$USERNAME" "$PASSWORD"
done
fi
# start server
exec mosquitto -c /etc/mosquitto.conf < /dev/null