XCaddy not including custom modules in binary build?

1. The problem I’m having:

I’ve built a custom module named ‘spartacus’.

When I execute the following - it builds correctly, and seems to run fine:

xcaddy list-modules:

http.handlers.spartacus

  Non-standard modules: 1

xcaddy run --config=caddy.json

(runs correctly).

xcaddy build --output=caddy-with-spartacus

(works fine)

But when I execute:

./caddy-with-spartacus -config caddy.json

It says:

❯ ./caddy-with-spartacus run --config caddy.json
2024/05/05 18:21:00.230	INFO	using provided configuration	{"config_file": "caddy.json", "config_adapter": ""}
2024/05/05 18:21:00.232	INFO	admin	admin endpoint started	{"address": "localhost:2019", "enforce_origin": false, "origins": ["//localhost:2019", "//[::1]:2019", "//127.0.0.1:2019"]}
2024/05/05 18:21:00.232	INFO	tls.cache.maintenance	started background certificate maintenance	{"cache": "0x140003c7080"}
2024/05/05 18:21:00.232	INFO	http.auto_https	server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS	{"server_name": "spartacus_server", "https_port": 443}
2024/05/05 18:21:00.232	INFO	http.auto_https	enabling automatic HTTP->HTTPS redirects	{"server_name": "spartacus_server"}
2024/05/05 18:21:00.234	INFO	tls.cache.maintenance	stopped background certificate maintenance	{"cache": "0x140003c7080"}
Error: loading initial config: loading new config: loading http app module: provision http: server spartacus_server: setting up route handlers: route 0: loading handler modules: position 0: loading module 'spartacus': unknown module: http.handlers.spartacus

Am I missing something?



## 2. Error messages and/or full log output:
<!--
Please DO NOT REDACT any information except credentials. Leave domain names intact!
Please DO NOT POST TRUNCATED LOG LINES as systemd is notorious for this.
Please USE THIS COMMAND TO VIEW LOGS with systemd:
    $ journalctl -u caddy --no-pager | less +G`
Please DO NOT USE WEB BROWSERS. Use `curl -vL` instead.
Please ENABLE DEBUG MODE FIRST by adding "debug" to the global options of your Caddyfile. See https://caddyserver.com/docs/caddyfile/options#debug for an example.
-->

❯ ./caddy-with-spartacus run --config caddy.json
2024/05/05 18:39:19.893 INFO using provided configuration {“config_file”: “caddy.json”, “config_adapter”: “”}
2024/05/05 18:39:19.897 INFO admin admin endpoint started {“address”: “localhost:2019”, “enforce_origin”: false, “origins”: [“//localhost:2019”, “//[::1]:2019”, “//127.0.0.1:2019”]}
2024/05/05 18:39:19.898 INFO tls.cache.maintenance started background certificate maintenance {“cache”: “0x140001c4280”}
2024/05/05 18:39:19.898 INFO http.auto_https server is listening only on the HTTPS port but has no TLS connection policies; adding one to enable TLS {“server_name”: “spartacus_server”, “https_port”: 443}
2024/05/05 18:39:19.898 INFO http.auto_https enabling automatic HTTP->HTTPS redirects {“server_name”: “spartacus_server”}
2024/05/05 18:39:19.900 DEBUG http.auto_https adjusted config {“tls”: {“automation”:{“policies”:[{“subjects”:[“localhost”,“127.0.0.1”]},{}]}}, “http”: {“servers”:{“remaining_auto_https_redirects”:{“listen”:[“:80”],“routes”:[{},{}],“logs”:{“default_logger_name”:“spartacusStdOutLogs”}},“spartacus_server”:{“listen”:[“:443”],“routes”:[{“handle”:[{“development”:true,“handler”:“spartacus”,“posthog”:{“endpoint”:“https://1e747868-3524-4d27-ad60-2e73e05bb428.mock.pstmn.io”}}]},{}],“tls_connection_policies”:[{}],“automatic_https”:{},“logs”:{“default_logger_name”:“spartacusStdOutLogs”}}}}}
2024/05/05 18:39:19.900 INFO tls.cache.maintenance stopped background certificate maintenance {“cache”: “0x140001c4280”}
Error: loading initial config: loading new config: loading http app module: provision http: server spartacus_server: setting up route handlers: route 0: loading handler modules: position 0: loading module ‘spartacus’: unknown module: http.handlers.spartacus```

