Dockerfile.sidecar 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # Multi-stage build for Go Sidecar
  2. FROM golang:1.24-alpine AS builder
  3. # Install build dependencies
  4. RUN apk add --no-cache git ca-certificates tzdata
  5. # Set work directory
  6. WORKDIR /app
  7. # Copy go mod files
  8. COPY go.mod go.sum ./
  9. # Download dependencies
  10. RUN go mod download
  11. # Copy source code
  12. COPY cmd/ ./cmd/
  13. COPY pkg/ ./pkg/
  14. # Build the binaries
  15. RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o demo-server ./cmd/demo-server
  16. RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o sidecar ./cmd/sidecar
  17. RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o test-rdma ./cmd/test-rdma
  18. # Runtime stage
  19. FROM alpine:3.18
  20. # Install runtime dependencies
  21. RUN apk --no-cache add ca-certificates curl jq
  22. # Create app user
  23. RUN addgroup -g 1001 appgroup && \
  24. adduser -D -s /bin/sh -u 1001 -G appgroup appuser
  25. # Set work directory
  26. WORKDIR /app
  27. # Copy binaries from builder stage
  28. COPY --from=builder /app/demo-server .
  29. COPY --from=builder /app/sidecar .
  30. COPY --from=builder /app/test-rdma .
  31. # Change ownership
  32. RUN chown -R appuser:appgroup /app
  33. USER appuser
  34. # Expose the demo server port
  35. EXPOSE 8081
  36. # Health check
  37. HEALTHCHECK --interval=10s --timeout=5s --start-period=15s --retries=3 \
  38. CMD curl -f http://localhost:8081/health || exit 1
  39. # Default command (demo server)
  40. CMD ["./demo-server", "--port", "8081", "--enable-rdma", "--debug"]