Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

199 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

cpritchett/caddy-labels


Logo

Caddy with Docker Label Support & Cloudflare

Pull Requests Issues

Table of Contents

About

Caddy with docker label support & Cloudflare

This image will inspect container labels & translate them into a caddy config like so:

services:
  server:
    ...
    networks:
      - proxy_network
    deploy:
      labels:
        # *.example.com {
        - caddy: '*.example.com'
        # revere_proxy <DOCKER IP>:80
        - caddy.reverse_proxy: {{upstreams 80}}
        # tls { dns cloudflare }
        - caddy.tls.dns: cloudflare
        # }

Other useful patterns:

# Load-balance sockets
caddy.reverse_proxy.lb_policy: client_ip_hash
# Multiple domains
caddy: a.example.com b.example.com
caddy.@match0.host: a.example.com
caddy.@match1.host: b.example.com
caddy.0_reverse_proxy: '@match0 {{upstreams 80}}'
caddy.1_reverse_proxy: '@match1 {{upstreams 81}}'
# Whitelist network
caddy.@local.remote_ip: '192.168.0.0/24'
caddy.handle: '@local'
caddy.handle.reverse_proxy: '{{upstreams 3000}}'

See caddy-docker-proxy for more information

Built With

Docker

Setup

Production

Prerequisites

Instructions

  1. Create a compose file:
services:
  caddy:
    image: cpritchett/caddy-labels:latest
    environment:
      CADDY_INGRESS_NETWORKS: proxy_network
      TZ: America/Toronto
    ports:
     - 80:80
     - 443:443
    volumes:
     - data:/data/caddy
     - /var/run/docker.sock:/var/run/docker.sock
    networks:
     - proxy_network
    deploy:
      mode: global
      labels:
        caddy.email: example@example.com
        # Cloudflare
        caddy.acme_dns: 'cloudflare TOKEN'

networks:
  proxy_network:

volumes:
  data:
  1. Deploy: docker compose up

Development

Development Prerequisites

Build Instructions

  1. Update desired version number in Dockerfile
  2. Build docker image: docker build -t cpritchett/caddy-labels:latest .

Linting

This project includes comprehensive linting for code quality:

Setup with mise (recommended):

mise run setup  # Install all tools and dependencies

Setup without mise:

bun install  # Install Bun dependencies
# Install hadolint manually for your platform

Available commands:

bun run lint          # Run all linters
bun run lint:docker   # Lint Dockerfile with hadolint
bun run lint:markdown # Lint Markdown files
bun run lint:yaml     # Lint YAML files with ESLint
bun run lint:fix      # Auto-fix Markdown issues

Tools included:

  • Bun - Fast JavaScript runtime and package manager
  • Socket.dev - Dependency security scanning (GitHub Actions)
  • Hadolint - Dockerfile linting and security checks
  • markdownlint - Markdown formatting and style
  • eslint-plugin-yml - YAML syntax and style via ESLint
  • commitlint - Conventional commit message format
  • Husky - Git hooks for pre-commit linting

Git hooks:

  • Pre-commit: Runs all linters before allowing commits
  • Commit-msg: Validates commit message format

Versioning

This project uses Release Please for automated versioning and release management based on Conventional Commits.

Versioning Strategy: This project uses independent semantic versioning (e.g., v1.0.0, v1.1.0) to track changes to this wrapper repository. The Caddy version in each release is clearly identified via the caddy-X.Y.Z Docker tag.

Version Tags

Docker images are tagged with multiple formats:

  • Semantic Version Tags: 1.0.0, 1.0, 1 (track wrapper repository changes)
  • Caddy Version Tag: caddy-2.10.0 (shows the Caddy version included)
  • Latest Tag: latest (always points to the most recent main branch build)
  • Timestamp Tag: YYYYMMDD-HHmmss (for each main branch build)

Release Process

  1. For Caddy Updates: Renovate detects new Caddy versions and creates a PR
  2. Merge with Conventional Commit: Use appropriate commit format (e.g., fix: upgrade to Caddy 2.11.0)
  3. For Wrapper Changes: Make changes with conventional commits (feat:, fix:, docs:, ci:)
  4. Release Please Triggers: Automatically creates/updates a release PR with:
    • Automated CHANGELOG updates (including all changes since last release)
    • Version bump based on conventional commits
  5. Merge Release PR: Creates a GitHub release and triggers Docker image builds

Versioning Examples

  • v1.0.0 - Initial release (Caddy 2.10.0)
  • v1.1.0 - Add new plugin support (still Caddy 2.10.0)
  • v1.2.0 - Upgrade to Caddy 2.11.0
  • v1.2.1 - Fix configuration bug (still Caddy 2.11.0)

Commit Format

Follow the Conventional Commits specification:

  • feat: - New features (bumps minor version)
  • fix: - Bug fixes or Caddy upgrades (bumps patch version)
  • docs: - Documentation changes (included in changelog)
  • ci: - CI/CD changes (included in changelog)
  • chore: - Maintenance tasks (hidden from changelog)
  • Add ! or BREAKING CHANGE: for breaking changes (bumps major version)

Examples:

  • fix: upgrade to Caddy 2.11.0 for security patches
  • feat: add support for Tailscale plugin
  • ci: improve Docker build caching

License

Copyright © 2023 cpritchett | Available under MIT Licensing

See the license for more information.

About

Caddy with Docker Label Support & Cloudflare

Resources

Contributing

Stars

Watchers

Forks

Releases

Packages

Used by

Contributors

Languages