mirror of
https://github.com/hanzoai/pubsub.git
synced 2026-10-30 15:06:26 +00:00
The official golang images set GOTOOLCHAIN=local, so a go.mod `go` directive
newer than the base image fails the build at the first go command:
go: go.mod requires go >= 1.26.5 (running go 1.26.4; GOTOOLCHAIN=local)
Two orthogonal changes. Pinning the base to the exact patch go.mod names makes
the build hermetic — the versions match, so no toolchain is downloaded.
GOTOOLCHAIN=auto is the resilience half: when go.mod next moves ahead of the
pin, the toolchain is fetched and checksum-verified against sum.golang.org
instead of failing the build outright.
docker/Dockerfile.nightly keeps its floating golang:alpine base on purpose —
tracking the newest Go is the point of that image, and pinning it would add a
second thing to bump. GOTOOLCHAIN=auto alone makes it correct whatever the tag
resolves to.
Co-authored-by: Hanzo Dev <[email protected]>
54 lines
1.5 KiB
Docker
54 lines
1.5 KiB
Docker
FROM --platform=$BUILDPLATFORM golang:alpine AS builder
|
|
# go.mod pins the toolchain. The golang base image sets GOTOOLCHAIN=local,
|
|
# which turns a `go` directive newer than the image into a hard build
|
|
# failure instead of a download.
|
|
ENV GOTOOLCHAIN=auto
|
|
|
|
ARG VERSION="nightly"
|
|
ARG GIT_COMMIT
|
|
|
|
ARG TARGETOS
|
|
ARG TARGETARCH
|
|
|
|
ENV GOOS=$TARGETOS \
|
|
GOARCH=$TARGETARCH \
|
|
GO111MODULE=on \
|
|
CGO_ENABLED=0
|
|
|
|
RUN apk add --no-cache ca-certificates
|
|
RUN update-ca-certificates
|
|
|
|
WORKDIR /src
|
|
RUN mkdir -p /src/out/$GOOS/$GOARCH
|
|
|
|
COPY ./pubsub/ /src/pubsub/
|
|
COPY ./nsc/ /src/nsc/
|
|
COPY ./natscli/ /src/natscli/
|
|
|
|
RUN cd /src/pubsub && go build -trimpath \
|
|
-ldflags "-w -X server.serverVersion=${VERSION},server.gitCommit=${GIT_COMMIT}" \
|
|
-o /src/out/$TARGETOS/$TARGETARCH/pubsub .
|
|
|
|
RUN cd /src/natscli && go build -trimpath \
|
|
-ldflags "-w -X main.version=${VERSION}" \
|
|
-o /src/out/$TARGETOS/$TARGETARCH/nats ./nats
|
|
|
|
RUN cd /src/nsc && go build -trimpath \
|
|
-o /src/out/$TARGETOS/$TARGETARCH/nsc .
|
|
|
|
FROM --platform=$TARGETPLATFORM alpine:latest
|
|
|
|
ARG TARGETOS
|
|
ARG TARGETARCH
|
|
|
|
COPY ./pubsub/docker/pubsub.conf /nats/conf/pubsub.conf
|
|
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
|
|
COPY --from=builder /src/out/$TARGETOS/$TARGETARCH/pubsub /bin/pubsub
|
|
COPY --from=builder /src/out/$TARGETOS/$TARGETARCH/nats /bin/nats
|
|
COPY --from=builder /src/out/$TARGETOS/$TARGETARCH/nsc /bin/nsc
|
|
|
|
EXPOSE 4222 8222 6222 5222
|
|
|
|
ENTRYPOINT ["/bin/pubsub"]
|
|
CMD ["-c", "/nats/conf/pubsub.conf"]
|