# Build stage FROM golang:1.21-alpine AS builder WORKDIR /app COPY go.mod go.sum ./ RUN go mod download COPY main.go ./ RUN CGO_ENABLED=0 GOOS=linux go build -ldflags="-s -w" -o nats-ui main.go # Runtime stage FROM alpine:3.19 RUN apk --no-cache add ca-certificates tzdata && \ adduser -D -u 1000 -h /app appuser WORKDIR /app COPY --from=builder /app/nats-ui . COPY index.html ./ # config.yaml is in .gitignore; create default in image (override via volume at runtime) RUN printf '%s\n' \ 'nats_url: "nats://localhost:4222"' \ 'subjects: ">"' \ 'port: "8080"' \ 'max_messages: 1000' \ > config.yaml RUN chmod +x nats-ui && chown -R appuser:appuser /app EXPOSE 8080 USER appuser ENTRYPOINT ["./nats-ui"] CMD ["config.yaml"]