Cloudflare automatic DNS update for homelab

Search for a command to run...

No comments yet. Be the first to comment.
Policyer is an open-source project (more like a vision) I created after being inspired by policy engines that become very popular lately (OPA,Checkov)Policyer going to focus on providing a platform to run and create meaningful reports, data engagemen...
Your team has 14 versions of the same code review skill across 5 repos, with no way to sync them. when one improves, the others don't. drop a folder in .claude/skills/ and pray nothing drifts. source

AI agents are unreasonably good at writing SQL. They get specific error messages, fix their own mistakes in one retry, and can introspect query performance with EXPLAIN ANALYZE before you even ask. No

n8n has over 400 integrations. Zapier claims 7,000+. Every single one was hand-built, tested against a moving API, and will eventually break when that API ships a v2. The entire workflow automation in

Part of the "Your Next Startup" series, where I break down startup ideas I think are worth building. Auth0 sold for \(6.5B. Okta is worth \)15B+. CyberArk, Delinea, BeyondTrust, all printing money fro

For as long as software has existed, we've been building two doors into our systems. Door one: the UI, a carefully designed surface where humans point, click, and occasionally rage-quit. Door two: the

First of all, I love Cloudflare, I think they have a great product, I use Cloudflare to manage all my DNS, anyone that has a homelab setup knows you need to figure out a way to keep Cloudflare IP update if your home IP is changed, there are many great solutions out there but I love to create my own tools, so I created cloudflaresync.
My home lab setup is a set of docker-compose files, everything is dockerized so this was the obvious choice, I'm trying to learn Golang so written in Go, and the code is very simple, but taylormade to my need.
# docker-compose
version: '3.4'
services:
cloudflaresync:
image: niradler/cloudflaresync
env_file:
- .env
The code is very straightforward, we get the configuration from a set of env vars, and configure a cron task to run every x time to update DNS records with new IP, I'm also using it to create new records when a new service is created.
// main.go
package main
import (
...
"github.com/cloudflare/cloudflare-go"
"github.com/joho/godotenv"
"github.com/robfig/cron/v3"
)
....
func main() {
err := godotenv.Load()
if err != nil {
log.Println("Error loading .env file")
}
updateRecords()
log.Println("Start cron", time.Now())
cronExpression, exist := os.LookupEnv("CRON")
if !exist {
cronExpression = "0 * * * *"
}
log.Println("cron:", cronExpression)
c := cron.New()
id, err := c.AddFunc(cronExpression, updateRecords)
if err != nil {
log.Fatal("cron AddFunc error:", err)
}
log.Println("cron id:", id)
c.Start()
log.Println("Cron Info: ", c.Entries())
go forever()
quitChannel := make(chan os.Signal, 1)
signal.Notify(quitChannel, syscall.SIGINT, syscall.SIGTERM)
<-quitChannel
fmt.Println("done")
}
Supported env vars:
CLOUDFLARE_API_TOKEN=<key>
CLOUDFLARE_DOMAIN=example.com
CLOUDFLARE_SUB_DOMAINS=test,home
CRON=*/2 * * * *
PROXIED=true
Running example for raspberry pi.
docker run --name cloudflaresync --env CLOUDFLARE_API_TOKEN=<key> --env CLOUDFLARE_SUB_DOMAINS=<app,home> --env CLOUDFLARE_DOMAIN=<example.com> --restart unless-stopped niradler/cloudflaresync:armv7
Updated to automatically update record from container label, check out the repo for more details https://github.com/niradler/cloudflaresync
version: "3.5"
services:
cloudflaresync:
image: niradler/cloudflaresync:latest
restart: unless-stopped
environment:
CLOUDFLARE_API_TOKEN: "${CLOUDFLARE_API_TOKEN}"
CLOUDFLARE_DOMAIN: "${DOMAIN}"
CLOUDFLARE_SUB_DOMAINS: "${SUB_DOMAINS}"
DOCKER_DAEMON: 'true'
labels:
- homepage.show=true
- homepage.description=cloudflaresync
- homepage.title=cloudflaresync
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
version: "3.5"
services:
adminer:
image: adminer:latest
labels:
- cloudflaresync.name=adminer
will automatically create a record adminer.domain