3. Caddy version:

v0.4.0 h1:V4n6nNlkRPmrgE+npteBjS7hgMfw24UEmiIONDpIWSo=

4. How I installed and ran Caddy:

xcaddy build --config caddy.json
./caddy-with-spartacus run --config caddy.json

a. System environment:

MacOS

b. Command:

./caddy-with-spartacus run --config caddy.json

c. Service/unit/compose file:

N/A

d. My complete Caddy config:

{
    "logging": {
        "logs": {
            "default": {
                "level": "DEBUG"
            }
        }
    },
    "apps": {
        "http": {
            "servers": {
                "spartacus_server": {
                    "listen": [
                        ":443"
                    ],
                    "routes": [
                        {
                            "handle": [
                                {
                                    "handler": "spartacus",
                                    "posthog": {
                                        "endpoint": "https://1e747868-3524-4d27-ad60-2e73e05bb428.mock.pstmn.io"
                                    },
                                    "development": true
                                }
                            ]
                        },
                        {
                            "match": [
                                {
                                    "host": [
                                        "localhost",
                                        "127.0.0.1"
                                    ]
                                }
                            ]
                        }
                    ],
                    "logs": {
                        "default_logger_name": "spartacusStdOutLogs"
                    }
                }
            }
        }
    }
}```


### 5. Links to relevant resources:
<!-- Optional, but can help get us on the same page quickly. -->

That shows the modules in the ephemeral build.

Try ./caddy-with-spartacus list-modules and ./caddy-with-spartacus build-info and ./caddy-with-spartacus version. What do you see for those?

1 Like

yep - nothing.

>  ./caddy-with-spartacus list-modules

[...]

  Standard modules: 106

http.reverse_proxy.transport.http_ntlm

  Non-standard modules: 1

  Unknown modules: 0

Do i need to include my module with -with?

I tried that, but got the following:

2024/05/05 17:38:21 [INFO] exec (timeout=0s): /Users/daaronch/.asdf/shims/go get -d -v -tags nobadger github.com/bacalhau-project/spartacus github.com/caddyserver/caddy/v2
go: downloading github.com/bacalhau-project/spartacus v0.0.0-20240505145136-2d0a9a13145a
go: github.com/bacalhau-project/spartacus@v0.0.0-20240505145136-2d0a9a13145a: verifying module: github.com/bacalhau-project/spartacus@v0.0.0-20240505145136-2d0a9a13145a: reading https://sum.golang.org/lookup/github.com/bacalhau-project/spartacus@v0.0.0-20240505145136-2d0a9a13145a: 404 Not Found
	server response:
	not found: github.com/bacalhau-project/spartacus@v0.0.0-20240505145136-2d0a9a13145a: invalid version: git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/vcs/1d96a0eb44e5d01c9f3a044247f8289dce0c32b27aa76a249a444e5056e5b0b2: exit status 128:
		fatal: could not read Username for 'https://github.com': terminal prompts disabled
	Confirm the import path was entered correctly.
	If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.
2024/05/05 17:38:26 [FATAL] exit status 1

It is a private repo, but I followed the instructions here: Frequently Asked Questions (FAQ) - The Go Programming Language

here is my ./.git/config:

[url "ssh://git@github.com/"]
        insteadOf = https://github.com/

And my private keys are set up correctly:

❯ ssh git@github.com
PTY allocation request failed on channel 0
Hi aronchick! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.

When you use xcaddy build, yes. You can do --with github.com/bacalhau-project/spartacus=. where =. means “get the package from the current directory”. See the README.

1 Like

Amazing! Thank you so much - I didn’t see this in the readme at all (worked perfectly).