From 86976e51333811193e976c26122becdfdb26f595 Mon Sep 17 00:00:00 2001 From: Timothy Miller <46549361+timothymiller@users.noreply.github.com> Date: Sat, 30 Jul 2022 20:24:27 -0400 Subject: [PATCH] Added per-subdomain proxy flag to config.json --- README.md | 74 +++++++++++++---------------- cloudflare-ddns.py | 11 +++-- config-example.json | 23 +++++---- k8s/cloudflare-ddns-Deployment.yaml | 34 ------------- k8s/cloudflare-ddns.yml | 33 +++++++++++++ 5 files changed, 86 insertions(+), 89 deletions(-) delete mode 100644 k8s/cloudflare-ddns-Deployment.yaml create mode 100644 k8s/cloudflare-ddns.yml diff --git a/README.md b/README.md index bb8499d..4422f42 100755 --- a/README.md +++ b/README.md @@ -20,9 +20,9 @@ Stale, duplicate DNS records are removed for housekeeping. ## 📊 Stats -| Size | Downloads | Discord | -| ------------- | ------------- | ------------- | -| [![cloudflare-ddns docker image size](https://img.shields.io/docker/image-size/timothyjmiller/cloudflare-ddns?style=flat-square)](https://hub.docker.com/r/timothyjmiller/cloudflare-ddns "cloudflare-ddns docker image size") | [![Total DockerHub pulls](https://img.shields.io/docker/pulls/timothyjmiller/cloudflare-ddns?style=flat-square)](https://hub.docker.com/r/timothyjmiller/cloudflare-ddns "Total DockerHub pulls") | [![Official Discord Server](https://img.shields.io/discord/785778163887112192?style=flat-square)](https://discord.gg/UgGmwMvNxm "Official Discord Server") +| Size | Downloads | Discord | +| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | +| [![cloudflare-ddns docker image size](https://img.shields.io/docker/image-size/timothyjmiller/cloudflare-ddns?style=flat-square)](https://hub.docker.com/r/timothyjmiller/cloudflare-ddns 'cloudflare-ddns docker image size') | [![Total DockerHub pulls](https://img.shields.io/docker/pulls/timothyjmiller/cloudflare-ddns?style=flat-square)](https://hub.docker.com/r/timothyjmiller/cloudflare-ddns 'Total DockerHub pulls') | [![Official Discord Server](https://img.shields.io/discord/785778163887112192?style=flat-square)](https://discord.gg/UgGmwMvNxm 'Official Discord Server') | ## ⁉️ How Private & Secure? @@ -82,11 +82,11 @@ Some ISP provided modems only allow port forwarding over IPv4 or IPv6. In this c ## 📠 Hosting multiple subdomains on the same IP? -You can save yourself some trouble when hosting multiple domains pointing to the same IP address (in the case of Traefik) by defining one A & AAAA record 'ddns.example.com' pointing to the IP of the server that will be updated by this DDNS script. For each subdomain, create a CNAME record pointing to 'ddns.example.com'. Now you don't have to manually modify the script config every time you add a new subdomain to your site! +You can save yourself some trouble when hosting multiple domains pointing to the same IP address (in the case of Traefik) by defining one A & AAAA record 'ddns.example.com' pointing to the IP of the server that will be updated by this DDNS script. For each subdomain, create a CNAME record pointing to 'ddns.example.com'. Now you don't have to manually modify the script config every time you add a new subdomain to your site! ## 🌐 Hosting multiple domains (zones) on the same IP? -You can handle ddns for multiple domains (cloudflare zones) using the same docker container by separating your configs inside ```config.json``` like below: +You can handle ddns for multiple domains (cloudflare zones) using the same docker container by separating your configs inside `config.json` like below: ### ⚠️ Note @@ -97,35 +97,28 @@ Do not include the base domain name in your `subdomains` config. Do not use the "cloudflare": [ { "authentication": { - "api_token": "api_token_here", - "api_key": { - "api_key": "api_key_here", - "account_email": "your_email_here" - } + "api_token": "api_token_here", + "api_key": { + "api_key": "api_key_here", + "account_email": "your_email_here" + } }, "zone_id": "your_zone_id_here", "subdomains": [ - "", - "remove_or_replace_with_your_subdomain" - ], - "proxied": true - }, - { - "authentication": { - "api_token": "api_token_here", - "api_key": { - "api_key": "api_key_here", - "account_email": "your_email_here" - } - }, - "zone_id": "your_zone_id_here", - "subdomains": [ - "", - "remove_or_replace_with_your_subdomain" - ], - "proxied": true + { + "name": "", + "proxied": false + }, + { + "name": "remove_or_replace_with_your_subdomain", + "proxied": false + } + ] } - ] + ], + "a": true, + "aaaa": true, + "purgeUnknownRecords": false } ``` @@ -136,14 +129,14 @@ Pre-compiled images are available via [the official docker container on DockerHu Modify the host file path of config.json inside the volumes section of docker-compose.yml. ```yml -version: "3.7" +version: '3.7' services: cloudflare-ddns: image: timothyjmiller/cloudflare-ddns:latest container_name: cloudflare-ddns security_opt: - no-new-privileges:true - network_mode: "host" + network_mode: 'host' environment: - PUID=1000 - PGID=1000 @@ -166,38 +159,37 @@ docker-compose up -d ## 🐋 Kubernetes - Create config File -``` bash +```bash cp ../../config-example.json config.json ``` Edit config.jsonon (vim, nvim, nano... ) -``` bash + +```bash ${EDITOR} config.json ``` Create config file as Secret. -``` bash +```bash kubectl create secret generic config-cloudflare-ddns --from-file=config.json --dry-run=client -oyaml -n ddns > config-cloudflare-ddns-Secret.yaml ``` apply this secret -``` bash +```bash kubectl apply -f config-cloudflare-ddns-Secret.yaml rm config.json # recomended Just keep de secret on Kubernetes Cluster ``` apply this Deployment -``` bash +```bash kubectl apply -f cloudflare-ddns-Deployment.yaml ``` - ## 🐧 Deploy with Linux + Cron ### 🏃 Running (all distros) @@ -230,9 +222,9 @@ Docker Hub has experimental support for multi-architecture builds. Their officia 1. Choose build platform -- Multi-architecture (experimental) `docker-build-all.sh` +- Multi-architecture (experimental) `docker-build-all.sh` -- Linux/amd64 by default `docker-build.sh` +- Linux/amd64 by default `docker-build.sh` 2. Give your bash script permission to execute. diff --git a/cloudflare-ddns.py b/cloudflare-ddns.py index 445c50c..dea4c69 100755 --- a/cloudflare-ddns.py +++ b/cloudflare-ddns.py @@ -6,7 +6,7 @@ # A small, 🕵️ privacy centric, and ⚡ # lightning fast multi-architecture Docker image for self hosting projects. -__version__ = "1.0.1" +__version__ = "1.0.2" import json import os @@ -105,15 +105,16 @@ def commitRecord(ip): base_domain_name = response["result"]["name"] ttl = 300 # default Cloudflare TTL for subdomain in subdomains: - subdomain = subdomain.lower().strip() + name = subdomain["name"].lower().strip() fqdn = base_domain_name - if subdomain != '' and subdomain != '*' and subdomain != '@': - fqdn = subdomain + "." + base_domain_name + # Check if name provided is a reference to the root domain + if name != '' and name != '*' and name != '@': + fqdn = name + "." + base_domain_name record = { "type": ip["type"], "name": fqdn, "content": ip["ip"], - "proxied": option["proxied"], + "proxied": subdomain["proxied"], "ttl": ttl } dns_records = cf_api( diff --git a/config-example.json b/config-example.json index 2357030..99d537f 100755 --- a/config-example.json +++ b/config-example.json @@ -2,18 +2,23 @@ "cloudflare": [ { "authentication": { - "api_token": "api_token_here", - "api_key": { - "api_key": "api_key_here", - "account_email": "your_email_here" - } + "api_token": "api_token_here", + "api_key": { + "api_key": "api_key_here", + "account_email": "your_email_here" + } }, "zone_id": "your_zone_id_here", "subdomains": [ - "", - "remove_or_replace_with_your_subdomain" - ], - "proxied": false + { + "name": "", + "proxied": false + }, + { + "name": "remove_or_replace_with_your_subdomain", + "proxied": false + } + ] } ], "a": true, diff --git a/k8s/cloudflare-ddns-Deployment.yaml b/k8s/cloudflare-ddns-Deployment.yaml deleted file mode 100644 index 59f9d98..0000000 --- a/k8s/cloudflare-ddns-Deployment.yaml +++ /dev/null @@ -1,34 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: cloudflate-ddns -spec: - selector: - matchLabels: - app: cloudflate-ddns - - template: - metadata: - labels: - app: cloudflate-ddns - - spec: - containers: - - name: cloudflate-ddns - image: timothyjmiller/cloudflare-ddns:latest - #image: quay.io/arpagon/cloudflare-ddns:v1.0.0 - resources: - limits: - memory: "32Mi" - cpu: "50m" - env: - - name: CONFIG_PATH - value: "/etc/cloudflare-ddns/" - volumeMounts: - - mountPath: "/etc/cloudflare-ddns" - name: config-cloudflare-ddns - readOnly: true - volumes: - - name: config-cloudflare-ddns - secret: - secretName: config-cloudflare-ddns \ No newline at end of file diff --git a/k8s/cloudflare-ddns.yml b/k8s/cloudflare-ddns.yml new file mode 100644 index 0000000..6084c69 --- /dev/null +++ b/k8s/cloudflare-ddns.yml @@ -0,0 +1,33 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: cloudflare-ddns +spec: + selector: + matchLabels: + app: cloudflare-ddns + + template: + metadata: + labels: + app: cloudflare-ddns + + spec: + containers: + - name: cloudflare-ddns + image: timothyjmiller/cloudflare-ddns:latest + resources: + limits: + memory: '32Mi' + cpu: '50m' + env: + - name: CONFIG_PATH + value: '/etc/cloudflare-ddns/' + volumeMounts: + - mountPath: '/etc/cloudflare-ddns' + name: config-cloudflare-ddns + readOnly: true + volumes: + - name: config-cloudflare-ddns + secret: + secretName: config-cloudflare-ddns