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:
+9
-4
@@ -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"]
|
||||
|
||||
@@ -1,12 +0,0 @@
|
||||
networks:
|
||||
ddns:
|
||||
|
||||
services:
|
||||
ddns:
|
||||
build: .
|
||||
env_file:
|
||||
- env
|
||||
hostname: apps_ddns
|
||||
image: ${IMAGE}:${VERSION}
|
||||
networks:
|
||||
- ddns
|
||||
@@ -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}
|
||||
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
|
||||
echo $(date) ${IP0} ${IP1} .
|
||||
ipAddrs[${i}]="$ipPublic"
|
||||
echo " Updated ${host}.${domain} -> ${ipPublic}"
|
||||
fi
|
||||
sleep 3661
|
||||
done
|
||||
fi
|
||||
done
|
||||
sleep 3600
|
||||
done
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
services:
|
||||
ddns:
|
||||
build: .
|
||||
container_name: ddns
|
||||
restart: unless-stopped
|
||||
networks:
|
||||
- proxy
|
||||
|
||||
networks:
|
||||
proxy:
|
||||
external: true
|
||||
Reference in New Issue
Block a user