Skip to content

Commit

Permalink
Final update and usable Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
SpasovskiFilip committed Aug 18, 2024
1 parent bcff5ad commit 2651442
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 11 deletions.
34 changes: 34 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dns_updater.log
scripts/*
.vscode/
__pycache__/
19 changes: 16 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
40 changes: 32 additions & 8 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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

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
2 changes: 2 additions & 0 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(',')
Expand Down Expand Up @@ -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.",
Expand Down

0 comments on commit 2651442

Please sign in to comment.