Dockerfile 896 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. # Build stage
  2. FROM golang:1.21-alpine AS builder
  3. # Install build dependencies
  4. RUN apk add --no-cache gcc musl-dev
  5. WORKDIR /app
  6. # Copy go mod files
  7. COPY go.mod go.sum ./
  8. # Download dependencies
  9. RUN go mod download
  10. # Copy source code
  11. COPY . .
  12. # Build the application
  13. RUN CGO_ENABLED=1 GOOS=linux go build -a -installsuffix cgo -ldflags="-s -w" -o nvml-gpu-ha .
  14. # Runtime stage
  15. FROM nvidia/cuda:12.2-base-ubuntu22.04
  16. # Install runtime dependencies
  17. RUN apt-get update && \
  18. apt-get install -y --no-install-recommends \
  19. ca-certificates && \
  20. rm -rf /var/lib/apt/lists/*
  21. # Copy the binary from builder stage
  22. COPY --from=builder /app/nvml-gpu-ha /usr/local/bin/nvml-gpu-ha
  23. # Create non-root user
  24. RUN useradd -r -s /bin/false nvml-gpu
  25. USER nvml-gpu
  26. # Default command
  27. ENTRYPOINT ["/usr/local/bin/nvml-gpu-ha"]
  28. CMD ["--mqtt-host=localhost", "--mqtt-port=1883", "--polling-period=30"]