A Dynamic DNS service for Cloudflare, supporting multiple DNS providers and IP discovery services.
699
A Dynamic DNS service for Cloudflare implemented with Clean Architecture and Adapter design pattern, supporting multiple DNS providers and IP discovery services.
src/
├── domain/ # Business logic and interfaces
│ ├── entities/ # Domain entities (IpRecord, DnsRecord)
│ ├── interfaces/ # Domain interfaces (IDnsProvider, IIpDiscoveryService)
│ └── services/ # Domain services (DdnsService)
├── infrastructure/ # External concerns
│ ├── adapters/ # Implementation of domain interfaces
│ │ ├── CloudflareDnsAdapter.ts
│ │ ├── MyIpDiscoveryAdapter.ts
│ │ └── MyIpComDiscoveryAdapter.ts
│ └── config/ # Configuration management
├── application/ # Application services
│ └── DdnsApplication.ts # Main application orchestrator
└── index.ts # Entry point
docker run -d \
--name cloudflare-ddns \
-e CLOUDFLARE_API_TOKEN=your_token \
-e CLOUDFLARE_ZONE_ID=your_zone_id \
-e CLOUDFLARE_DNS_RECORD_ID=your_record_id \
-e CLOUDFLARE_SUB_DOMAIN_NAME=your_subdomain \
-e CLOUDFLARE_TIME_SLEEP=60000 \
weerayuthmc/cloudflare-ddns:latest
# Clone the repository
git clone [email protected]:9mc/tools/cloudflare-ddns.git
cd cloudflare-ddns
# Copy and configure environment variables
cp .env .env.local
# Edit .env.local with your actual Cloudflare credentials
# Start the service with Docker Compose
docker compose up -d
# View logs
docker compose logs -f
# Stop the service
docker compose down
# Clone the repository
git clone [email protected]:9mc/tools/cloudflare-ddns.git
cd cloudflare-ddns/src
# Install dependencies
npm install
# Build the project
npm run build
# Set environment variables (see Configuration section)
# ...
# Start the service
npm start
Set the following environment variables:
| Variable | Description | Required |
|---|---|---|
CLOUDFLARE_API_TOKEN | Cloudflare API token with DNS edit permissions | Yes |
CLOUDFLARE_ZONE_ID | Zone ID from Cloudflare dashboard | Yes |
CLOUDFLARE_DNS_RECORD_ID | DNS record ID to update | Yes |
CLOUDFLARE_SUB_DOMAIN_NAME | Subdomain name (e.g., home.example.com) | Yes |
CLOUDFLARE_TIME_SLEEP | Check interval in milliseconds (default: 60000) | No |
For GitHub Actions deployment, see GitHub Actions Setup Guide for detailed instructions on configuring secrets and variables.
IDnsProvider:import { IDnsProvider } from '../../domain/interfaces/IDnsProvider';
export class NewDnsProviderAdapter implements IDnsProvider {
async updateDnsRecord(record: DnsRecord): Promise<DnsUpdateResult> {
// Implementation here
}
getName(): string {
return 'New DNS Provider';
}
}
DdnsApplication to use the new provider.IIpDiscoveryService:import { IIpDiscoveryService } from '../../domain/interfaces/IIpDiscoveryService';
export class NewIpServiceAdapter implements IIpDiscoveryService {
async getPublicIp(): Promise<string> {
// Implementation here
}
getName(): string {
return 'New IP Service';
}
}
DdnsApplication to use the new service.# Install dependencies
npm install
# Start development with hot reload
npm run dev
# Build the project
npm run build
# Clean build artifacts
npm run clean
The project includes a comprehensive CI/CD pipeline with:
The pipeline automatically deploys to the 9mcint server when changes are pushed to the main branch, ensuring the latest version is always running in production.
# Build for development
docker build -t weerayuthmc/cloudflare-ddns:dev .
# Build for production with multi-platform support
docker buildx build --platform linux/amd64,linux/arm64 -t weerayuthmc/cloudflare-ddns:latest .
# Using Docker Compose for local development
docker compose build
# Using Docker Compose with custom environment file
docker compose --env-file .env.local up -d
MIT License - see LICENSE file for details.
Content type
Image
Digest
sha256:20a4fd964…
Size
67.4 MB
Last updated
8 months ago
docker pull weerayuthmc/cloudflare-ddns