|
| 1 | +--- |
| 2 | +title: Custom Caddy Builder |
| 3 | +homepage: https://github.com/caddyserver/xcaddy |
| 4 | +tagline: | |
| 5 | + xcaddy makes it easy to make custom builds of the Caddy Web Server |
| 6 | +--- |
| 7 | + |
| 8 | +To update or switch versions, run `webi xcaddy@stable` (or `@v0.3`, `@beta`, |
| 9 | +etc). |
| 10 | + |
| 11 | +### Files |
| 12 | + |
| 13 | +These are the files / directories that are created and/or modified with this |
| 14 | +install: |
| 15 | + |
| 16 | +```text |
| 17 | +~/.config/envman/PATH.env |
| 18 | +~/.local/bin/xcaddy |
| 19 | +~/.local/opt/go/ |
| 20 | +~/go/bin/ |
| 21 | +``` |
| 22 | + |
| 23 | +## Cheat Sheet |
| 24 | + |
| 25 | +> `xcaddy` makes it easy to build caddy with DNS providers, and to test builds |
| 26 | +> of feature branches and PRs. |
| 27 | +
|
| 28 | +Build with `xcaddy`: |
| 29 | + |
| 30 | +```sh |
| 31 | +CGO_ENABLED=0 xcaddy build 'v2.7.5' \ |
| 32 | + --with github.com/caddy-dns/duckdns \ |
| 33 | + --with github.com/caddy-dns/lego-deprecated \ |
| 34 | + --output ./caddy-v2.7.5-extras |
| 35 | +``` |
| 36 | + |
| 37 | +See that it worked: |
| 38 | + |
| 39 | +```sh |
| 40 | +./caddy-v2.7.5-extras list-modules |
| 41 | +# v2.7.5 h1:HoysvZkLcN2xJExEepaFHK92Qgs7xAiCFydN5x5Hs6Q= |
| 42 | +``` |
| 43 | + |
| 44 | +Other helpful tips: |
| 45 | + |
| 46 | +- Caddy Versions |
| 47 | +- DNS Providers |
| 48 | +- Other Modules |
| 49 | +- Cross-Compiling |
| 50 | +- Build a Feature Branch |
| 51 | +- Build a Fork |
| 52 | +- List Built-In Modules |
| 53 | +- Common ENVs |
| 54 | + |
| 55 | +### How to List Available Caddy Versions |
| 56 | + |
| 57 | +<https://github.com/caddyserver/caddy/releases> |
| 58 | + |
| 59 | +See also: |
| 60 | + |
| 61 | +- <https://github.com/caddyserver/caddy/tags> |
| 62 | +- <https://webinstall.dev/api/releases/caddy.json?pretty=true&channel=stable&os=linux&arch=amd64&limit=10> |
| 63 | +- <https://webinstall.dev/api/releases/caddy.tab?channel=stable&os=linux&arch=amd64&limit=100> |
| 64 | + |
| 65 | +### How to Find DNS Providers |
| 66 | + |
| 67 | +There are two types of DNS Providers: |
| 68 | + |
| 69 | +**1.`libdns`** |
| 70 | + |
| 71 | +These providers each have their own module, most of which can be searched here: |
| 72 | + |
| 73 | +- <https://github.com/caddy-dns> |
| 74 | +- <https://caddyserver.com/docs/modules/> (search `dns.providers`) |
| 75 | + |
| 76 | +**2. `lego` (legacy)** |
| 77 | + |
| 78 | +This module bundles _many_ providers together, _all_ of which are listed here: |
| 79 | + |
| 80 | +- `github.com/caddy-dns/lego-deprecated` |
| 81 | +- <https://github.com/go-acme/lego#dns-providers> |
| 82 | +- <https://caddyserver.com/docs/modules/dns.providers.lego_deprecated> |
| 83 | + |
| 84 | +### How to Find Other Modules |
| 85 | + |
| 86 | +There are a variety of other modules, including things like `ngrok`, `s3`, |
| 87 | +`layer4`, and others. |
| 88 | + |
| 89 | +Most module authors register them in the caddy modules docs: |
| 90 | + |
| 91 | +- <https://caddyserver.com/docs/modules/> |
| 92 | + |
| 93 | +However, a module can be loaded from any Git URL (not just GitHub). |
| 94 | + |
| 95 | +Note: Modules are named internally by their namespace (e.g. `dns.providers.x`), |
| 96 | +but referenced externally by their Git URL . |
| 97 | + |
| 98 | +### How to Cross-Compile |
| 99 | + |
| 100 | +Use `CGO_ENABLED`, `GOOS`, `GOARCH`, and `GOARM` (for 32-bit ARM): |
| 101 | + |
| 102 | +```sh |
| 103 | +GOOS=linux GOARCH=arm64 GOARM= \ |
| 104 | +CGO_ENABLED=0 \ |
| 105 | + xcaddy build 'v2.7.5' \ |
| 106 | + --with github.com/caddy-dns/duckdns \ |
| 107 | + --with github.com/caddy-dns/lego-deprecated \ |
| 108 | + --output ./caddy-v2.7.5-extras |
| 109 | +``` |
| 110 | + |
| 111 | +You can _inline_ (as seen above) or `export` the ENVs: |
| 112 | + |
| 113 | +```sh |
| 114 | +export GOOS=linux |
| 115 | +export GOARCH=arm64 |
| 116 | +export GOARM= |
| 117 | +export CGO_ENABLED=0 |
| 118 | + |
| 119 | +xcaddy build 'v2.7.5' \ |
| 120 | + --with github.com/caddy-dns/duckdns \ |
| 121 | + --with github.com/caddy-dns/lego-deprecated \ |
| 122 | + --output ./caddy-v2.7.5-extras |
| 123 | +``` |
| 124 | + |
| 125 | +Using `CGO_ENABLED=0` can only build pure Go programs, which means that |
| 126 | +cross-compiling is guaranteed to succeed (assuming the modules don't contain C), |
| 127 | +however, file sizes may be slightly larger for bundling Go modules for DNS |
| 128 | +resolution, etc, which your OS would otherwise provide. |
| 129 | + |
| 130 | +Common OSes and Arches are: |
| 131 | + |
| 132 | +- `linux`, `darwin`, `windows`, `freebsd` |
| 133 | +- `amd64`, `arm64`, `mips`, `ppc64le` |
| 134 | + |
| 135 | +See also: |
| 136 | + |
| 137 | +- OSes: `go tool dist list | cut -d/ -f1 | sort -u` |
| 138 | +- Arches: `go tool dist list | cut -d/ -f2 | sort -u` |
| 139 | + |
| 140 | +### How to Build From a Feature Branch |
| 141 | + |
| 142 | +The `build` is actually a [commit-ish][commit-ish] (a.k.a. a "git ref"), which |
| 143 | +can apply to any branch of the official repository: |
| 144 | + |
| 145 | +```sh |
| 146 | +xcaddy build "file-placeholder" |
| 147 | +``` |
| 148 | + |
| 149 | +See also: |
| 150 | + |
| 151 | +- <https://github.com/caddyserver/caddy/tags> |
| 152 | +- <https://github.com/caddyserver/caddy/branches> |
| 153 | +- <https://github.com/caddyserver/caddy/commits/master> |
| 154 | + |
| 155 | +[commit-ish]: |
| 156 | + https://mirrors.edge.kernel.org/pub/software/scm/git/docs/#_identifier_terminology |
| 157 | + |
| 158 | +### How to List Built-In Modules |
| 159 | + |
| 160 | +When it's time to rebuild `caddy` and you've forgotten which modules you used to |
| 161 | +build it, fear not! |
| 162 | + |
| 163 | +`list-modules` to the rescue! |
| 164 | + |
| 165 | +```sh |
| 166 | +caddy list-modules |
| 167 | +``` |
| 168 | + |
| 169 | +```text |
| 170 | +admin.api.load |
| 171 | +# ... 104 other modules |
| 172 | +tls.stek.standard |
| 173 | +
|
| 174 | + Standard modules: 106 |
| 175 | +
|
| 176 | +dns.providers.duckdns |
| 177 | +
|
| 178 | + Non-standard modules: 1 |
| 179 | +``` |
| 180 | + |
| 181 | +### Common Options |
| 182 | + |
| 183 | +Here are some of the common environment variables that change xcaddy's behavior: |
| 184 | + |
| 185 | +| Option | Description | |
| 186 | +| ---------------------- | ------------------------------------------------------------- | |
| 187 | +| `CGO_ENABLED` | Set to `0` to build pure Go (no C or OS libraries) | |
| 188 | +| `GOOS` | For cross-compiling: `linux`, `darwin`, `windows`, etc | |
| 189 | +| `GOARCH` | For cross-compiling: `amd64`, `arm64`, `arm`, etc | |
| 190 | +| `GOARM` | For cross-compiling arm (32-bit): `7` or `6` (8 is arm64) | |
| 191 | +| `CADDY_VERSION` | Equivalent to `xcaddy build "$CADDY_VERSION" ...` | |
| 192 | +| `XCADDY_SETCAP=1` | Linux: runs [`sudo setcap cap_net_bind_service=+ep`][netbind] | |
| 193 | +| `XCADDY_SUDO=0` | Don't use `sudo` for `XCADDY_SETCAP` (i.e. on Alpine) | |
| 194 | +| `XCADDY_RACE_DETECTOR` | For finding race conditions in feature builds | |
| 195 | +| `XCADDY_DEBUG=1` | Disables `-ldflags '-w -s'`, for debug builds | |
| 196 | +| `XCADDY_SKIP_CLEANUP` | Leaves build files (for debugging failure) | |
| 197 | +| `XCADDY_SKIP_BUILD` | For use with building & releasing custom builds w/ GoReleaser | |
| 198 | + |
| 199 | +[netbind]: ../setcap-netbind/ |
| 200 | + |
| 201 | +See also: |
| 202 | + |
| 203 | +- `go tool dist list` |
| 204 | +- <https://github.com/caddyserver/xcaddy#environment-variables> |
0 commit comments