1
0
Fork 0

Switch to Go modules and script, bump to 1.0.0
continuous-integration/drone/push Build is passing Details

Closes #3
pull/5/head 1.0.0
Ambrose Chua 2019-07-02 13:20:58 +08:00
parent 6da16d7546
commit a44cf0f4a3
5 changed files with 93 additions and 21 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
caddy.go
go.sum

View File

@ -1,38 +1,29 @@
#
# Build stage by @abiosoft https://github.com/abiosoft/caddy-docker
# Build stage
#
FROM golang:1.12-alpine as build
# args
ARG version="0.11.5"
# add plugins here separated by commas
ARG version="1.0.0"
# add plugin import paths here separated by commas
ARG plugins=""
ARG telemetry="true"
# deps
RUN apk add --no-cache git
# source
RUN git clone https://github.com/mholt/caddy -b "v${version}" $GOPATH/src/github.com/mholt/caddy
WORKDIR $GOPATH/src/github.com/mholt/caddy
RUN git checkout -b "v${version}"
# plugin helper
RUN go get -v github.com/abiosoft/caddyplug/caddyplug
# build root
RUN mkdir /build
WORKDIR /build
ENV GO111MODULE=on
ENV CGO_ENABLED=0
# plugins
RUN for plugin in $(echo $plugins | tr "," " "); do \
go get -v $(caddyplug package $plugin); \
printf "package caddyhttp\nimport _ \"$(caddyplug package $plugin)\"" > \
$GOPATH/src/github.com/mholt/caddy/caddyhttp/$plugin.go ; \
done
# builder dependency
RUN git clone https://github.com/caddyserver/builds $GOPATH/src/github.com/caddyserver/builds
COPY go.mod plugger.go ./
RUN go run plugger.go -plugins="${plugins}" -telemetry="${telemetry}"
# build
WORKDIR $GOPATH/src/github.com/mholt/caddy/caddy
RUN git checkout -f
RUN go run build.go
RUN go build
RUN mv caddy /

View File

@ -21,3 +21,18 @@ Persist `.caddy` to avoid hitting Let's Encrypt's rate limit:
```
docker run -it --rm -p 2015:2015 -v $PWD:/srv -v $PWD/Caddyfile:/etc/Caddyfile -v $HOME/.caddy:/etc/.caddy productionwentdown/caddy
```
# Build with plugins
Using `docker build` arguments:
```
docker build -t caddy --build-arg plugins=github.com/abiosoft/caddy-git,github.com/zikes/gopkg .
```
You can also fork and edit plugger.go for more advanced plugin configuration
# Build without telemetry
```
docker build -t caddy --build-arg telemetry=false
```

3
go.mod Normal file
View File

@ -0,0 +1,3 @@
module caddy
require github.com/mholt/caddy v1.0.0

61
plugger.go Normal file
View File

@ -0,0 +1,61 @@
// +build ignore
package main
import (
"flag"
"log"
"os"
"strings"
"text/template"
)
var plugins string
var telemetry bool
func main() {
flag.StringVar(&plugins, "plugins", "", "Specify plugins by full paths, seperated by commas")
flag.BoolVar(&telemetry, "telemetry", false, "Enable telemetry")
flag.Parse()
d := &data{
Plugins: strings.FieldsFunc(plugins, func(c rune) bool { return c == ',' }),
EnableTelemetry: telemetry,
}
log.Printf("Additional plugins: %v", d.Plugins)
log.Printf("Enabled telemetry: %v", d.EnableTelemetry)
f, err := os.Create("caddy.go")
defer f.Close()
if err != nil {
log.Fatal("Unable to open file")
}
t := template.Must(template.New("caddy.go").Parse(caddyTemplate))
t.Execute(f, d)
}
type data struct {
Plugins []string
EnableTelemetry bool
}
var caddyTemplate = `
package main
import (
"github.com/mholt/caddy/caddy/caddymain"
// plug in plugins here
{{range $plugin := .Plugins}}
_ "{{$plugin}}"
{{end}}
)
func main() {
// optional: disable telemetry
caddymain.EnableTelemetry = {{.EnableTelemetry}}
caddymain.Run()
}
`