| 1 |
FROM --platform=$BUILDPLATFORM golang:alpine AS builder |
| 2 |
|
| 3 |
ARG VERSION="nightly" |
| 4 |
ARG GIT_COMMIT |
| 5 |
|
| 6 |
ARG TARGETOS |
| 7 |
ARG TARGETARCH |
| 8 |
|
| 9 |
ENV GOOS=$TARGETOS \ |
| 10 |
GOARCH=$TARGETARCH \ |
| 11 |
GO111MODULE=on \ |
| 12 |
CGO_ENABLED=0 |
| 13 |
|
| 14 |
RUN apk add --no-cache ca-certificates |
| 15 |
RUN update-ca-certificates |
| 16 |
|
| 17 |
WORKDIR /src |
| 18 |
RUN mkdir -p /src/out/$GOOS/$GOARCH |
| 19 |
|
| 20 |
COPY ./nats-server/ /src/nats-server/ |
| 21 |
COPY ./nsc/ /src/nsc/ |
| 22 |
COPY ./natscli/ /src/natscli/ |
| 23 |
|
| 24 |
RUN cd /src/nats-server && go build -trimpath \ |
| 25 |
-ldflags "-w -X server.serverVersion=${VERSION},server.gitCommit=${GIT_COMMIT}" \ |
| 26 |
-o /src/out/$TARGETOS/$TARGETARCH/nats-server . |
| 27 |
|
| 28 |
RUN cd /src/natscli && go build -trimpath \ |
| 29 |
-ldflags "-w -X main.version=${VERSION}" \ |
| 30 |
-o /src/out/$TARGETOS/$TARGETARCH/nats ./nats |
| 31 |
|
| 32 |
RUN cd /src/nsc && go build -trimpath \ |
| 33 |
-o /src/out/$TARGETOS/$TARGETARCH/nsc . |
| 34 |
|
| 35 |
FROM --platform=$TARGETPLATFORM alpine:latest |
| 36 |
|
| 37 |
ARG TARGETOS |
| 38 |
ARG TARGETARCH |
| 39 |
|
| 40 |
RUN apk add --no-cache tzdata |
| 41 |
|
| 42 |
COPY ./nats-server/docker/nats-server.conf /nats/conf/nats-server.conf |
| 43 |
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ |
| 44 |
COPY --from=builder /src/out/$TARGETOS/$TARGETARCH/nats-server /bin/nats-server |
| 45 |
COPY --from=builder /src/out/$TARGETOS/$TARGETARCH/nats /bin/nats |
| 46 |
COPY --from=builder /src/out/$TARGETOS/$TARGETARCH/nsc /bin/nsc |
| 47 |
|
| 48 |
EXPOSE 4222 8222 6222 5222 |
| 49 |
|
| 50 |
ENTRYPOINT ["/bin/nats-server"] |
| 51 |
CMD ["-c", "/nats/conf/nats-server.conf"] |