2020-04-08 01:56:30 +01:00
`xcaddy` - Custom Caddy Builder
===============================
2020-03-21 20:31:29 +00:00
2020-04-08 01:56:30 +01:00
This command line tool and associated Go package makes it easy to make custom builds of the [Caddy Web Server ](https://github.com/caddyserver/caddy ).
It is used heavily by Caddy plugin developers as well as anyone who wishes to make custom `caddy` binaries (with or without plugins).
2020-03-21 20:31:29 +00:00
Supports Caddy 2 and up.
2020-04-08 01:56:30 +01:00
⚠️ Still in development.
Stay updated, be aware of changes, and please submit feedback! Thanks!
2020-03-25 06:01:44 +00:00
2020-03-21 20:31:29 +00:00
## Requirements
2020-04-22 23:29:57 +01:00
- [Go installed ](https://golang.org/doc/install )
- [Go modules ](https://github.com/golang/go/wiki/Modules ) enabled
2020-03-21 20:31:29 +00:00
2020-04-08 01:56:30 +01:00
## Command usage
2020-03-21 20:31:29 +00:00
2020-04-08 01:56:30 +01:00
The `xcaddy` command has two primary uses:
2020-03-21 20:31:29 +00:00
2020-04-08 01:56:30 +01:00
- Compile custom `caddy` binaries
- A replacement for `go run` while developing Caddy plugins
2020-03-25 06:01:44 +00:00
2020-04-08 01:56:30 +01:00
Install the `xcaddy` command with:
2020-04-02 16:05:25 +01:00
2020-04-08 01:56:30 +01:00
```bash
$ go get -u github.com/caddyserver/xcaddy/cmd/xcaddy
2020-04-02 16:05:25 +01:00
```
2020-04-22 23:29:57 +01:00
The `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.
As usual with `go` command, the `xcaddy` command will pass through the `GOOS` , `GOARCH` , and `GOARM` environment variables for cross-compilation.
2020-04-08 01:56:30 +01:00
### Custom builds
2020-03-25 06:01:44 +00:00
2020-03-21 20:31:29 +00:00
Syntax:
```
2020-04-22 23:29:57 +01:00
$ xcaddy build [< caddy_version > ]
2020-04-08 01:56:30 +01:00
[--output < file > ]
2020-04-22 23:29:57 +01:00
[--with < module [ @ version ] [ = replacement ] > ...]
2020-03-21 20:31:29 +00:00
```
2020-04-22 23:29:57 +01:00
- `<caddy_version>` is the core Caddy version to build; defaults to `CADDY_VERSION` env variable or latest.
2020-03-21 20:31:29 +00:00
- `--output` changes the output file.
2020-04-22 23:40:25 +01:00
- `--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.
2020-03-25 06:01:44 +00:00
2020-04-22 23:29:57 +01:00
Examples:
2020-03-25 06:01:44 +00:00
```bash
2020-04-22 23:29:57 +01:00
$ xcaddy build \
--with github.com/caddyserver/ntlm-transport
$ xcaddy build v2.0.1 \
2020-04-08 01:56:30 +01:00
--with github.com/caddyserver/ntlm-transport@v0.1.0
2020-04-22 23:29:57 +01:00
$ xcaddy build \
--with github.com/caddyserver/ntlm-transport=../../my-fork
$ xcaddy build \
2020-04-22 23:40:25 +01:00
--with github.com/caddyserver/ntlm-transport@v0.1.0=../../my-fork
2020-03-25 06:01:44 +00:00
```
### For plugin development
2020-04-22 23:29:57 +01:00
If 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` .
2020-04-08 01:56:30 +01:00
The binary will be built and run from the current directory, then cleaned up.
2020-03-25 06:01:44 +00:00
2020-04-08 01:56:30 +01:00
The current working directory must be inside an initialized Go module.
2020-03-25 06:01:44 +00:00
Syntax:
```
2020-04-08 01:56:30 +01:00
$ xcaddy < args... >
2020-03-25 06:01:44 +00:00
```
- `<args...>` are passed through to the `caddy` command.
2020-03-21 20:31:29 +00:00
For example:
```bash
2020-03-25 06:01:44 +00:00
$ xcaddy list-modules
2020-04-08 01:56:30 +01:00
$ xcaddy run
2020-03-25 06:01:44 +00:00
$ xcaddy run --config caddy.json
2020-03-21 20:31:29 +00:00
```
2020-04-08 01:56:30 +01:00
## Library usage
```go
builder := xcaddy.Builder{
CaddyVersion: "v2.0.0-rc.1",
Plugins: []xcaddy.Dependency{
{
ModulePath: "github.com/caddyserver/ntlm-transport",
Version: "v0.1.0",
},
},
}
err := builder.Build("./caddy")
```
Versions can be anything compatible with `go get` .
2020-03-21 20:31:29 +00:00
---
© 2020 Matthew Holt