Skip to content

Feature Request: Multi-line label value with nested blocks #769

@polarathene

Description

@polarathene

See these references:

There's a variety of issues beyond those where users would benefit from this feature.

  • It also would remove the workaround I suggest above which requires individual snippets to be mounted into the CDP container for import, as the equivalent could be defined as a label for importing if necessary.
  • For configuration that is one-off for a container, the config would be much more easier to read and solve the problem of CDP not having working support for config scenarios in the references above.

3 examples if the feature existed

services:
  supabase-db:
    labels:
      # Far more pleasant than what the user attempted across multiple labels (and failed):
      # https://github.com/lucaslorentz/caddy-docker-proxy/issues/765#issuecomment-3691818216
      # https://github.com/lucaslorentz/caddy-docker-proxy/issues/702#issuecomment-2765241269
      'caddy.layer4.:5432': |
        @postgres tls sni supabasedb.example.com
        route @postgres {
          tls {
            connection_policy {
              alpn postgresql
          }
          proxy {{upstreams 5432}}
        }
services:
  example:
    labels:
      caddy: example.localhost
      # Importing a snippet from a custom Caddyfile base to use import "blocks" args:
      # https://github.com/lucaslorentz/caddy-docker-proxy/issues/767#issuecomment-3691842054
      # https://caddyserver.com/docs/caddyfile/directives/import#syntax
      'caddy.import': |
        import extendable-proxy {
          proxy_target {
            to 10.0.0.1
          }
          proxy_options {
            transport http {
              tls
            }
          }
        }

# Connect all services in other Compose configs to CDP via this network:
networks:
  default:
    name: caddy-net

services:
  reverse-proxy:
    image: lucaslorentz/caddy-docker-proxy:2.10
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
    # Compose V2 does not require quotes for ports (no longer mistaken as hexadecimal).
    # `443/udp` for HTTP/3 support:
    ports: [80:80/tcp, 443:443/tcp, 443:443/udp]
    # Applying a global config via label with full block config:
    # https://github.com/lucaslorentz/caddy-docker-proxy/issues/695#issuecomment-2741982290
    labels:
      caddy: |
        dynamic_dns {
          # Use the `file` placeholder for secrets instead of `env`,
          # this is a more secure practice that has reduced risk of unintentional exposure:
          provider cloudflare {file./path/to/CLOUDFLARE_API_TOKEN}
          domains {
            # Use `env` placeholder for dynamic data:
            {env.DOMAIN}
          }
          check_interval 5m
          versions ipv4
        }

Without the feature proposed, one can configure the equivalent via a custom Caddyfile which looks like this if using the inline Docker Compose configs feature (or alternatively using an import directive via label + separate config workaround should work too):

services:
  reverse-proxy:
    # Providing your own base `Caddyfile` requires this ENV:
    environment:
      CADDY_DOCKER_CADDYFILE_PATH: /etc/caddy/Caddyfile
    configs:
      - source: caddy-config
        target: /etc/caddy/Caddyfile

configs:
  caddy-config:
    content: |
      # Global Settings
      { ... }

      # Anything else you'd like in your base `Caddyfile` after global settings goes here

Presumably if the label value is multi-line, that would be sufficient to toggle the parser logic to support this functionality? Insert the config value at the label key for the generated Caddyfile?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions