Added the missing containers from rpi-docker-images

This commit is contained in:
2021-04-24 13:00:00 +02:00
parent ee7613803d
commit bf41bdbb21
11 changed files with 408 additions and 1 deletions

8
gandi/Dockerfile Normal file
View File

@@ -0,0 +1,8 @@
FROM alpine:latest
ADD updatedns.sh /usr/bin/updatedns.sh
RUN apk add --no-cache curl jq \
&& chmod +x /usr/bin/updatedns.sh
CMD /usr/bin/updatedns.sh

20
gandi/README.md Normal file
View File

@@ -0,0 +1,20 @@
Docker image to automatically update Gandi DNS with the current IP adress
# Status
[![Github link](https://assets-cdn.github.com/favicon.ico)](https://github.com/napnap75/rpi-docker-images/) [![Docker hub link](https://www.docker.com/favicon.ico)](https://hub.docker.com/r/napnap75/rpi-gandi/)
# Content
This image is based [my own Alpine Linux base image](https://hub.docker.com/r/napnap75/rpi-alpine-base/).
This image contains :
- the python Gandi CLI for the v4 version
- curl and jq to access Gandi REST API for the v5 version
# Usage
Use this image to update a DNS record to the current IP of the host: `docker run -e GANDI_API_KEY="YOUR GANDI API KEY" -e GANDI_HOST="THE HOST NAME IN THE GANDI DOMAIN" -e GANDI_DOMAIN="YOUR GANDI DOMAIN" --name gandi napnap75/rpi-gandi:latest`
Use the following images :
- `napnap75/rpi-gandi:v4` if you use the v4 version of Gandi
- `napnap75/rpi-gandi:v5` or `napnap75/rpi-gandi:latest` if you use the v5 version of Gandi
Every 5 minutes, the image will automatically check the current IP address of the host and, if necessary, update the DNS.

43
gandi/updatedns.sh Normal file
View File

@@ -0,0 +1,43 @@
#!/bin/bash
# First check if the gandi cli is properly configured, otherwise configure it
while true ; do
# Get my current IP
my_ip=$(curl -s https://api.ipify.org)
# Get my currently registered IP
current_record=$(curl -s -H"X-Api-Key: $GANDI_API_KEY" https://dns.api.gandi.net/api/v5/domains/$GANDI_DOMAIN/records | jq -c '.[] | select(.rrset_name == "'$GANDI_HOST'") | select(.rrset_type == "A")')
current_ip=$(echo $current_record | jq -r '.rrset_values[0]')
# Check if both IP addresses are correct
if [[ "$my_ip" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ && "$current_ip" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]] ; then
# If they do not match, change it (and keep the TTL and TYPE)
if [[ "$my_ip" != "$current_ip" ]]; then
echo "Updating $GANDI_HOST.$GANDI_DOMAIN record with IP $my_ip"
current_ttl=$(echo $current_record | jq -r '.rrset_ttl')
curl -s -X PUT -H "Content-Type: application/json" -H "X-Api-Key: $GANDI_API_KEY" -d '{"rrset_ttl": '$current_ttl', "rrset_values":["'$my_ip'"]}' https://dns.api.gandi.net/api/v5/domains/$GANDI_DOMAIN/records/$GANDI_HOST/A
# If the update was OK
if [[ $? == 0 ]] ; then
# Send a notification to Slack
if [[ "$SLACK_URL" != "" ]] ; then
curl -o /dev/null -s -X POST -d "payload={\"username\": \"gandi\", \"icon_emoji\": \":dart:\", \"text\": \"New IP $my_ip for host $GANDI_HOST.$GANDI_DOMAIN\"}" $SLACK_URL
fi
# Send a notification to Healthchecks
if [[ "$HEALTHCHECKS_URL" != "" ]] ; then
curl -o /dev/null -s -m 10 --retry 5 $HEALTHCHECKS_URL
fi
fi
else
# Send a notification to Healthchecks
if [[ "$HEALTHCHECKS_URL" != "" ]] ; then
curl -o /dev/null -s -m 10 --retry 5 $HEALTHCHECKS_URL
fi
fi
fi
# Wait 5 minutes
sleep 300
done