caddyserver / caddy-docker

Source for the official Caddy v2 Docker Image
https://hub.docker.com/_/caddy
Apache License 2.0
408 stars 74 forks source link

Build caddy with mercure and cloudflare-dns #363

Closed wiseguy1394 closed 1 month ago

wiseguy1394 commented 1 month ago

Hi, the following dockerfile suddenly stopped working:

FROM caddy:2.7-builder AS caddy_builder

RUN apk update && \
    apk add --no-cache build-base && \
    CGO_ENABLED=1 xcaddy build  \
    --with github.com/dunglas/mercure  \
    --with github.com/dunglas/mercure/caddy \
    --with github.com/caddy-dns/cloudflare

FROM caddy:2.7

RUN echo "net.core.rmem_max=2500000" > /etc/sysctl.conf

COPY --from=caddy_builder --link /usr/bin/caddy /usr/bin/caddy

WORKDIR /var/www/public

It seems to be some problems with different go versions:

31.84 go: upgraded golang.org/x/sys v0.14.0 => v0.21.0
31.84 go: upgraded golang.org/x/term v0.13.0 => v0.20.0
31.84 go: upgraded golang.org/x/text v0.13.0 => v0.16.0
31.84 go: upgraded golang.org/x/tools v0.10.0 => v0.21.1-0.20240508182429-e35e4ccd0d2d
31.84 go: upgraded google.golang.org/protobuf v1.31.0 => v1.34.1
31.84 go: added gopkg.in/ini.v1 v1.67.0
31.84 2024/07/22 08:00:53 [INFO] exec (timeout=0s): /usr/local/go/bin/go get -d -v github.com/dunglas/mercure/caddy github.com/caddyserver/caddy/v2@v2.7.6 
32.51 go: downloading github.com/dunglas/mercure/caddy v0.16.2
32.56 go: github.com/dunglas/mercure/caddy@v0.16.2 requires go >= 1.22.0 (running go 1.21.10; GOTOOLCHAIN=local)
32.57 2024/07/22 08:00:53 [FATAL] exit status 1

How can this be fixed? Following dockerfile seems to work:

FROM caddy:2.8-builder AS caddy_builder

RUN apk update && \
    apk add --no-cache build-base && \
    CGO_ENABLED=1 xcaddy build  \
    --with github.com/dunglas/mercure  \
    --with github.com/dunglas/mercure/caddy \
    --with github.com/caddy-dns/cloudflare

FROM caddy:2.7

RUN echo "net.core.rmem_max=2500000" > /etc/sysctl.conf

COPY --from=caddy_builder --link /usr/bin/caddy /usr/bin/caddy

WORKDIR /var/www/public

Are there any problems to do so?

hairyhenderson commented 1 month ago

@wiseguy1394 Caddy 2.7 is out of date, 2.8 is current. You should move to 2.8 completely.

The reason for this is that you're building with the latest version of the listed modules, one of which has updated to require a newer version of Go than is shipped in the old Caddy 2.7 builder image.

The only thing I would change in your working Dockerfile is use FROM caddy:2.8 instead of FROM caddy:2.7. They're almost exactly the same since you're overwriting the Caddy binary anyway.