Skip to content

Commit

Permalink
Merge branch 'master' of github.com:timothymiller/cloudflare-ddns
Browse files Browse the repository at this point in the history
  • Loading branch information
Nevah5 committed Sep 3, 2024
2 parents 0453c85 + f0d9510 commit b29cbc7
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 15 deletions.
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,8 @@ updates:
directory: '/'
schedule:
interval: 'daily'

- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'daily'
11 changes: 6 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ FROM python:alpine AS base
FROM base AS dependencies
# install dependencies
COPY requirements.txt .
RUN pip install -r requirements.txt
RUN pip install --user -r requirements.txt

#
# ---- Release ----
FROM dependencies AS release
# copy project source file(s)
FROM base AS release
# copy installed dependencies and project source file(s)
WORKDIR /
COPY --from=dependencies /root/.local /root/.local
COPY cloudflare-ddns.py .
CMD ["python", "-u", "/cloudflare-ddns.py", "--repeat"]
CMD ["python", "-u", "/cloudflare-ddns.py", "--repeat"]
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,20 @@ If you have multiple IP addresses and want to load balance between them, you can
}
```

### Docker environment variable support

Define environmental variables starts with `CF_DDNS_` and use it in config.json

For ex:

```json
{
"cloudflare": [
{
"authentication": {
"api_token": "${CF_DDNS_API_TOKEN}",
```

### 🧹 Optional features

`purgeUnknownRecords` removes stale DNS records from Cloudflare. This is useful if you have a dynamic DNS record that you no longer want to use. If you have a dynamic DNS record that you no longer want to use, you can set `purgeUnknownRecords` to `true` and the script will remove the stale DNS record from Cloudflare.
Expand Down
18 changes: 12 additions & 6 deletions cloudflare-ddns.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

__version__ = "1.0.2"

from string import Template

import json
import os
import signal
Expand All @@ -17,7 +19,8 @@
import requests

CONFIG_PATH = os.environ.get('CONFIG_PATH', os.getcwd())

# Read in all environment variables that have the correct prefix
ENV_VARS = {key: value for (key, value) in os.environ.items() if key.startswith('CF_DDNS_')}

class GracefulExit:
def __init__(self):
Expand Down Expand Up @@ -260,8 +263,11 @@ def updateIPs(ips):
config = None
try:
with open(os.path.join(CONFIG_PATH, "config.json")) as config_file:
config = json.loads(config_file.read())
except Exception as e:
if len(ENV_VARS) != 0:
config = json.loads(Template(config_file.read()).safe_substitute(ENV_VARS))
else:
config = json.loads(config_file.read())
except:
print(f"😡 Error reading config.json {str(e)}")
# wait 10 seconds to prevent excessive logging on docker auto restart
time.sleep(10)
Expand All @@ -286,8 +292,8 @@ def updateIPs(ips):
print(
"⚙️ No config detected for 'ttl' - defaulting to 300 seconds (5 minutes)")
if ttl < 30:
ttl = 30 #
print("⚙️ TTL is too low - defaulting to 30 seconds")
ttl = 1 #
print("⚙️ TTL is too low - defaulting to 1 (auto)")
if (len(sys.argv) > 1):
if (sys.argv[1] == "--repeat"):
if ipv4_enabled and ipv6_enabled:
Expand All @@ -310,4 +316,4 @@ def updateIPs(ips):
print("❓ Unrecognized parameter '" +
sys.argv[1] + "'. Stopping now.")
else:
updateIPs(getIPs())
updateIPs(getIPs())
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
requests==2.28.2
requests==2.31.0
3 changes: 2 additions & 1 deletion scripts/docker-build-all.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/bin/bash
docker buildx build --platform linux/ppc64le,linux/s390x,linux/386,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/amd64 --tag timothyjmiller/cloudflare-ddns:latest ../
BASH_DIR=$(dirname $(realpath "${BASH_SOURCE}"))
docker buildx build --platform linux/ppc64le,linux/s390x,linux/386,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/amd64 --tag timothyjmiller/cloudflare-ddns:latest ${BASH_DIR}/../
# TODO: Support linux/riscv64
3 changes: 2 additions & 1 deletion scripts/docker-build.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/bash
docker build --platform linux/amd64 --tag timothyjmiller/cloudflare-ddns:latest ../
BASH_DIR=$(dirname $(realpath "${BASH_SOURCE}"))
docker build --platform linux/amd64 --tag timothyjmiller/cloudflare-ddns:latest ${BASH_DIR}/../
3 changes: 2 additions & 1 deletion scripts/docker-publish.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
#!/bin/bash
docker buildx build --platform linux/ppc64le,linux/s390x,linux/386,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/amd64 --tag timothyjmiller/cloudflare-ddns:latest --push ../
BASH_DIR=$(dirname $(realpath "${BASH_SOURCE}"))
docker buildx build --platform linux/ppc64le,linux/s390x,linux/386,linux/arm/v6,linux/arm/v7,linux/arm64/v8,linux/amd64 --tag timothyjmiller/cloudflare-ddns:latest --push ${BASH_DIR}/../

0 comments on commit b29cbc7

Please sign in to comment.