diff --git a/.dockerignore b/.dockerignore index 4c49bd7..51defbe 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1 +1,35 @@ +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/go/build-context-dockerignore/ + .env +**/.DS_Store +**/__pycache__ +**/.venv +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/bin +**/charts +**/docker-compose* +**/compose.y*ml +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md diff --git a/.gitignore b/.gitignore index a9d4cd4..4b0c5be 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ dns_updater.log scripts/* .vscode/ +__pycache__/ diff --git a/Dockerfile b/Dockerfile index 3ca2a0d..4e4115a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,24 @@ +# syntax=docker/dockerfile:1 FROM python:alpine +# Prevents Python from writing pyc files. +ENV PYTHONDONTWRITEBYTECODE=1 + +# Keeps Python from buffering stdout and stderr to avoid situations where +# the application crashes without emitting any logs due to buffering. +ENV PYTHONUNBUFFERED=1 + WORKDIR /app +# Copy relevant files into the container COPY main.py /app -COPY domains.json /app +COPY functions.py /app COPY requirements.txt /app +COPY domains.json /app -RUN pip install --no-cache-dir -r /app/requirements.txt +RUN --mount=type=cache,target=/root/.cache/pip \ + --mount=type=bind,source=requirements.txt,target=requirements.txt \ + python -m pip install -r requirements.txt -CMD ["python", "main.py"] +# Run the application. +CMD ["python", "main.py"] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 7c65f82..e79cecb 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,33 @@ +#Docker compose for cloudflare-dns-updater +version: "3.6" services: - dns-updater: - # Uncomment this to use an image instead of building locally - # image: your-image-tag - # Uncomment this to build locally - build: . - env_file: - - .env - \ No newline at end of file + cloudlfare-dns-updater: + image: "cloudflare-dns-updater:latest" + container_name: "cloudlfare-dns-updater" + volumes: + - app-data:/app # optional unless using the domains.json file and DOMAINS_FILE_PATH variable + environment: + CF_API_TOKEN: "YOUR_API_TOKEN" # Recomended to create a token for the zones, not use the main token + CF_ZONE_ID: "YOUR_ZONE_ID1,YOUR_ZONE_ID2" # Can be only 1 zone ID (usually is) + # Choose the method in which you get your domain records: + # You must choose one method + # DOMAINS_FILE_PATH is not needed if the DOMAINS or DNS_RECORD_COMMENT_KEY variables are set. + # Edit the domains.json according to the example file in the mounted volume. + # If you don't mount a volume, you cannot use the domains.json file and DOMAINS_FILE_PATH variable. + + DNS_RECORD_COMMENT_KEY: "Comm1,Comm2" # Any DNS reccord that has any of the comments specified here. Can be 1 comment + # DOMAINS: "domain.com,example1.domain.com,example2.domain.com" + # DOMAINS_FILE_PATH: .\domains.json + SCHEDULE_MINUTES: 5 + PROXIED: True # if proxied is set to True, TTL cannot be set/changed + TYPE: A # Supports either A, AAA or CNAME + TTL: 1 + restart: "unless-stopped" + +volumes: + app-data: + driver: local + driver_opts: + o: bind + type: none + device: /volume1/docker/cloudflare-dns-updater \ No newline at end of file diff --git a/functions.py b/functions.py index f130b30..a6d9bb4 100644 --- a/functions.py +++ b/functions.py @@ -33,6 +33,7 @@ DOMAINS_LIST = [] CF_ZONE_ID_LIST = [] DNS_RECORD_COMMENT_KEY_LIST = [] + # Calcualte values from above variables if DOMAINS is not None: DOMAINS_LIST = DOMAINS.split(',') @@ -386,6 +387,7 @@ def get_all_dns_records(): domains_list = get_dns_records_by_comments(CF_ZONE_ID_LIST, DNS_RECORD_COMMENT_KEY_LIST) for list_item in domains_list: domain_records += list_item + return domain_records if DOMAINS is not None: LOGGER.info( "Using list of DOMAINS=[%s] to find DNS records to update.",