Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added proxy, ttl and type support for the domain records #11

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
5 changes: 4 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,7 @@ CF_API_TOKEN=your_account_api_token
CF_ZONE_ID=your_cf_zone_id
DNS_RECORD_COMMENT_KEY=your_record_comment
DOMAINS_FILE_PATH=.\domains.json
SCHEDULE_MINUTES=60
SCHEDULE_MINUTES=5
PROXIED=True
TYPE=A
TTL=1
32 changes: 28 additions & 4 deletions .github/workflows/pylint.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,45 @@ on:
workflow_dispatch:
push:
pull_request:

env:
CF_ZONE_ID: ${{ secrets.CF_ZONE_ID }}
CF_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
DNS_RECORD_COMMENT_KEY: ${{ secrets.DNS_RECORD_COMMENT_KEY }}
DOMAINS_FILE_PATH: ${{ secrets.DOMAINS_FILE_PATH }}
DOMAINS: ${{ secrets.DOMAINS }}
SCHEDULE_MINUTES: "5"
TTL: "1"
PROXIED: "True"
TYPE: "A"
UPDATE_TYPE: "False"
UPDATE_PROXY: "False"
UPDATE_TTL: "False"

jobs:
build:
name: Run tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v3
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pylint
pip install pylint pytest pytest-md pytest-emoji
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Analysing the code with pylint
run: |
pylint $(git ls-files '*.py')
pylint $(git ls-files '*.py')
- name: Run pytest
uses: pavelzw/pytest-action@v2.2.0
with:
verbose: true
emoji: true
job-summary: true
custom-arguments: 'functions.py -q'
click-to-expand: true
report-title: 'Test Report'
4 changes: 1 addition & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
.env
domains.json
dns_updater.log
domains.json
scripts/*
.vscode/
__pycache__/
21 changes: 18 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
FROM python:3.11-slim
# 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 functions.py /app
COPY requirements.txt /app
COPY domains.json /app

RUN pip install --no-cache-dir requests schedule
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
13 changes: 0 additions & 13 deletions domains.example.json

This file was deleted.

31 changes: 31 additions & 0 deletions domains.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"zones": [
{
"id": "$CF_ZONE_ID",
"domains":
[
{
"name": "proxymanager.example.com"
},
{
"name": "portainer.example.com"
},
{
"name": "pihole.example.com"
},
{
"name": "myvpn.example.com"
},
{
"name": "plex.example.com"
},
{
"name": "jellyfin.example.com"
},
{
"name": "example.com"
}
]
}
]
}
Loading
Loading