mirror of
https://github.com/napnap75/multiarch-docker-images.git
synced 2026-02-05 02:18:59 +01:00
Added the missing containers from rpi-docker-images
This commit is contained in:
8
gandi/Dockerfile
Normal file
8
gandi/Dockerfile
Normal 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
20
gandi/README.md
Normal file
@@ -0,0 +1,20 @@
|
||||
Docker image to automatically update Gandi DNS with the current IP adress
|
||||
|
||||
# Status
|
||||
[](https://github.com/napnap75/rpi-docker-images/) [](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
43
gandi/updatedns.sh
Normal 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
|
||||
Reference in New Issue
Block a user