1. The problem I’m having:
I am taking a stab at building a small (read-only) UI for the caddy API.
So far I configured Caddy to expose the API and I have a standalone app that displays some data (like the config and limited metrics). As a next step, I want to wrap my UI into a module so I can install it with caddy (instead of running it as another container) — also to not have to expose the API (even if it’s “just” a local Docker network in the end).
This question is kind of broad — apologies — but how do you get started?
I know “how to” Go, as in, using the embed feature. But usually, this is a two step process. I build my JavaScript, then I move the build artefact to the go build
, etc…
With xcaddy build --with etc
(btw, kudos for creating that, it’s kinda wild to customise Caddy like this and get a binary) I am bit stuck on where to start.
Is it possible to use xcaddy
with already compiled Go code? E.g., I would pre-compile my module and then include that somehow? Or do I have to write some Make to inject the build from JavaScript somehow? Or can I start npm run build
somewhere?
I feel like, this is a noob question, but my Google fu is lacking.
2. Error messages and/or full log output:
n/a
3. Caddy version:
/srv # caddy version
v2.6.4 h1:2hwYqiRwk1tf3VruhMpLcYTg+11fCdr8S3jhNAdnPy8=
4. How I installed and ran Caddy:
I am using a multi-stage (Docker) build to build and essentially run Caddy:
ARG CADDY_VERSION=2.6.4
FROM caddy:${CADDY_VERSION}-builder as builder
RUN xcaddy build \
--with github.com/lucaslorentz/caddy-docker-proxy@v2.8.4
FROM caddy:${CADDY_VERSION}
WORKDIR /
ADD . .
WORKDIR /srv
COPY --from=builder /usr/bin/caddy /usr/bin/caddy
ENTRYPOINT [ "/usr/bin/caddy" ]
CMD ["docker-proxy", "--caddyfile-path=/opt/etc/caddy/Caddyfile", "--ingress-networks=public"]
a. System environment:
- Docker for Mac (Docker Swarm)
- Docker 20.x (Linux, OpenStack)
b. Command:
n/a
c. Docker
docker run --rm -it \
--name caddy-dev-local \
-p 80:80 \
-e ADMIN_API_URL=http://admin-api.127.0.0.1.nip.io \
-v $(CURDIR)/rootfs/etc/caddy:/opt/etc/caddy \
$(image)
d. My complete Caddy config:
{
debug
admin localhost:2019
log default {
output stdout
format console
include http.log.access admin.api
}
}
# admin-ui host
{$ADMIN_API_URL} {
route {
reverse_proxy localhost:2019 {
header_up Host localhost:2019
}
}
}