Refactor DDNS updater: switch to Alpine, support multiple domains

- Replace golang base image with alpine for smaller footprint
- Add bash/curl dependencies explicitly
- Refactor script to support multiple domains via arrays
- Improve logging with timestamps and status messages
- Simplify docker-compose configuration
- Remove obsolete build scripts and env files

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
primal
2026-01-26 15:40:55 -05:00
parent 484426a1cd
commit 97fd399b4d
7 changed files with 49 additions and 35 deletions
+9 -4
View File
@@ -1,4 +1,9 @@
FROM golang:latest
WORKDIR /root
ADD ddns.bash .
CMD [ "/root/ddns.bash" ]
FROM alpine:latest
RUN apk add --no-cache bash curl
WORKDIR /app
COPY ddns.bash .
RUN chmod +x ddns.bash
CMD ["./ddns.bash"]
-2
View File
@@ -1,2 +0,0 @@
PROJECT=apps
SERVICE=ddns
-2
View File
@@ -1,2 +0,0 @@
docker pull golang:latest
docker build -t primal/ddns .
-12
View File
@@ -1,12 +0,0 @@
networks:
ddns:
services:
ddns:
build: .
env_file:
- env
hostname: apps_ddns
image: ${IMAGE}:${VERSION}
networks:
- ddns
+29 -13
View File
@@ -1,16 +1,32 @@
#!/bin/bash
DOMN=primal.host
PASS=35f5fa4e1fc04d539260a4afaeb42371 \
IP0=''
# Namecheap Dynamic DNS Updater
# https://www.namecheap.com/support/knowledgebase/article.aspx/29/11/how-to-dynamically-update-the-hosts-ip-with-an-https-request/
declare -a domains
domains=( "primal.host" )
declare -a ipAddrs
ipAddrs=( "0.0.0.0" )
declare -a passwords
passwords=( "4e6b91f434284c6d9261d5779b1d560f" )
while true ; do
IP1=$(curl --no-progress-meter 'https://api.ipify.org?format=text')
if [[ "${IP1}" != "${IP0}" && "${IP1}" != '' ]] ; then
OP0=$(curl --no-progress-meter -X GET -d 'host=@' -d "domain=${DOMN}" -d "password=${PASS}" -d "ip=${IP1}" -G 'https://dynamicdns.park-your-domain.com/update')
OP1=$(curl --no-progress-meter -X GET -d 'host=*' -d "domain=${DOMN}" -d "password=${PASS}" -d "ip=${IP1}" -G 'https://dynamicdns.park-your-domain.com/update')
echo $(date) ${IP0} ${IP1}
IP0=${IP1}
else
echo $(date) ${IP0} ${IP1} .
fi
sleep 3661
ipPublic=$(curl --no-progress-meter 'https://api.ipify.org?format=text')
echo "$(date '+%Y-%m-%d %H:%M:%S') Public IP: ${ipPublic}"
for i in ${!domains[@]} ; do
domain=${domains[$i]}
ipAddr=${ipAddrs[$i]}
password=${passwords[$i]}
if [[ "$ipPublic" != "$ipAddr" ]] ; then
for host in '@' '*' ; do
response="$(curl --no-progress-meter -G -d "host=$host" -d "domain=$domain" -d "password=$password" -d "ip=$ipPublic" https://dynamicdns.park-your-domain.com/update)"
if [[ $(echo $response | grep -c "<ErrCount>0</ErrCount>" -) -ne 1 ]] ; then
echo " ERROR updating ${host}.${domain}: $response"
else
ipAddrs[${i}]="$ipPublic"
echo " Updated ${host}.${domain} -> ${ipPublic}"
fi
done
fi
done
sleep 3600
done
+11
View File
@@ -0,0 +1,11 @@
services:
ddns:
build: .
container_name: ddns
restart: unless-stopped
networks:
- proxy
networks:
proxy:
external: true
-2
View File
@@ -1,2 +0,0 @@
VERSION=v1.0.0
IMAGE=gitea.primal.host/wehrv/ddns