Skip to main content

A powerful CLI tool for setting up and managing Cloudflare DNS records with Caddy reverse proxy. Easily deploy local services with public domains, automate DNS configuration, and manage SSL certificates using Cloudflare's API.

Project description

Caddy Cloudflare CLI

A powerful CLI tool for setting up and managing Cloudflare DNS records with Caddy reverse proxy. Easily deploy local services with public domains, automate DNS configuration, and manage SSL certificates using Cloudflare's API.

License: GPL-3.0

Features

  • 🚀 Create and manage Cloudflare DNS records with ease
  • 🔒 Automatic SSL certificate provisioning via Caddy and Cloudflare
  • 🌐 Expose local services to the internet in seconds
  • 🛡️ Leverage Cloudflare's security and CDN benefits
  • 🔄 Simple commands to deploy, list, and remove domains

Installation

# Install with pip
pip install caddy-cloudflare-cli

# Or install with development dependencies
pip install caddy-cloudflare-cli[dev]

Cloudflare Setup Guide

Before using this tool, you'll need a Cloudflare account and domain. Follow these steps:

1. Register a Domain

If you don't already have a domain:

  1. Purchase a domain from any domain registrar (Namecheap, GoDaddy, etc.)
  2. We recommend choosing a domain registrar based on price and their ease of changing nameservers

2. Add Domain to Cloudflare

  1. Create a Cloudflare account if you don't have one
  2. Log in to Cloudflare and click "Add a Site"
  3. Enter your domain name and click "Add Site"
  4. Select a plan (the Free plan works fine for this tool)
  5. Cloudflare will scan for existing DNS records

3. Update Nameservers

  1. Cloudflare will provide you with nameservers (e.g., cruz.ns.cloudflare.com and tim.ns.cloudflare.com)
  2. Go to your domain registrar's website
  3. Find the nameserver settings for your domain
  4. Replace the current nameservers with Cloudflare's nameservers
  5. Save the changes (propagation can take up to 24 hours)

4. Create API Tokens

For the most secure setup, create dedicated API tokens:

  1. Go to your Cloudflare dashboard
  2. Navigate to "My Profile" → "API Tokens"
  3. Click "Create Token"
  4. Choose "Create Custom Token"
  5. Give your token a name (e.g., "Caddy DNS Token")
  6. Under "Permissions", add:
    • Zone - DNS - Edit
  7. Under "Zone Resources", select:
    • Include - Specific zone - Your domain
  8. Click "Continue to Summary" and then "Create Token"
  9. Copy the token value (you won't be able to see it again!)

Usage

Initial Setup

# Initialize configuration
caddy-cloudflare init

Follow the interactive prompts to configure your Cloudflare credentials and domain.

Install Caddy

# Install Caddy locally
caddy-cloudflare install

# Or install Caddy system-wide (requires sudo)
sudo caddy-cloudflare install --system

Deploy a Service

# Deploy with interactive prompts
caddy-cloudflare deploy

# Deploy with specific options
caddy-cloudflare deploy --subdomain myapp --port 3000

# Using a custom IP (instead of auto-detection)
caddy-cloudflare deploy --ip 203.0.113.1

Manage Deployments

# List all deployments
caddy-cloudflare list

# Show all DNS records (not just deployments)
caddy-cloudflare list --all

# Delete a deployment
caddy-cloudflare delete myapp

Proxy Management

# Start the Caddy proxy
caddy-cloudflare proxy start

# Check proxy status
caddy-cloudflare proxy status

# Stop the proxy
caddy-cloudflare proxy stop

# Reload proxy configuration
caddy-cloudflare proxy reload

Troubleshooting

# Run diagnostic checks
caddy-cloudflare debug

Advanced Usage

Using Environment Variables

You can use environment variables instead of storing credentials in config files:

# API Token method (recommended)
export CLOUDFLARE_API_TOKEN="your-api-token"

# Least privilege method (recommended)
export CLOUDFLARE_ZONE_TOKEN="your-zone-token"
export CLOUDFLARE_DNS_TOKEN="your-dns-token"

# Global API key method (legacy)
export CLOUDFLARE_API_KEY="your-global-api-key"
export CLOUDFLARE_EMAIL="your-email@example.com"

# Domain configuration
export CLOUDFLARE_DOMAIN="yourdomain.com"

Contributing

Contributions are welcome! Here's how you can contribute:

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/my-new-feature
  3. Commit your changes: git commit -am 'Add some feature'
  4. Push to the branch: git push origin feature/my-new-feature
  5. Submit a pull request

Development Setup

# Clone repository
git clone https://github.com/yourusername/caddy-cloudflare-cli.git
cd caddy-cloudflare-cli

# Install development dependencies
pip install -e ".[dev]"

# Run tests
pytest

Areas for Contribution

We're especially interested in contributions for:

  1. New DNS Providers: Add support for more DNS providers beyond Cloudflare
  2. New Proxy Providers: Add support for additional reverse proxy solutions
  3. Bug Fixes: Help identify and fix bugs
  4. Documentation: Improve documentation and examples
  5. Testing: Add more tests and improve test coverage

Creating Issues

If you find a bug or want to request a feature, please create an issue:

## Description
A clear description of the issue or feature request

## Steps to Reproduce (for bugs)
1. Step 1
2. Step 2
3. ...

## Expected Behavior
What you expected to happen

## Actual Behavior
What actually happened

## Environment
- OS: [e.g., Ubuntu 22.04]
- Python version: [e.g., 3.11.2]
- Package version: [e.g., 0.1.0]

TODO

  • Add support for wedos.cz WAPI DNS provider
  • Implement direct Cloudflare Tunnel support
  • Add support for more complex Caddy configurations
  • Create Docker container for easier deployment
  • Implement concurrent multi-domain management

License

This project is licensed under the GNU General Public License v3.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

caddy_cloudflare_cli-1.1.6.tar.gz (52.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

caddy_cloudflare_cli-1.1.6-py3-none-any.whl (61.6 kB view details)

Uploaded Python 3

File details

Details for the file caddy_cloudflare_cli-1.1.6.tar.gz.

File metadata

  • Download URL: caddy_cloudflare_cli-1.1.6.tar.gz
  • Upload date:
  • Size: 52.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.9

File hashes

Hashes for caddy_cloudflare_cli-1.1.6.tar.gz
Algorithm Hash digest
SHA256 1600181e7c9eb3d041b8de8679accd317532f500ead6baf75381855f972395c4
MD5 f218e730eabaeea9e9f6cc9432ccb5c7
BLAKE2b-256 925c05db05de1b91fe9d2c76615b8e3b95c3fc609ca69a9d8f2722a96eeabf94

See more details on using hashes here.

File details

Details for the file caddy_cloudflare_cli-1.1.6-py3-none-any.whl.

File metadata

File hashes

Hashes for caddy_cloudflare_cli-1.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 704b9e69c16c91fb9daf7927993405b85bf23199f89fd04fb47082bad85d6be3
MD5 ed66db90de5eb780b40709b1c0989af7
BLAKE2b-256 f24f251ac2e6152380e17500c9576d09ad743825d255dc80d4b15eed6167ec5c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page