Skip to content

Commit c719390

Browse files
committed
Fix multi-arch build issue for docker image
1 parent ad5e190 commit c719390

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

Dockerfile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,20 @@
11
FROM golang:1.25.4 AS build-env
22
WORKDIR /usr/local/go/src/github.com/SpectoLabs/hoverfly
33
COPY . /usr/local/go/src/github.com/SpectoLabs/hoverfly
4-
RUN cd core/cmd/hoverfly && CGO_ENABLED=0 GOOS=linux go install -ldflags "-s -w"
54

6-
FROM alpine:latest
7-
RUN apk --no-cache add ca-certificates
5+
# Support multi-arch builds with buildx by honoring TARGETOS/TARGETARCH
6+
ARG TARGETOS=linux
7+
ARG TARGETARCH
8+
RUN cd core/cmd/hoverfly \
9+
&& CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} \
10+
go install -ldflags "-s -w"
11+
12+
# Final minimal image based on Alpine, without running apk to avoid QEMU trigger issues
13+
FROM alpine:3.20
14+
# Provide CA certificates by copying from the builder (PEM bundle is arch-independent)
15+
COPY --from=build-env /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
16+
# Copy the statically linked hoverfly binary
817
COPY --from=build-env /usr/local/go/bin/hoverfly /bin/hoverfly
9-
ENTRYPOINT ["/bin/hoverfly", "-listen-on-host=0.0.0.0"]
10-
CMD [""]
1118

19+
ENTRYPOINT ["/bin/hoverfly", "-listen-on-host=0.0.0.0"]
1220
EXPOSE 8500 8888

0 commit comments

Comments
 (0)