Skip to content

can't build the module #22

Description

@SinisterSpatula

Hi, I'm getting an error message when I build using xcaddy in a Dockerfile, go errors that say stuff is redeclared. Been stuck for a long while trying to figure out how to solve it. Initally I was using the official caddy-builder-alpine image, but your module requires go 1.24.0 and they haven't updated from 1.23 in that image yet.

error message:

25.86 2025/02/28 08:56:07 [INFO] exec (timeout=0s): /usr/local/go/bin/go build -o /usr/bin/caddy -ldflags -w -s -trimpath -tags nobadger,nomysql,nopgx 
26.60 # runtime
26.60 /usr/local/go/src/runtime/map.go:877:6: mapiterinit redeclared in this block
26.60   /usr/local/go/src/runtime/linkname_swiss.go:91:6: other declaration of mapiterinit
26.60 /usr/local/go/src/runtime/map.go:937:6: mapiternext redeclared in this block
26.60   /usr/local/go/src/runtime/linkname_swiss.go:144:6: other declaration of mapiternext
26.60 /usr/local/go/src/runtime/map.go:1519:6: reflect_mapiterinit redeclared in this block
26.60   /usr/local/go/src/runtime/linkname_swiss.go:123:6: other declaration of reflect_mapiterinit
26.60 /usr/local/go/src/runtime/map.go:1536:6: reflect_mapiternext redeclared in this block
26.60   /usr/local/go/src/runtime/linkname_swiss.go:173:6: other declaration of reflect_mapiternext
26.60 /usr/local/go/src/runtime/map.go:1550:6: reflect_mapiterkey redeclared in this block
26.60   /usr/local/go/src/runtime/linkname_swiss.go:191:6: other declaration of reflect_mapiterkey
26.60 /usr/local/go/src/runtime/map.go:1564:6: reflect_mapiterelem redeclared in this block
26.60   /usr/local/go/src/runtime/linkname_swiss.go:209:6: other declaration of reflect_mapiterelem
26.60 /usr/local/go/src/runtime/map_fast32_swiss.go:18:6: mapaccess1_fast32 redeclared in this block
26.60   /usr/local/go/src/runtime/map_fast32.go:13:6: other declaration of mapaccess1_fast32
26.60 /usr/local/go/src/runtime/map_fast32_swiss.go:29:6: mapaccess2_fast32 redeclared in this block
26.60   /usr/local/go/src/runtime/map_fast32.go:62:6: other declaration of mapaccess2_fast32
26.60 /usr/local/go/src/runtime/map_fast32_swiss.go:41:6: mapassign_fast32 redeclared in this block
26.60   /usr/local/go/src/runtime/map_fast32.go:113:6: other declaration of mapassign_fast32
26.60 /usr/local/go/src/runtime/map_fast32_swiss.go:52:6: mapassign_fast32ptr redeclared in this block
26.60   /usr/local/go/src/runtime/map_fast32.go:212:6: other declaration of mapassign_fast32ptr
26.60 /usr/local/go/src/runtime/map_fast32_swiss.go:52:6: too many errors
26.64 2025/02/28 08:56:08 [INFO] Skipping cleanup as requested; leaving folder intact: /tmp/buildenv_2025-02-28-0855.4189852179
26.64 2025/02/28 08:56:08 [FATAL] exit status 1
------
failed to solve: process "/bin/sh -c xcaddy build     --with github.com/caddy-dns/porkbun     --with github.com/greenpau/caddy-security     --with github.com/mholt/caddy-l4     --with github.com/caddyserver/transform-encoder     --with github.com/hslatman/caddy-crowdsec-bouncer/http@main     --with github.com/hslatman/caddy-crowdsec-bouncer/layer4@main     --with github.com/aksdb/caddy-cgi/v2" did not complete successfully: exit code: 1
root@0ceaf8fc5009:/opt/stacks/caddy#

My Dockerfile:

# Set Caddy version
ARG CADDY_VERSION=2.9.1
ARG GO_VERSION=1.24.0

# Use Caddy builder image
FROM caddy:${CADDY_VERSION}-builder-alpine AS builder

# Bring in ARGs to the build stage
ARG GO_VERSION

# Install necessary build tools
RUN apk add --no-cache git gcc musl-dev wget

# Download and install Go
RUN wget https://go.dev/dl/go${GO_VERSION}.linux-amd64.tar.gz && \
    tar -C /usr/local -xzf go${GO_VERSION}.linux-amd64.tar.gz && \
    rm go${GO_VERSION}.linux-amd64.tar.gz

# Set Go environment variables
ENV PATH /usr/local/go/bin:$PATH

# Build Caddy with the desired plugins
RUN xcaddy build \
    --with github.com/caddy-dns/porkbun \
    --with github.com/greenpau/caddy-security \
    --with github.com/mholt/caddy-l4 \
    --with github.com/caddyserver/transform-encoder \
    --with github.com/hslatman/caddy-crowdsec-bouncer/http@main \
    --with github.com/hslatman/caddy-crowdsec-bouncer/layer4@main \
    --with github.com/aksdb/caddy-cgi/v2

# Use a lightweight Caddy image for the final stage
FROM caddy:${CADDY_VERSION}-alpine

# Copy the custom Caddy binary
COPY --from=builder /usr/bin/caddy /usr/bin/caddy

# Run Caddy with the specified configuration
CMD ["caddy", "run", "--config", "/etc/caddy/Caddyfile", "--adapter", "caddyfile"]

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions