• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H04-Sep-2021-251212

cmd/H04-Sep-2021-794670

vendor/github.com/Masterminds/semver/v3/H03-May-2022-3,5252,590

.gitignoreH A D04-Sep-2021130 139

.golangci.ymlH A D04-Sep-2021923 4338

.goreleaser.ymlH A D04-Sep-20212.5 KiB10697

LICENSEH A D04-Sep-202111.1 KiB202169

README.mdH A D04-Sep-20214.7 KiB15298

builder.goH A D04-Sep-20218.7 KiB274161

builder_test.goH A D04-Sep-20211.8 KiB8971

environment.goH A D04-Sep-20216.9 KiB267192

go.modH A D04-Sep-202195 63

go.sumH A D04-Sep-2021183 32

platforms.goH A D04-Sep-20211.8 KiB8362

README.md

1`xcaddy` - Custom Caddy Builder
2===============================
3
4This command line tool and associated Go package makes it easy to make custom builds of the [Caddy Web Server](https://github.com/caddyserver/caddy).
5
6It is used heavily by Caddy plugin developers as well as anyone who wishes to make custom `caddy` binaries (with or without plugins).
7
8Stay updated, be aware of changes, and please submit feedback! Thanks!
9
10## Requirements
11
12- [Go installed](https://golang.org/doc/install)
13
14## Install
15
16You can [download binaries](https://github.com/caddyserver/xcaddy/releases) that are already compiled for your platform from the Release tab.
17
18You may also build `xcaddy` from source:
19
20```bash
21$ go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest
22```
23
24For Debian, Ubuntu, and Raspbian, an `xcaddy` package is available from our [Cloudsmith repo](https://cloudsmith.io/~caddy/repos/xcaddy/packages/):
25
26```bash
27sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https
28curl -1sLf 'https://dl.cloudsmith.io/public/caddy/xcaddy/gpg.key' | sudo tee /etc/apt/trusted.gpg.d/caddy-xcaddy.asc
29curl -1sLf 'https://dl.cloudsmith.io/public/caddy/xcaddy/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-xcaddy.list
30sudo apt update
31sudo apt install xcaddy
32```
33
34## Command usage
35
36The `xcaddy` command has two primary uses:
37
381. Compile custom `caddy` binaries
392. A replacement for `go run` while developing Caddy plugins
40
41The `xcaddy` command will use the latest version of Caddy by default. You can customize this for all invocations by setting the `CADDY_VERSION` environment variable.
42
43As usual with `go` command, the `xcaddy` command will pass the `GOOS`, `GOARCH`, and `GOARM` environment variables through for cross-compilation.
44
45
46### Custom builds
47
48Syntax:
49
50```
51$ xcaddy build [<caddy_version>]
52    [--output <file>]
53    [--with <module[@version][=replacement]>...]
54```
55
56- `<caddy_version>` is the core Caddy version to build; defaults to `CADDY_VERSION` env variable or latest.
57- `--output` changes the output file.
58- `--with` can be used multiple times to add plugins by specifying the Go module name and optionally its version, similar to `go get`. Module name is required, but specific version and/or local replacement are optional.
59
60Examples:
61
62```bash
63$ xcaddy build \
64    --with github.com/caddyserver/ntlm-transport
65
66$ xcaddy build v2.0.1 \
67    --with github.com/caddyserver/ntlm-transport@v0.1.1
68
69$ xcaddy build \
70    --with github.com/caddyserver/ntlm-transport=../../my-fork
71
72$ xcaddy build \
73    --with github.com/caddyserver/ntlm-transport@v0.1.1=../../my-fork
74```
75
76You can even replace Caddy core using the `--with` flag:
77
78```
79$ xcaddy build \
80    --with github.com/caddyserver/caddy/v2=../../my-caddy-fork
81```
82
83This allows you to hack on Caddy core (and optionally plug in extra modules at the same time!) with relative ease.
84
85
86### For plugin development
87
88If you run `xcaddy` from within the folder of the Caddy plugin you're working on _without the `build` subcommand_, it will build Caddy with your current module and run it, as if you manually plugged it in and invoked `go run`.
89
90The binary will be built and run from the current directory, then cleaned up.
91
92The current working directory must be inside an initialized Go module.
93
94Syntax:
95
96```
97$ xcaddy <args...>
98```
99- `<args...>` are passed through to the `caddy` command.
100
101For example:
102
103```bash
104$ xcaddy list-modules
105$ xcaddy run
106$ xcaddy run --config caddy.json
107```
108
109The race detector can be enabled by setting `XCADDY_RACE_DETECTOR=1`. The DWARF debug info can be enabled by setting `XCADDY_DEBUG=1`.
110
111
112### Getting `xcaddy`'s version
113
114```
115$ xcaddy version
116```
117
118
119## Library usage
120
121```go
122builder := xcaddy.Builder{
123	CaddyVersion: "v2.0.0",
124	Plugins: []xcaddy.Dependency{
125		{
126			ModulePath: "github.com/caddyserver/ntlm-transport",
127			Version:    "v0.1.1",
128		},
129	},
130}
131err := builder.Build(context.Background(), "./caddy")
132```
133
134Versions can be anything compatible with `go get`.
135
136
137
138## Environment variables
139
140Because the subcommands and flags are constrained to benefit rapid plugin prototyping, xcaddy does read some environment variables to take cues for its behavior and/or configuration when there is no room for flags.
141
142- `CADDY_VERSION` sets the version of Caddy to build.
143- `XCADDY_RACE_DETECTOR=1` enables the Go race detector in the build.
144- `XCADDY_DEBUG=1` enables the DWARF debug information in the build.
145- `XCADDY_SETCAP=1` will run `sudo setcap cap_net_bind_service=+ep` on the temporary binary before running it when in dev mode.
146- `XCADDY_SKIP_BUILD=1` causes xcaddy to not compile the program, it is used in conjunction with build tools such as [GoReleaser](https://goreleaser.com). Implies `XCADDY_SKIP_CLEANUP=1`.
147- `XCADDY_SKIP_CLEANUP=1` causes xcaddy to leave build artifacts on disk after exiting.
148
149---
150
151&copy; 2020 Matthew Holt
152