Question Regarding Caddy xcaddy modules and versioning

I am building a Docker image to create a custom Caddy server with specific modules. Here is my Dockerfile:

FROM golang:1.21.3-alpine as builder

ARG TARGETOS
ARG TARGETPLATFORM
ARG TARGETARCH
ARG CADDY_VERSION="v2.7.6"
ENV CADDY_VERSION=$CADDY_VERSION
RUN echo "Building Caddy $CADDY_VERSION for $TARGETOS"

WORKDIR /workspace

RUN go install github.com/caddyserver/xcaddy/cmd/xcaddy@latest

RUN GOOS=$TARGETOS GOARCH=$TARGETARCH xcaddy build \
    --with github.com/abiosoft/caddy-yaml \
    --with github.com/mholt/caddy-l4 \
    --with github.com/ss098/certmagic-s3

FROM alpine

COPY --from=builder /workspace/caddy /bin/caddy

ENTRYPOINT ["/bin/caddy"]

My question is: Are the modules installed from their main/master branches, or do the versions of each module depend on the Caddy version being used? I want my Dockerfile to specify exact versions for each module included in the Caddy build.

Regards :slight_smile:

No.

Kinda. It follows Go module resolution rules. There are two scenarios, each of which branch:

  • The argument of --with flag does not contain @<version>:

    • The module is tagged: it’ll pick up the latest tag
    • The module is not tagged: It’ll pick up HEAD
  • The argument of --with flag contains a version/tag:

    • The module is tagged: It’ll pick up the specified version
    • The module is not tagged: The flag accepts commit hash and branch. If the specified version is completely unknown, it’ll fail with an error of unknown revision.

All to say, you can specify the version for each of your modules to pin them down to a known version.

2 Likes

Thank you for your answer! I will take it into account.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.