1
0
Fork 0

Experimental bashbrew

test
Ambrose Chua 2020-04-08 01:56:21 +08:00
parent c97b19e1dd
commit 2ac27f11bd
Signed by: ambrose
GPG Key ID: BC367D33F140B5C2
8 changed files with 150 additions and 115 deletions

View File

@ -1,3 +0,0 @@
:2015 {
root /srv
}

View File

@ -1,51 +0,0 @@
#
# Build stage
#
FROM golang:1.13-alpine as build
# args
ARG version="1.0.5"
# add plugin import paths here separated by commas
ARG plugins=""
ARG telemetry="true"
# build root
WORKDIR /build
# plugins
COPY plugger.go ./
# build & test
RUN apk add --no-cache git upx ca-certificates \
&& echo -e "module caddy\nrequire github.com/caddyserver/caddy v${version}" > go.mod \
&& go run plugger.go -plugins="${plugins}" -telemetry="${telemetry}" \
&& CGO_ENABLED=0 GOOS=linux GO111MODULE=on go build \
&& upx --ultra-brute caddy \
&& ./caddy -version
#
# Final image
#
FROM scratch
# labels
LABEL org.label-schema.vcs-url="https://github.com/productionwentdown/caddy"
LABEL org.label-schema.version=${version}
LABEL org.label-schema.schema-version="1.0"
# copy binary and ca certs
COPY --from=build /build/caddy /bin/caddy
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
# copy default caddyfile
COPY Caddyfile /etc/Caddyfile
# set default caddypath
ENV CADDYPATH=/etc/.caddy
VOLUME /etc/.caddy
# serve from /srv
WORKDIR /srv
EXPOSE 2015
ENTRYPOINT ["/bin/caddy", "--conf", "/etc/Caddyfile", "--log", "stdout"]

9
Makefile Normal file
View File

@ -0,0 +1,9 @@
.PHONY: all
all: update library/caddy
.PHONY: update
update: scratch/Dockerfile
./update.sh
library/caddy: generate-stackbrew-library.sh
./generate-stackbrew-library.sh > library/caddy

45
generate-stackbrew-library.sh Executable file
View File

@ -0,0 +1,45 @@
#!/bin/bash
set -Eeuo pipefail
gitHubUrl='https://github.com/productionwentdown/caddy'
gitHubUpstreamUrl='https://github.com/caddyserver/caddy-docker'
join() {
local sep="$1"; shift
local out; printf -v out "${sep//%/%%}%s" "$@"
echo "${out#$sep}"
}
_wget() {
wget -qO- -o /dev/null "$@"
}
cat <<-EOH
# see https://github.com/caddyserver/caddy-docker
Maintainers: Ambrose Chua <ambrose@makerforce.io> (@serverwentdown)
GitRepo: https://github.com/productionwentdown/caddy.git
GitCommit: $(git log --format='format:%H' -1)
EOH
caddyVersion="$(_wget "$gitHubUpstreamUrl/raw/master/stackbrew-config.yaml" | grep -oP '(?<=caddy_version: ).+$')"
version="${caddyVersion#v}"
versionAliases=($version)
arches=(amd64)
if [[ "$version" =~ "-rc" ]]; then
versionAliases+=(test)
elif [[ "$version" =~ "-beta" ]]; then
versionAliases+=()
else
versionAliases+=(latest)
fi
cat <<-EOE
Tags: $(join ', ' "${versionAliases[@]}")
Architectures: $(join ', ' "${arches[@]}")
Directory: scratch
EOE

9
library/caddy Normal file
View File

@ -0,0 +1,9 @@
# see https://github.com/caddyserver/caddy-docker
Maintainers: Ambrose Chua <ambrose@makerforce.io> (@serverwentdown)
GitRepo: https://github.com/productionwentdown/caddy.git
GitCommit: c97b19e1ddf4f8107ce5004038feb627679ad3f5
Tags: 2.0.0-rc.1, test
Architectures: amd64
Directory: scratch

