Skip to content

Commit e5edcfa

Browse files
committed
added cloudflare api and zone registry
1 parent de3d49b commit e5edcfa

File tree

7 files changed

+941
-10
lines changed

7 files changed

+941
-10
lines changed

.goreleaser.yaml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,21 @@ snapshot:
3535

3636
release:
3737
header: |
38-
## Major Feature Update with Graft 🚀
38+
## Feature Update with Graft 🚀
3939
40+
### V2.1 Highlights:
41+
1. **Cloudflare API Integration**: Automated DNS zone mapping based on Traefik host labels.
42+
2. **Cloudflare Zone Registry**: Manage multiple Cloudflare accounts and zones with an interactive selection menu.
43+
3. **Bug Fixes**: Improved domain detection and duplicate record handling.
44+
45+
### V2 Highlights:
4046
This release introduces significant enhancements to Graft, moving from basic local-to-server deployments to a more robust CI/CD-driven workflow using GitHub Actions and our new `graft-hook` service.
4147
42-
### Key Highlights:
4348
1. **Git Remote Modes**: Move away from direct local-to-server channels. Deployments now go through GitHub Workflows and CI/CD channels.
4449
2. **Graft-Hook**: A new webhook service personalized specifically for Graft-based servers, maintaining a zero-config solution with proper security.
4550
3. **Automated GitHub Workflows**: Graft now generates production-ready workflows automatically from your `graft-compose.yml` context.
4651
4. **Enhanced Monitoring**: Easy CLI-based monitoring for `graft-hook`, including real-time build error logs.
47-
5. **Bug Fixes & UX**: Numerous performance improvements and user experience refinements.
52+
4853
footer: |
4954
---
5055
Released by **skssmd** using [GoReleaser](https://github.com/goreleaser/goreleaser).

COMMANDS.md

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,109 @@ graft sync compose -h # Upload only (no restart)
423423

424424
---
425425

426+
## DNS Mapping Commands
427+
428+
### `graft map`
429+
Automatically map all service domains to Cloudflare DNS records.
430+
431+
```bash
432+
graft map
433+
```
434+
435+
**What it does:**
436+
1. Parses `graft-compose.yml` to extract all Traefik `Host()` rules
437+
2. Detects the server's public IP address
438+
3. Prompts for Cloudflare API credentials (saved for future use)
439+
4. Verifies DNS ownership via Cloudflare API
440+
5. For each domain:
441+
- Checks if DNS record exists
442+
- Creates new A record if missing
443+
- Prompts to update if existing record points to different IP
444+
6. Displays summary of changes
445+
446+
**Requirements:**
447+
- Cloudflare API Token with DNS edit permissions
448+
- Zone ID for your domain
449+
- Services must have Traefik labels with `Host()` rules
450+
451+
**Example:**
452+
```bash
453+
$ graft map
454+
455+
🔍 Parsing docker-compose file...
456+
📋 Found 3 service(s) with domains:
457+
- frontend: app.example.com, www.example.com
458+
- backend: api.example.com
459+
- admin: admin.example.com
460+
461+
🌐 Detecting server IP...
462+
Detected IP: 203.0.113.42
463+
464+
🔐 Cloudflare API Token: ****
465+
🔐 Zone ID: ****
466+
✅ Cloudflare credentials saved
467+
468+
🔐 Verifying DNS ownership...
469+
✅ DNS ownership verified
470+
471+
📍 Checking DNS records...
472+
✅ app.example.com → 203.0.113.42 (already correct)
473+
⚠️ www.example.com → 198.51.100.10 (exists, current IP)
474+
Overwrite with 203.0.113.42? (y/n): y
475+
✅ Updated
476+
➕ api.example.com → Creating new record...
477+
✅ Created
478+
➕ admin.example.com → Creating new record...
479+
✅ Created
480+
481+
✅ DNS mapping complete!
482+
- 1 unchanged
483+
- 1 updated
484+
- 2 created
485+
```
486+
487+
---
488+
489+
### `graft map service <service-name>`
490+
Map DNS records for a specific service only.
491+
492+
```bash
493+
graft map service backend
494+
graft map service frontend
495+
```
496+
497+
**What it does:**
498+
Same as `graft map` but only processes the specified service.
499+
500+
**Example:**
501+
```bash
502+
$ graft map service backend
503+
504+
🔍 Mapping service: backend
505+
📋 Found domain(s): api.example.com
506+
507+
🌐 Detecting server IP...
508+
Server IP: 203.0.113.42
509+
510+
🔐 Verifying DNS ownership...
511+
✅ DNS ownership verified
512+
513+
📍 Processing DNS records...
514+
➕ api.example.com → Creating new record...
515+
✅ Created: api.example.com → 203.0.113.42
516+
517+
✅ DNS mapping complete for service: backend
518+
```
519+
520+
**Benefits:**
521+
- ✅ Automates DNS record creation
522+
- ✅ Prevents manual DNS configuration errors
523+
- ✅ Saves Cloudflare credentials for future use
524+
- ✅ Safe overwrite prompts for existing records
525+
- ✅ Works with multiple domains per service
526+
527+
---
528+
426529
## Monitoring Commands
427530
428531
### `graft logs <service>`
@@ -843,6 +946,8 @@ graft exec backend sh
843946
- `graft sync [service] [-h] [--git] [--branch <name>] [--commit <hash>]` - Deploy
844947
- `graft sync compose [-h]` - Update compose only
845948
- `graft logs <service>` - Stream logs
949+
- `graft map` - Map all service domains to Cloudflare DNS
950+
- `graft map service <name>` - Map specific service domain to Cloudflare DNS
846951
847952
### Passthrough Commands (via docker compose)
848953
- `graft ps` - Container status

cmd/graft/main.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,18 @@ func main() {
163163
runPull(registryContext, args[1])
164164
case "mode":
165165
runMode()
166+
case "map":
167+
if len(args) < 2 {
168+
runMap([]string{}) // Map all services
169+
} else if args[1] == "service" {
170+
if len(args) < 3 {
171+
fmt.Println("Usage: graft map service <service-name>")
172+
return
173+
}
174+
runMapService(args[2])
175+
} else {
176+
runMap(args[1:])
177+
}
166178
default:
167179
// Handle the --pull flag as requested in the specific format
168180
// foundPull := false
@@ -204,6 +216,8 @@ func printUsage() {
204216
fmt.Println(" sync [service] [-h] Deploy project to server")
205217
fmt.Println(" logs <service> Stream service logs")
206218
fmt.Println(" mode Change project deployment mode")
219+
fmt.Println(" map Map all service domains to Cloudflare DNS")
220+
fmt.Println(" map service <name> Map specific service domain to Cloudflare DNS")
207221
}
208222
func runMode() {
209223
reader := bufio.NewReader(os.Stdin)

0 commit comments

Comments
 (0)