Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
10 changes: 8 additions & 2 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,7 +263,10 @@ def updateIPs(ips):
config = None
try:
with open(os.path.join(CONFIG_PATH, "config.json")) as config_file:
config = json.loads(config_file.read())
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("😡 Error reading config.json")
# wait 10 seconds to prevent excessive logging on docker auto restart
Expand Down
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}/../