mirror of
https://github.com/timothymiller/cloudflare-ddns.git
synced 2026-03-21 22:48:57 -03:00
support for environmental substitution in config.json using python Template
refer comment in #35
This commit is contained in:
14
README.md
14
README.md
@@ -213,9 +213,19 @@ Do not include the base domain name in your `subdomains` config. Do not use the
|
||||
}
|
||||
```
|
||||
|
||||
### 🗣️ Call to action: Docker environment variable support
|
||||
### Docker environment variable support
|
||||
|
||||
I am looking for help adding Docker environment variable support to this project. If interested, check out [this comment](https://github.com/timothymiller/cloudflare-ddns/pull/35#issuecomment-974752476) and open a PR.
|
||||
Define environmental variables starts with `CF_DDNS_` and use it in config.json
|
||||
|
||||
For ex:
|
||||
|
||||
```json
|
||||
{
|
||||
"cloudflare": [
|
||||
{
|
||||
"authentication": {
|
||||
"api_token": "${CF_DDNS_API_TOKEN}",
|
||||
```
|
||||
|
||||
## 🐳 Deploy with Docker Compose
|
||||
|
||||
|
||||
@@ -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):
|
||||
@@ -216,7 +219,7 @@ if __name__ == '__main__':
|
||||
config = None
|
||||
try:
|
||||
with open(os.path.join(CONFIG_PATH, "config.json")) as config_file:
|
||||
config = json.loads(config_file.read())
|
||||
config = json.loads(Template(config_file.read()).safe_substitute(ENV_VARS))
|
||||
except:
|
||||
print("😡 Error reading config.json")
|
||||
# wait 10 seconds to prevent excessive logging on docker auto restart
|
||||
|
||||
@@ -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