Building caddy with plugins from source

I am struggling to build caddy from source with plugins in my docker container. My understanding from the wiki pages about building plugins was, that to compile them into caddy, you just have to import the package in the run.go file in caddymain. Doing that gave me errors, like

# github.com/mholt/caddy/caddy/caddymain
./run.go:24: imported and not used: "github.com/abiosoft/caddy-git" as git

(importing only the git plugin) and

# github.com/hacdias/caddy-filemanager/assets
../../../../hacdias/caddy-filemanager/assets/assets.go:19: undefined: Asset

without caddy-filemanager even imported. I imported those ones though:

	"github.com/abiosoft/caddy-git"
	"github.com/hacdias/caddy-minify"
	"github.com/pedronasser/caddy-search"
	"github.com/namsral/multipass/caddy"
	"github.com/hacdias/caddy-hugo"

Is there anything else I need to do? Am I doing something completely wrong?

Thanks!

For reference, this is my Dockerfile:

FROM alpine:edge
MAINTAINER Jan Christian Grünhage <mail@janchristiangruenhage.de>

ENV GOPATH /gopath
ENV CADDY_REPO_OWNER mholt
ENV CADDY_REPO_NAME caddy
ENV CADDY_BRANCH master
ENV CADDYPATH /caddy
ENV UID 192
ENV GID 192

COPY ./plugins.txt /plugins

RUN addgroup -g $GID -S caddy \
	&& adduser -u $UID -g $GID -S caddy

RUN apk add --update musl \
	&& apk add --no-cache build-base libcap tini go git \
	&& mkdir -p $GOPATH/src/github.com/$CADDY_REPO_OWNER \
	&& cd $GOPATH/src/github.com/$CADDY_REPO_OWNER \
	&& git clone https://github.com/$CADDY_REPO_OWNER/$CADDY_REPO_NAME \
	&& cd $CADDY_REPO_NAME \
	&& git checkout $CADDY_BRANCH \
	&& cd caddy/caddymain \
	&& head -n 23 run.go > newrun.go \
	&& cat /plugins >> newrun.go \
	&& tail -n +24 run.go >> newrun.go \
	&& rm -f run.go \
	&& mv newrun.go run.go \
	&& go get github.com/$CADDY_REPO_OWNER/$CADDY_REPO_NAME/... \
	&& mv $GOPATH/bin/caddy /usr/bin \
	&& setcap cap_net_bind_service=+ep /usr/bin/caddy \
	&& apk del --purge build-base go \
	&& mkdir $CADDYPATH \
	&& rm -rf $GOPATH /var/cache/apk/*

USER		caddy
EXPOSE		2015 80 443
VOLUME		[ "$CADDYPATH" ]
WORKDIR		"$CADDYPATH"
ENTRYPOINT	[ "/sbin/tini" ]
CMD		[ "caddy", "-quic", "--conf", "/caddy/Caddyfile" ]

/plugins contains the urls to the repos of the plugins that I want to use.

1 Like

You forgot one very important character as shown on the wiki (which, um, I would link to but GitHub is down right now):

_ "github.com/abiosoft/caddy_git"

This means import the package for its side-effects, like registering the plugin.

For @hacdias’s plugins, you need to run go generate on them.

1 Like

Thank you :slight_smile: