dunglas / mercure

🪽 An open, easy, fast, reliable and battery-efficient solution for real-time communications
https://mercure.rocks
GNU Affero General Public License v3.0
3.99k stars 297 forks source link

XCaddy Custom Build to install Mercure plugin not working #929

Closed dayton-outar closed 3 months ago

dayton-outar commented 3 months ago

I use the following commands to build a caddy with mercure.

XCADDY_VERSION=0.4.2
FILE="xcaddy_${XCADDY_VERSION}_linux_amd64.tar.gz"

DIR="/app/bin"
mkdir -p $DIR
XCADDY="$DIR/xcaddy"

if [ ! -e "${DIR}/xcaddy" ]; then
  # Download xcaddy
  wget -O $FILE "https://github.com/caddyserver/xcaddy/releases/download/v${XCADDY_VERSION}/$FILE"
  tar xvzf $FILE -C $DIR
  rm $FILE
else
  echo "Found $XCADDY"
fi

# Build caddy with mercure plugin
"$XCADDY" build --with github.com/dunglas/mercure

# List modules
./caddy list-modules

After the script is completed, I cannot find mercure handler. See output below,

...
    http.handlers.acme_server
    http.handlers.authentication
    http.handlers.copy_response
    http.handlers.copy_response_headers
    http.handlers.encode
    http.handlers.error
    http.handlers.file_server
    http.handlers.headers
    http.handlers.intercept
    http.handlers.invoke
    http.handlers.log_append
    http.handlers.map
    http.handlers.metrics
    http.handlers.push
    http.handlers.request_body
    http.handlers.reverse_proxy
    http.handlers.rewrite
    http.handlers.static_response
    http.handlers.subroute
    http.handlers.templates
    http.handlers.tracing
    http.handlers.vars

What could I be missing?

N.B. I also tried building with xcaddy build --with github.com/dunglas/mercure/caddy

dunglas commented 3 months ago

you indeed need xcaddy build --with github.com/dunglas/mercure/caddy. Can you double-check that you don't see the module with this change?

dayton-outar commented 3 months ago

Here's the response from platform.sh when I run ./caddy run --config dev.Caddyfile,

2024/08/13 12:49:21.588 INFO    using config from file  {"file": "dev.Caddyfile"}
Error: adapting config using caddyfile: dev.Caddyfile:8: unrecognized directive: mercure

See below the dev.Caddyfile,

{
    # Optional: Enable debug logging
    debug
}

:3000 {
    # Enable the Mercure module
    mercure {
        # Publisher JWT key
        jwt_key {env.MERCURE_PUBLISHER_JWT_KEY}

        # Subscribers JWT key
        jwt_key_subscriber {env.MERCURE_SUBSCRIBER_JWT_KEY}

        # Transport URL
        transport_url {env.MERCURE_TRANSPORT_URL}

        # Allow all CORS origins
        cors_origins *

        # Allow all publishers
        publish_origins *

        # Enable the subscription endpoint (default is enabled)
        subscriptions

        # Enable the publishing endpoint (default is enabled)
        publish

        # Enable UI
        ui

        # Configure the hub path and address
        # address :3000
        # path /hub
    }

    # Health check endpoint
    respond /health 200
}

See below the full list of modules when I run ./caddy list-modules,

admin.api.load
admin.api.metrics
admin.api.pki
admin.api.reverse_proxy
caddy.adapters.caddyfile
caddy.config_loaders.http
caddy.filesystems
caddy.listeners.http_redirect
caddy.listeners.proxy_protocol
caddy.listeners.tls
caddy.logging.encoders.append
caddy.logging.encoders.console
caddy.logging.encoders.filter
caddy.logging.encoders.filter.cookie
caddy.logging.encoders.filter.delete
caddy.logging.encoders.filter.hash
caddy.logging.encoders.filter.ip_mask
caddy.logging.encoders.filter.query
caddy.logging.encoders.filter.regexp
caddy.logging.encoders.filter.rename
caddy.logging.encoders.filter.replace
caddy.logging.encoders.json
caddy.logging.writers.discard
caddy.logging.writers.file
caddy.logging.writers.net
caddy.logging.writers.stderr
caddy.logging.writers.stdout
caddy.storage.file_system
events
http
http.authentication.hashes.bcrypt
http.authentication.providers.http_basic
http.encoders.gzip
http.encoders.zstd
http.handlers.acme_server
http.handlers.authentication
http.handlers.copy_response
http.handlers.copy_response_headers
http.handlers.encode
http.handlers.error
http.handlers.file_server
http.handlers.headers
http.handlers.intercept
http.handlers.invoke
http.handlers.log_append
http.handlers.map
http.handlers.metrics
http.handlers.push
http.handlers.request_body
http.handlers.reverse_proxy
http.handlers.rewrite
http.handlers.static_response
http.handlers.subroute
http.handlers.templates
http.handlers.tracing
http.handlers.vars
http.ip_sources.static
http.matchers.client_ip
http.matchers.expression
http.matchers.file
http.matchers.header
http.matchers.header_regexp
http.matchers.host
http.matchers.method
http.matchers.not
http.matchers.path
http.matchers.path_regexp
http.matchers.protocol
http.matchers.query
http.matchers.remote_ip
http.matchers.vars
http.matchers.vars_regexp
http.precompressed.br
http.precompressed.gzip
http.precompressed.zstd
http.reverse_proxy.selection_policies.client_ip_hash
http.reverse_proxy.selection_policies.cookie
http.reverse_proxy.selection_policies.first
http.reverse_proxy.selection_policies.header
http.reverse_proxy.selection_policies.ip_hash
http.reverse_proxy.selection_policies.least_conn
http.reverse_proxy.selection_policies.query
http.reverse_proxy.selection_policies.random
http.reverse_proxy.selection_policies.random_choose
http.reverse_proxy.selection_policies.round_robin
http.reverse_proxy.selection_policies.uri_hash
http.reverse_proxy.selection_policies.weighted_round_robin
http.reverse_proxy.transport.fastcgi
http.reverse_proxy.transport.http
http.reverse_proxy.upstreams.a
http.reverse_proxy.upstreams.multi
http.reverse_proxy.upstreams.srv
pki
tls
tls.ca_pool.source.file
tls.ca_pool.source.http
tls.ca_pool.source.inline
tls.ca_pool.source.pki_intermediate
tls.ca_pool.source.pki_root
tls.ca_pool.source.storage
tls.certificates.automate
tls.certificates.load_files
tls.certificates.load_folders
tls.certificates.load_pem
tls.certificates.load_storage
tls.client_auth.verifier.leaf
tls.get_certificate.http
tls.get_certificate.tailscale
tls.handshake_match.local_ip
tls.handshake_match.remote_ip
tls.handshake_match.sni
tls.issuance.acme
tls.issuance.internal
tls.issuance.zerossl
tls.leaf_cert_loader.file
tls.leaf_cert_loader.folder
tls.leaf_cert_loader.pem
tls.leaf_cert_loader.storage
tls.permission.http
tls.stek.distributed
tls.stek.standard

  Standard modules: 121

  Non-standard modules: 0

  Unknown modules: 0
dayton-outar commented 3 months ago

I'm going to try an older version.

dayton-outar commented 3 months ago

Went back to xcaddy 0.4.1 and now getting,

Error: loading initial config: loading new config: loading http app module: provision http: server srv0: setting up route handlers: route 0: loading handler modules: position 0: loading module 'mercure': provision http.handlers.mercure: a JWT key or the URL of a JWK Set for publishers must be provided