Commit 018105ee authored by Matthew Holt's avatar Matthew Holt

readme: Update build-from-source instructions for Go modules

parent bf6ec2bb
......@@ -75,17 +75,54 @@ Caddy binaries have no dependencies and are available for every platform. Get Ca
## Build
To build from source you need **[Git](https://git-scm.com/downloads)** and **[Go](https://golang.org/doc/install)** (1.12 or newer). Follow these instruction for fast building:
To build from source you need **[Git](https://git-scm.com/downloads)** and **[Go](https://golang.org/doc/install)** (1.12 or newer).
- Set the transitional environment variable `GO111MODULE` to `on`
- Get the source with `go get github.com/mholt/caddy/caddy` and then run `go get github.com/caddyserver/builds`
- Now `cd $GOPATH/src/github.com/mholt/caddy/caddy` and run `go run build.go`
**To build Caddy without plugins:**
Then make sure the `caddy` binary is in your PATH.
<!-- TODO: This env variable will not be required starting with Go 1.13 -->
1. Set the transitional environment variable for Go modules: `export GO111MODULE=on`
<!-- TODO: The specific version will not be required after the stable 1.0.0 release -->
2. Run `go get github.com/mholt/caddy/caddy@1.0.0-beta2`
To build for other platforms, use build.go with the `--goos` and `--goarch` flags.
Caddy will be installed to your `$GOPATH/bin` folder.
When building from source, telemetry is enabled by default. You can disable it by changing `enableTelemetry` in run.go before compiling, or use the `-disabled-metrics` flag at runtime to disable only certain metrics.
With these instructions, the binary will not have embedded version information (see [golang/go#29228](https://github.com/golang/go/issues/29228)), but it is fine for a quick start.
**To build Caddy with plugins (and with version information):**
There is no need to modify the Caddy code to build it with plugins. We will create a simple Go module with our own `main()` that you can use to make custom Caddy builds.
<!-- TODO: This env variable will not be required starting with Go 1.13 -->
1. Set the transitional environment variable for Go modules: `export GO111MODULE=on`
2. Create a new folder anywhere, and put this Go file into it, then import the plugins you want to include:
```go
package main
import (
"github.com/mholt/caddy/caddy/caddymain"
// plug in plugins here, for example:
// _ "import/path/here"
)
func main() {
// optional: disable telemetry
// caddymain.EnableTelemetry = false
caddymain.Run()
}
```
3. `go mod init mycaddy` (the name doesn't really matter).
4. `go install` will then create your binary at `$GOPATH/bin`, or `go build` will put it in the current directory.
**To install Caddy's source code for development:**
<!-- TODO: This env variable will not be required starting with Go 1.13 -->
1. Set the transitional environment variable for Go modules: `export GO111MODULE=on`
2. Run `git clone https://github.com/mholt/caddy.git` in any folder (doesn't have to be in GOPATH).
You can make changes to the source code in this repo, since it is a Go module.
When building from source, telemetry is enabled by default. You can disable it by changing `caddymain.EnableTelemetry = false` in run.go, or use the `-disabled-metrics` flag at runtime to disable only certain metrics.
## Quick Start
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment