Merge pull request #98 from home-assistant/build

Build
This commit is contained in:
Pascal Vizeli
2017-05-25 00:19:22 +02:00
committed by GitHub
4 changed files with 86 additions and 0 deletions

15
dnsmasq/Dockerfile Normal file
View File

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

33
dnsmasq/config.json Normal file
View File

@@ -0,0 +1,33 @@
{
"name": "Dnsmasq server",
"version": "0.1",
"slug": "dnsmasq",
"description": "A simple dns server with benefits",
"url": "https://home-assistant.io/addons/dnsmasq/",
"startup": "before",
"boot": "auto",
"ports": {
"53/udp": 53
},
"options": {
"defaults": ["8.8.8.8", "8.8.4.4"],
"forwards": [],
"hosts": []
},
"schema": {
"defaults": ["str"],
"forwards": [
{
"domain": "str",
"server": "str"
}
],
"hosts": [
{
"host": "str",
"ip": "str"
}
]
},
"image": "homeassistant/{arch}-addon-dnsmasq"
}

6
dnsmasq/dnsmasq.conf Normal file
View File

@@ -0,0 +1,6 @@
no-resolv
no-hosts
keep-in-foreground
log-queries
log-facility=-
no-poll

32
dnsmasq/run.sh Normal file
View File

@@ -0,0 +1,32 @@
#!/bin/bash
set -e
CONFIG_PATH=/data/options.json
DEFAULTS=$(jq --raw-output '.domain' $CONFIG_PATH)
FORWARDS=$(jq --raw-output '.forwards | length' $CONFIG_PATH)
HOSTS=$(jq --raw-output '.hosts | length' $CONFIG_PATH)
# Add default forward servers
for line in $DEFAULTS; do
echo "server=$line" >> /etc/dnsmasq.conf
done
# Create domain forwards
for (( i=0; i < "$FORWARDS"; i++ )); do
DOMAIN=$(jq --raw-output ".forwards[$i].domain" $CONFIG_PATH)
SERVER=$(jq --raw-output ".forwards[$i].server" $CONFIG_PATH)
echo "server=/$DOMAIN/$SERVER" >> /etc/dnsmasq.conf
done
# Create static hosts
for (( i=0; i < "$HOSTS"; i++ )); do
HOST=$(jq --raw-output ".forwards[$i].host" $CONFIG_PATH)
IP=$(jq --raw-output ".forwards[$i].ip" $CONFIG_PATH)
echo "address=/$HOST/$IP" >> /etc/dnsmasq.conf
done
# run dnsmasq
exec dnsmasq -C /etc/dnsmasq.conf < /dev/null