dockerize

This commit is contained in:
Tim Lappe 2025-03-23 12:10:48 +01:00
parent 88d02078b3
commit ff3d3c7a38
5 changed files with 51 additions and 5 deletions

20
Dockerfile Normal file
View File

@ -0,0 +1,20 @@
FROM debian:bookworm
RUN apt-get update && apt-get install -y ca-certificates
RUN useradd -m dyndns
COPY entrypoint.sh /home/dyndns/entrypoint.sh
RUN chmod +x /home/dyndns/entrypoint.sh
COPY DynDNS /home/dyndns/DynDNS
COPY .env /home/dyndns/.env
RUN chown -R dyndns:dyndns /home/dyndns
RUN chmod +x /home/dyndns/DynDNS
USER dyndns
WORKDIR /home/dyndns
CMD ["./entrypoint.sh"]

BIN
DynDNS

Binary file not shown.

6
docker-compose.yml Normal file
View File

@ -0,0 +1,6 @@
services:
dyndns:
build:
context: .
dockerfile: Dockerfile
restart: always

13
entrypoint.sh Normal file
View File

@ -0,0 +1,13 @@
#!/bin/bash
# Function to run the DynDNS update
run_dyndns() {
echo "Running DynDNS update at $(date)"
./DynDNS
}
# Then run every 5 minutes
while true; do
run_dyndns
sleep 300
done

View File

@ -7,17 +7,20 @@ import (
)
func ReadIp() (string, error) {
ip, err := _readIpFromIpify()
if err == nil {
fmt.Printf("Reading IP address ...\n")
ip, errIpify := _readIpFromIpify()
if errIpify == nil {
fmt.Printf("IP address from ipify: %s\n", ip)
return ip, nil
}
ip, err = _readIpFromIdentMe()
if err == nil {
ip, errIdentMe := _readIpFromIdentMe()
if errIdentMe == nil {
fmt.Printf("IP address from identme: %s\n", ip)
return ip, nil
}
return "", fmt.Errorf("error getting IP from all services: %v", err)
return "", fmt.Errorf("error getting IP from all services: %v, %v", errIpify, errIdentMe)
}
func _readIpFromIpify() (string, error) {
@ -35,6 +38,8 @@ func _readIpFromIpify() (string, error) {
return "", fmt.Errorf("error reading IP from ipify: %v", err)
}
fmt.Printf("IP address from ipify: %s\n", string(ip))
return string(ip), nil
}
@ -53,5 +58,7 @@ func _readIpFromIdentMe() (string, error) {
return "", fmt.Errorf("error reading IP from identme: %v", err)
}
fmt.Printf("IP address from identme: %s\n", string(ip))
return string(ip), nil
}