View File

@ -1,61 +0,0 @@
// +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/caddyserver/caddy/caddy/caddymain"
// plug in plugins here
{{range $plugin := .Plugins}}
_ "{{$plugin}}"
{{end}}
)
func main() {
// optional: disable telemetry
caddymain.EnableTelemetry = {{.EnableTelemetry}}
caddymain.Run()
}
`

32
scratch/Dockerfile Normal file
View File

@ -0,0 +1,32 @@
FROM caddy/caddy:2.0.0-rc.1 as build
RUN apk add --no-cache upx ca-certificates && upx --ultra-brute /usr/bin/caddy && caddy version
FROM scratch
COPY --from=build /etc/caddy/Caddyfile /etc/caddy/Caddyfile
COPY --from=build /usr/share/caddy/index.html /usr/share/caddy/index.html
COPY --from=build /usr/bin/caddy /usr/bin/caddy
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
ENV XDG_CONFIG_HOME=/config
ENV XDG_DATA_HOME=/data
ENV HOME=/
VOLUME /config
VOLUME /data
LABEL org.opencontainers.image.version=v2.0.0-rc.1
LABEL org.opencontainers.image.title="Caddy (productionwentdown)"
LABEL org.opencontainers.image.description="a powerful, enterprise-ready, open source web server with automatic HTTPS written in Go"
LABEL org.opencontainers.image.url=https://productionwentdown.github.io
LABEL org.opencontainers.image.documentation=https://caddyserver.com/docs
LABEL org.opencontainers.image.vendor="productionwentdown"
LABEL org.opencontainers.image.licenses=Apache-2.0
LABEL org.opencontainers.image.source="https://github.com/productionwentdown/caddy"
EXPOSE 80
EXPOSE 443
EXPOSE 2019
ENTRYPOINT ["/usr/bin/caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]

55
update.sh Executable file
View File

@ -0,0 +1,55 @@
#!/bin/bash
set -Eeuo pipefail
gitHubUpstreamUrl='https://github.com/caddyserver/caddy-docker'
join() {
local sep="$1"; shift
local out; printf -v out "${sep//%/%%}%s" "$@"
echo "${out#$sep}"
}
_wget() {
wget -qO- -o /dev/null "$@"
}
caddyVersion="$(_wget "$gitHubUpstreamUrl/raw/master/stackbrew-config.yaml" | grep -oP '(?<=caddy_version: ).+$')"
version="${caddyVersion#v}"
cat > scratch/Dockerfile <<-EODF
FROM caddy/caddy:$version as build
RUN apk add --no-cache upx ca-certificates \
&& upx --ultra-brute /usr/bin/caddy \
&& caddy version
FROM scratch
COPY --from=build /etc/caddy/Caddyfile /etc/caddy/Caddyfile
COPY --from=build /usr/share/caddy/index.html /usr/share/caddy/index.html
COPY --from=build /usr/bin/caddy /usr/bin/caddy
COPY --from=build /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
ENV XDG_CONFIG_HOME=/config
ENV XDG_DATA_HOME=/data
ENV HOME=/
VOLUME /config
VOLUME /data
LABEL org.opencontainers.image.version=$caddyVersion
LABEL org.opencontainers.image.title="Caddy (productionwentdown)"
LABEL org.opencontainers.image.description="a powerful, enterprise-ready, open source web server with automatic HTTPS written in Go"
LABEL org.opencontainers.image.url=https://productionwentdown.github.io
LABEL org.opencontainers.image.documentation=https://caddyserver.com/docs
LABEL org.opencontainers.image.vendor="productionwentdown"
LABEL org.opencontainers.image.licenses=Apache-2.0
LABEL org.opencontainers.image.source="https://github.com/productionwentdown/caddy"
EXPOSE 80
EXPOSE 443
EXPOSE 2019
ENTRYPOINT ["/usr/bin/caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]
EODF