# Build stage
FROM golang:1.26.3-alpine AS builder

RUN apk add --no-cache git make gcc musl-dev linux-headers bash

WORKDIR /build

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

# Copy source code
COPY . .

# Build luxd with pure Go (no CGO)
RUN CGO_ENABLED=0 ./scripts/build.sh -- -tags purego

# Runtime stage
FROM alpine:latest

RUN apk add --no-cache ca-certificates curl bash

# Create directories expected by k8s StatefulSet
RUN mkdir -p /luxd/build/plugins /var/lib/lux /data

# Copy the binary to expected location
COPY --from=builder /build/build/luxd /luxd/build/luxd

# Create lux user
RUN adduser -D -h /var/lib/lux lux && chown -R lux:lux /var/lib/lux /luxd /data

EXPOSE 9650 9651

ENTRYPOINT ["/luxd/build/luxd"]