Merge pull request #117 from arulrajnet/env-support

[feature] Support for environmental substitution in config.json
This commit is contained in:
Timothy Miller
2024-08-23 13:55:33 -04:00
committed by GitHub
5 changed files with 28 additions and 5 deletions

View File

@@ -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 ### 🧹 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. `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.

View File

@@ -8,6 +8,8 @@
__version__ = "1.0.2" __version__ = "1.0.2"
from string import Template
import json import json
import os import os
import signal import signal
@@ -17,7 +19,8 @@ import time
import requests import requests
CONFIG_PATH = os.environ.get('CONFIG_PATH', os.getcwd()) 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: class GracefulExit:
def __init__(self): def __init__(self):
@@ -260,6 +263,9 @@ if __name__ == '__main__':
config = None config = None
try: try:
with open(os.path.join(CONFIG_PATH, "config.json")) as config_file: 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()) config = json.loads(config_file.read())
except: except:
print("😡 Error reading config.json") print("😡 Error reading config.json")

View File

@@ -1,3 +1,4 @@
#!/bin/bash #!/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 # TODO: Support linux/riscv64

View File

@@ -1,2 +1,3 @@
#!/bin/bash #!/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}/../

View File

@@ -1,2 +1,3 @@
#!/bin/bash #!/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}/../