mirror of
https://github.com/timothymiller/cloudflare-ddns.git
synced 2026-03-21 22:48:57 -03:00
Merge pull request #117 from arulrajnet/env-support
[feature] Support for environmental substitution in config.json
This commit is contained in:
14
README.md
14
README.md
@@ -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.
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
|
||||
__version__ = "1.0.2"
|
||||
|
||||
from string import Template
|
||||
|
||||
import json
|
||||
import os
|
||||
import signal
|
||||
@@ -17,7 +19,8 @@ import time
|
||||
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):
|
||||
@@ -260,6 +263,9 @@ if __name__ == '__main__':
|
||||
config = None
|
||||
try:
|
||||
with open(os.path.join(CONFIG_PATH, "config.json")) as config_file:
|
||||
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")
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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}/../
|
||||
|
||||
@@ -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}/../
|
||||
|
||||
Reference in New Issue
Block a user