initial commit

This commit is contained in:
Benjamin Bärthlein
2020-03-28 17:56:11 +01:00
parent 4a3673e0d3
commit c4809b85b4
51 changed files with 26929 additions and 1 deletions
+26
View File
@@ -0,0 +1,26 @@
FROM golang:latest as builder
ENV GO111MODULE=on
ENV GOPATH=/root/go
RUN mkdir -p /root/go/src
COPY dyndns /root/go/src/dyndns
RUN cd /root/go/src/dyndns && go mod download && GOOS=linux GOARCH=amd64 go build -o /root/go/bin/dyndns && go test -v
FROM debian:buster-slim
RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
apt-get install -q -y bind9 dnsutils curl && \
apt-get clean
RUN chmod 770 /var/cache/bind
COPY deployment/setup.sh /root/setup.sh
RUN chmod +x /root/setup.sh
COPY deployment/named.conf.options /etc/bind/named.conf.options
WORKDIR /root
COPY --from=builder /root/go/bin/dyndns /root/dyndns
COPY dyndns/views /root/views
COPY dyndns/static /root/static
EXPOSE 53 8080
CMD ["sh", "-c", "/root/setup.sh ; service bind9 start ; /root/dyndns"]
+17
View File
@@ -0,0 +1,17 @@
version: '3'
services:
ddns:
image: bbaerthlein/docker-ddns-server:latest
restart: always
environment:
DDNS_ADMIN_LOGIN: 'admin:$$3$$abcdefg'
DDNS_DOMAIN: 'dyndns.example.com'
DDNS_PARENT_NS: 'ns.example.com'
DDNS_DEFAULT_TTL: '3600'
ports:
- "53:53"
- "53:53/udp"
- "8080:8080"
volumes:
- ./bind-data:/var/cache/bind
- ./database:/root/dyndns/database
+4
View File
@@ -0,0 +1,4 @@
DDNS_ADMIN_LOGIN=admin:$$3$$abcdefg
DDNS_DOMAIN=dyndns.example.com
DDNS_PARENT_NS=ns.example.com
DDNS_DEFAULT_TTL=3600
+8
View File
@@ -0,0 +1,8 @@
options {
directory "/var/cache/bind";
dnssec-validation auto;
recursion no;
allow-transfer { none; };
auth-nxdomain no;
listen-on-v6 { any; };
};
+48
View File
@@ -0,0 +1,48 @@
#!/bin/bash
[ -z "$DDNS_ADMIN_LOGIN" ] && echo "DDNS_ADMIN_LOGIN not set" && exit 1;
[ -z "$DDNS_DOMAIN" ] && echo "DDNS_DOMAIN not set" && exit 1;
[ -z "$DDNS_PARENT_NS" ] && echo "DDNS_PARENT_NS not set" && exit 1;
[ -z "$DDNS_DEFAULT_TTL" ] && echo "DDNS_DEFAULT_TTL not set" && exit 1;
DDNS_IP=$(curl icanhazip.com)
if ! grep 'zone "'$DDNS_DOMAIN'"' /etc/bind/named.conf > /dev/null
then
echo "creating zone...";
cat >> /etc/bind/named.conf <<EOF
zone "$DDNS_DOMAIN" {
type master;
file "$DDNS_DOMAIN.zone";
allow-query { any; };
allow-transfer { none; };
allow-update { localhost; };
};
EOF
fi
if [ ! -f /var/cache/bind/$DDNS_DOMAIN.zone ]
then
echo "creating zone file..."
cat > /var/cache/bind/$DDNS_DOMAIN.zone <<EOF
\$ORIGIN .
\$TTL 86400 ; 1 day
$DDNS_DOMAIN IN SOA ${DDNS_PARENT_NS}. root.${DDNS_DOMAIN}. (
74 ; serial
3600 ; refresh (1 hour)
900 ; retry (15 minutes)
604800 ; expire (1 week)
86400 ; minimum (1 day)
)
NS ${DDNS_PARENT_NS}.
A ${DDNS_IP}
\$ORIGIN ${DDNS_DOMAIN}.
\$TTL ${DDNS_DEFAULT_TTL}
EOF
fi
# If /var/cache/bind is a volume, permissions are probably not ok
chown root:bind /var/cache/bind
chown bind:bind /var/cache/bind/*
chmod 770 /var/cache/bind
chmod 644 /var/cache/bind/*