From 1e55144bf252f4074f5e0a3176ad44f138912dc1 Mon Sep 17 00:00:00 2001 From: timothymiller Date: Wed, 5 Aug 2020 13:30:33 -0400 Subject: [PATCH] Added docker-compose build steps to README.md --- .vscode/settings.json | 2 +- Dockerfile | 1 - README.md | 48 +++++++++++++++++++++++++++++++++++++++---- build-docker-image.sh | 2 +- cloudflare-ddns.py | 9 ++------ docker-compose.yml | 13 ++++++++++++ 6 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 docker-compose.yml diff --git a/.vscode/settings.json b/.vscode/settings.json index 31e2e40..856150f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -9,7 +9,7 @@ ".vscode": true, "LICENSE": true, "requirements.txt": true, - "build-docker-image.sh": true, + "build-docker-image.sh": false, ".gitignore": true, "Dockerfile": false, "start-sync.sh": false, diff --git a/Dockerfile b/Dockerfile index 4cacd49..65ea052 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,5 +14,4 @@ FROM dependencies AS release # copy project file(s) WORKDIR / COPY cloudflare-ddns.py . -COPY config.json . CMD ["python", "/cloudflare-ddns.py", "--repeat"] \ No newline at end of file diff --git a/README.md b/README.md index 09e02ea..70ebeb9 100755 --- a/README.md +++ b/README.md @@ -45,14 +45,54 @@ Alternatively, you can use the traditional API keys by setting appropriate value ## :fax: Hosting multiple domains on the same IP? You can save yourself some trouble when hosting multiple domains pointing to the same IP address (in the case of Traefik) by defining one A & AAAA record 'ddns.example.com' pointing to the IP of the server that will be updated by this DDNS script. For each subdomain, create a CNAME record pointing to 'ddns.example.com'. Now you don't have to manually modify the script config every time you add a new subdomain to your site! -## :whale: Deploy to Docker +## :whale: Deploy with Docker Compose -Create a config.json file with your production credentials and run the build-docker-image script. +Modify the host file path of config.json inside the volumes section of docker-compose.yml. + +```yml +version: "3.7" +services: + cloudflare-ddns: + image: timothymiller/cloudflare-ddns:latest + container_name: cloudflare-ddns + security_opt: + - no-new-privileges:true + environment: + - PUID=1000 + - PGID=1000 + volumes: + - /EDIT/YOUR/PATH/HERE/config.json:/config.json + restart: unless-stopped +``` + +### :running: Running + +From the project root directory + +```bash +docker-compose up -d +``` + +### Building from source + +Create a config.json file with your production credentials. + +Give build-docker-image.sh permission to execute. + +```bash +sudo chmod +x ./build-docker-image.sh +``` + +At project root, run the build-docker-image.sh script. ```bash -chmod +x ./build-docker-image.sh ./build-docker-image.sh -docker run -d timothymiller/cloudflare_ddns:latest +``` + +#### Run the locally compiled version + +```bash +docker run -d timothyjmiller/cloudflare_ddns:latest ``` ## :penguin: (legacy) Linux + cron instructions (all distros) diff --git a/build-docker-image.sh b/build-docker-image.sh index fabbd86..e35d0c0 100755 --- a/build-docker-image.sh +++ b/build-docker-image.sh @@ -1 +1 @@ -docker build -t timothymiller/cloudflare-ddns:latest . \ No newline at end of file +docker build -t timothyjmiller/cloudflare-ddns:latest . \ No newline at end of file diff --git a/cloudflare-ddns.py b/cloudflare-ddns.py index 5669008..5274e26 100755 --- a/cloudflare-ddns.py +++ b/cloudflare-ddns.py @@ -1,7 +1,5 @@ -import requests -import json -import sys -import os +import requests, json, sys, os +import time, traceback PATH = os.getcwd() + "/" version = float(str(sys.version_info[0]) + "." + str(sys.version_info[1])) @@ -104,9 +102,6 @@ def cf_api(endpoint, method, config, headers={}, data=False): return response.json() -# Scheduling -import time, traceback - def every(delay, task): next_time = time.time() + delay while True: diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..07ec82a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,13 @@ +version: "3.7" +services: + cloudflare-ddns: + image: timothymiller/cloudflare-ddns:latest + container_name: cloudflare-ddns + security_opt: + - no-new-privileges:true + environment: + - PUID=1000 + - PGID=1000 + volumes: + - /EDIT/YOUR/PATH/HERE/config.json:/config.json + restart: unless-stopped \ No newline at end of file