# Build stage
FROM golang:1.21-alpine AS builder

WORKDIR /app

# Install dependencies
RUN apk add --no-cache git make

# Copy go mod files
COPY go.mod go.sum ./
RUN go mod download

# Copy source code
COPY . .

# Build binaries
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o bin/dbnode ./cmd/dbnode
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o bin/dbclient ./cmd/dbclient

# Runtime stage
FROM alpine:latest

RUN apk --no-cache add ca-certificates

WORKDIR /root/

# Copy binaries from builder
COPY --from=builder /app/bin/dbnode .
COPY --from=builder /app/bin/dbclient .

# Create data directory
RUN mkdir -p /data

# Expose ports
EXPOSE 9001 9002

# Run dbnode by default
CMD ["./dbnode"]
